Menu Close

Arduino – Tilt Sensor

This tutorial explains how to use Tilt Sensor with Arduino.

1. Introduction:

Tilt sensors are devices that produce an electrical signal that varies with an angular movement. These sensors are used to measure slope and tilt within a limited range of motion.

Tilt sensors is used to detect orientation or inclination. Sometimes they are also referred as inclinometers, tilt switches, mercury switches or rolling ball sensors.

2. Working Principle:

Tilt sensor consist of a conductive free mass inside, such as blob of mercury or rolling ball and one end of the sensor has two conductive poles.

When the power is supplied, the rolling ball falls to the buttom of the sensor to form an electric connection. When the sensor is tilted, the rolling ball doesn’t fall to the bottom so that the current cannot flow the two end terminals of the sensor. Tilt sensors are widely used in mobile phones for auto rotation function, in games, satellites, vehicles.

3. Hardware required

S.No.ItemQuantity
1.Arduino 1
2.Breadboard 1
3.Tilt Sensor 1
4.LED 1
5.Resistor 1K 1
6.Male to Female Jumper Wires 3
7Male to Male Jumper Wires 2

4. Circuit Diagram

Make the following connections with Arduino-

5. Programming

//Robo India tutorial on Tilt Sensor 
//Hadware Required: Tilt Sensor and Ardino
//https://www.roboindia.com/tutorials

int sensor = 2;                 // tilt sensor as input pin
int LED = 4;                    // led as output pin

boolean switchState = false;   
int sensorState=0;              // current state

void setup()
{
pinMode(sensor, INPUT);
digitalWrite(sensor, HIGH);      //set the sensor as HIGH
pinMode(LED, OUTPUT);
}

void loop()
{
sensorState=digitalRead(sensor); //read value of the sensor either high or low

if(sensorState==HIGH)            //when tilt switch lays flat 
{
  if(switchState==false)
    switchState=true;
  else
    switchState=false;
}
if(switchState==true)
{
  digitalWrite(LED,HIGH);          
}
else
{
  digitalWrite(LED, LOW);      //when switch tilt on some angle 
}
delay(1000);
}


6. Output

Tilt the sensor, and the Led connected to the circuit, will glow up. and when we put sensor flat on table, Led will turn off.

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com

Leave a Reply