Tilt Switch

From SainSmart Wiki
Jump to: navigation, search

Tilt switch

What’s Tilt Sensor?

The tilt sensor is a component that can detect the tilting of an object. However it is only the equivalent to a pushbutton activated through a different physical mechanism. This type of sensor is the environmental-friendly version of a mercury-switch. It contains a metallic ball inside that will commute the two pins of the device from on to off and viceversa if the sensor reaches a certain angle.


Tilt switch controls led lamp light & out

Experiment component:

Tilt sensor : 1 Breadboard & Jumper wires

Connect your circuit as the below diagram.

Tilt switch connect to analog pin.



Example code void setup() {

   pinMode(8,OUTPUT);//set pin8 output

} void loop() {

   int i;//define i
             i=analogRead(5);//read voltage values of pin5
             if(i>200)//if more than 512(2.5V)
                   digitalWrite(8,HIGH);//light up led lamp
                   digitalWrite(8,LOW);//go out led lamp