Arduino Lesson 10: Tilt Sensor
Arduino Lesson 10

Tilt Sensor

Tilt sensor acting as a switch

Components Required



In this example, you are learning how to use a Tilt sensor. Tilt sensor produces digital outputs such as high and low. Therefore, the tilt sensor works as a switch that gives on and off states.

Learning outcomes

  • Digital reads and print them on the serial monitor
  • Working principle of the tilt sensor


When the device gets power and is in its upright position, then the rolling ball settles at the bottom of the sensor to form an electrical connection between the two end terminals of the sensor.

Figure 1: Working principle of tilt sensor [1]


As the first step, you should connect a Magicbit tilt sensor to the Magicbit core board. For this, you can use one side connector from four-side connectors of the Magicbit core board or if you want to extend the length of the connection, you can use jumper wires. For this example, the tilt sensor was connected to the upper left connector of the Magicbit core board. Then connect the Magicbit to your pc and upload the code. You can get outputs using a serial monitor.



const int TILTpin = 32;

void setup() {
  pinMode (TILTpin, INPUT);

void loop() {
Outputs: Serial monitor

Figure 2: High state of the tilt sensor

Figure 3: Low state of the tilt sensor


Const int TILTpin: Defining input pin digitalRead: Read the data input of configured data pin.

Related Posts
Leave a Reply