Tilt Sensor

In this project, you'll learn how to connect and use a tilt sensor to automatically turn on and off a LED.

A tilt sensor is a simple on-off switch for turning on and off an electric signal depending on whether the sensor is tilted or not. The switch is connected (on) when not tilted, and disconnected (off) when tilted.

Parts needed:
  • Arduino
  • A tilt sensor
  • A 22K Ω resistors (red-red-orange)
  • Wires
  • Breadboard
Tilt sensor 22K ohm resistor
1 Making the connections
  • Connect one end of the tilt sensor to positive 5V on the Arduino.
  • Connect the other end of the tilt sensor to pin 2 on the Arduino and to one end of the 22K Ω resistor.
  • Connect the other end of the resistor to GND on the Arduino.



Tilt sensor schematic
Tilt sensor connections
2 Create a new Bare Minimum program and type in this program.







The tilt sensor is connected to pin 2.
We use the interal LED that is connected to pin 13.


The pinMode command declares the tiltSensor pin to be for input, and the led pin to be for output.




The digitalRead command reads in a digital value (either HIGH or LOW) from the tiltSensor input pin, and stores the value in the tiltState variable.

The digitalWrite command will either turn on or off the internal LED depending on the value that is stored in the tiltState variable.
Tilt sensor program
3 Run the program.

Tilt the sensor and observe the internal LED on the Arduino board.