Another illustration how to control and wire the Rolling Ball Tilt Switch or Ball Sensor along with Raspberry Pi. Ball tilt switch allows you to detect an location or inclination they are small and easy to wired-up it use low
Starter #7 How to use Tilt Switch in Arduino with Sample Source Code
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