In this tutorial, we will learn how to interface a tilt sensor with Arduino.
A tilt sensor is used to detect a movement, tilted or shaken of an object.
The tilt sensor is commonly a ball bearing in a box with contacts at one end. When the box is tilted the ball rolls away from the contact and the connection is a loss.
On the other hand, when the box is tilted to roll the other way the ball touches the contact and completes the circuit.
The tilt sensor is sensitive to small movement of around 5 to 10 degrees when oriented with the ball just touching the contacts.
Tilt Sensor Pinout
Tilt Sensor has three pins are:
- 5V / VCC
- Tilt Sensor.
- Jumper Wires.
Circuit Diagram for Tilt Sensor with Arduino
The code uses a switch that closes a circuit when tilted, called a tilt sensor.
The below code will switch on the LED attached to pin 11 when the tilt sensors are tilted one way, and the LED connected to pin 12 will switch on when it is tilted the other way:
Use of only Tilt Sensor Switch with Arduino
The tilt sensor switch is the main part of the whole sensor module. We can only use this switch with Arduino.
Circuit Diagram for Tilt Switch
Code for Tilt Switch
Detect Change in the State of Sensor
To determine if something is being shaken, we need to check how long it’s been since the state of the tilt sensor changed.
If it hasn’t changed for a time you consider significant, the object is not shaking. Changing the orientation of the tilt sensor will change how vigorous the shaking need to be to trigger it.
Remove the LED from Pin 11.
Code for Check the Sensor state
The following code turns on an LED when the sensor is shaken.