Interfacing Tilt Sensor with Arduino UNO

A tilt sensor is a device that produces an electrical signal which is proportional to the angular movement. Orientation or Inclination can be detected using these sensors. They are sometimes referred as "mercury switches", "rolling ball sensors", "tilt switches", "inclinometer", "accelerometer". Tilt sensors are used in various fields like robotics, aviation, vehicle secular systems, portable computers.


Hardware List:


The components required to implement the circuit are as follows:


1.Arduino Board


Arduino Board


Arduino is an open-source microcontroller board. Analog or digital signals from different sensors can be read by Arduino. An Arduino Integrated Development Environment (IDE) software is available to write and upload the code to the physical Arduino board.


2.Tilt Switch ball



Tilt Switch Ball

A tilt Switch ball is a sensor that measures orientation or inclination. It is the component used to detect any inclination or orientation.


3.Bread Board


Breadboard


Bread Board is the basic component that is required to design any circuit. Electrical connections can be established between electronic components using a breadboard. It can be used to test the circuits before being soldered permanently.



4.Jumper Wires



Jumper Wires



Jumper wires are the wires that are used in connecting pins of Arduino to the breadboard. In this project male to male jumper wires are used that connects the female header pin of Arduino to the breadboard.



5.Resistor

220 ohms Resistor


Resistors are the components that limit the flow of current in an electronic circuit. The resistor used in this project is 220 ohms. The 4-band color of this resistor is Red, Red, Brown, Gold.


6. LEDs



LED



Light Emitting Diode (LED) is a semiconductor light source used as an indicator lamp. LED in this project indicates the tilt by Arduino.


Circuit:


The connections of the circuit are shown in the circuit diagram below.


Circuit Diagram


Jumper Wires are used to connect Arduino with Breadboard. Anode of LED is connected to pin 9, Cathode of LED is connected to ground (GND) through 220-ohm resistor. One end of the Tilt Sensor is connected to pin 8 and the other end connected to the ground (GND).


Code:


The following code is uploaded into the Arduino board using Arduino IDE software.

const int ledPin = 9;   //led is connected to pin 9 of arduino 

const int sensorPin=8;  //tilt switch is connected to pin 8 of arduino

The connections of LED and Tilt Switch to Arduino are established using the above lines of code.


void setup()
{ 
  pinMode(ledPin,OUTPUT); 
  pinMode(sensorPin,INPUT);
  digitalWrite(sensorPin, HIGH);
} 


In the first void setup, pin 8 is set as input, and pin 9 is set to high which is set to output.


void loop() 
{  
  if(digitalRead(sensorPin) == HIGH)    // switch is open
  { digitalWrite(ledPin,LOW); }     //turn the led off
  else                            // switch is closed
  { digitalWrite(ledPin,HIGH); }    //turn the led on 

}



In the void loop, the code to open and close the switch is written. The LED is turned off when the switch is open and turned on when the switch is closed.



Complete code:


const int ledPin = 9;   //led is connected to pin 9 of arduino

const int sensorPin=8; //tilt switch is connected to pin 8 of arduino

void setup()
{ 
  pinMode(ledPin,OUTPUT); 
  pinMode(sensorPin,INPUT);
  digitalWrite(sensorPin, HIGH);
} 

void loop() 
{  
  if(digitalRead(sensorPin) == HIGH)    // switch is open
  { digitalWrite(ledPin,LOW); }     //turn the led off
  else                            // switch is closed
  { digitalWrite(ledPin,HIGH); }    //turn the led on 
}

Download the code from below.

Tilt_Ball_Switch
.txt
Download TXT • 492B


Working:


A tilt sensor is a switch that turns on or off when it oriented at a certain angle. In this project, a roller-based tilt switch is used. To open or close a switch in roller-based tilt switch one or two metal balls are used. The switch is closed when the sensor is upright. The metal ball will be in contact with the two terminals when the sensor is upright making the switch to be closed. When the sensor is tilted at an angle the connection between the terminals is lost as the metal ball moves and loses contact with the terminals making the switch open. The working of the Tilt sensor is illustrated in the following figure.



After all the circuit connections are made and before powering ON the circuit is as shown below.




After interfacing the Arduino and uploading the code and the circuit works as per the instructions given in the code and the orientation is detected and is indicated by LED.


The circuit below shows the output when the roller ball switch is upright.




The video below explains the circuit connections, working of the circuit, working of the code, and LED indication i.e., observing the output.


Video By :- Anupama Koley



See Also-

  1. Object Detection using Ultrasonic sensor.

  2. Arduino DIY Calculator using Keypad.



  • Facebook
  • YouTube
  • Instagram
  • LinkedIn
LearnElectronics
Contact Us