How to use the TILT switch using Arduino.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
int led=7; int tilt =2; void setup() { pinMode(led,OUTPUT); pinMode(tilt,INPUT); } void loop() { if(digitalRead(tilt)==HIGH) { digitalWrite(led,LOW);//turn off the LED } else { digitalWrite(led,HIGH);//turn on the LED } } |
Download the source code here | 14Core_Tilt_Switch
Starter #7 How to use Tilt Switch in Arduino with Sample Source Code