Tilt Sensor

The tilt sensor is a component that can detect the tilting of an object.

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.

The code example is exactly as the one we would use for a pushbutton but substituting this one with the tilt sensor. We use a pull-up resistor (thus use active-low to activate the pins) and connect the sensor to a digital input pin that we will read when needed.

The prototyping board has been populated with a 1K resistor to make the pull-up and the sensor itself. We have chosen the tilt sensor from Assemtech, which datasheet can be found here. The hardware was mounted and photographed by Anders Gran, the software comes from the basic Arduino examples.

Picture of a protoboard supporting the tilt sensor, by Anders Gran
Picture of a protoboard supporting the tilt sensor, by Anders Gran

1/* Tilt Sensor
2 * -----------
3 *
4 * Detects if the sensor has been tilted or not and
5 * lights up the LED if so. Note that due to the
6 * use of active low inputs (through a pull-up resistor)
7 * the input is at low when the sensor is active.
8 *
9 * (cleft) David Cuartielles for DojoCorp and K3
10 * @author: D. Cuartielles
11 *
12 */
13
14int ledPin = 13;
15int inPin = 7;
16int value = 0;
17
18void setup()
19{
20 pinMode(ledPin, OUTPUT); // initializes digital pin 13 as output
21 pinMode(inPin, INPUT); // initializes digital pin 7 as input
22}
23
24void loop()
25{
26 value = digitalRead(inPin); // reads the value at a digital input
27 digitalWrite(ledPin, value);
28}

Contribute to Arduino

Join the community and suggest improvements to this article via GitHub. Make sure to read out contribution policy before making your pull request.

Missing something?

Check out our store and get what you need to follow this tutorial.

Suggest Changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. You can read more on how to contribute in the contribution policy.