Tilt Switch is a component that detects if it’s right side up or tilted.
Materials
- 1 Arduino Uno board
- 1 Basic Education shield
- 1 Tinkerkit tilt switch
- 1 TinkerKit wire
Instructions
- Connect the Tilt Switch with TinkerKit wire
- Connect the other end of the wire to to D10 on the shield.
In the Arduino IDE open Example>BasicEducationShield>Help>TiltSwitch.
/* TiltSwitch */ #include <BasicEducationShield.h> TiltSwitch me=TiltSwitch(10); void setup(){ Serial.begin(9600); //Initialize the component. Must be called. me.begin(); } void loop(){ Serial.println("Please tilt..."); //Wait until the tilt switch is tilted. Serial.println(me.pressed()); }
Note: The Tilt Switch only have 2 states, up-right or not up-right. It does not detect whether it’s upside down or measures the angle of the tilt. So make sure it suits your project, and if you’re using it, it’s recommended that it starts with up-right.
It’s not working
- Make sure you’ve connected the sensor to the same pin as stated in the code.