In this Illustration we will going to wire the mercury switch module is a family of the tilt switching sensor, and it has an on-board LED as indicator as power status it can be used to build a simple circuit
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