Tilt Sensor Example

Tilt Sensor

The tilt sensor is essentially a button, activated by its movement rather than a click with your finger. So these sensors are used to detect movements. For example, you can place a tilt sensor to an object and then you can monitor its movement.

Hardware Required

Arduino Board

Tilt sensor

LED

Resistor 220 ohm

Circuit

Connect the tilt sensor to the Ground and 5V PINs of your board. Between the 5V and the tilt PIN there's a 10K resistance. Then wire up the 5V PIN of the sensor to the Arduino Board PIN digital 2.

Schematics

Code

The sketch code defines variable used to control the Tilt sensor and the LED. There are also other varibles used to determine the current/previous status, a variable to evaulate the threshold and timing. The void loop repeatly reads the tilt sensor PIN. If a movement is detected, it changes the LED status to HIGH or LOW. The LED status is changed if the current read operation has been made after "threshold" time. If the tilt sensor does not detect a movement after "threshold" time elapsed, the LED status will be reset.