How to Connect Tilt Sensor Using Arduino Development Board

by avaqsemi in Circuits > Arduino

506 Views, 1 Favorites, 0 Comments

How to Connect Tilt Sensor Using Arduino Development Board

Arduino.jpg

A tilt sensor switch is an electronic device that can be used to detect the orientation of an object and output a high or low level accordingly. In fact, inside it there is a mercury ball that moves and creates a short circuit. This way the tilt sensor can close or break the loop depending on the direction.

In this project, we connected the Mercury switch/tilt sensor to the Arduino UNO development board. Then depending on the output of the tilt sensor, we control the LED and buzzer. Whenever we tilt the sensor, the alarm will turn on.

Supplies

● Mercury switch/tilt sensor

● Arduino UNO development board

● Buzzer

● LED indicator

● Resistor - 220 ohms

● Breadboard

● Connection wires

Circuit Diagram of the Connection Between the Tilt Sensor and Arduino

Arduino.jpg

To connect the tilt sensor to the Arduino development board, we need a 5v DC power supply to work. This 5v is provided using the Arduino UNO, and the output of the tilt sensor is connected to pin 4 of the Arduino. The LED is connected to Pin 2 of the Arduino UNO via a 220 ohm resistor to limit the current to a safe value. And, the buzzer is connected directly to PIN 3 of the Arduino UNO.

Tilt Sensor

sensor.png
Mercury switch.png

This is a Mercury switch based tilt sensor module that provides a high level at its output pins when tilted. It requires a 5V DC input. It is a three-terminal device consisting of an input, a ground and an output. It has a glass tube consisting of two electrodes and a liquid mercury sphere. The liquid mercury bulb closes as well as opens the circuit when it is tilted in a specific direction. The working and internal structure of the module is as follows:

The Working Process of the Tilt Sensor (without Tilt)

not tilted.png

Initially, when it is in the non-tiled position as shown below, it will output a low output because the liquid mercury closes the circuit by connecting two electrodes. When the output is low, the on-board LED will always be on.

The Working Process of the Tilt Sensor (tilt)

tilted.png

When it is tilted in a specific direction or angle, the liquid mercury breaks the contact between the metal electrodes and opens the circuit. Therefore, we output a high level in this case and the on-board LED goes out.

Code and Work Process Description

program.png

The complete code to connect the tilt sensor to the Arduino is given at the end of this article.

In the following code, we define the pins as inputs and outputs. Pins 2 and 3 are set as output pins for the LED and buzzer respectively, and pin 4 is set as input to capture the input data from the tilt sensor.

void setup() {

 pinMode(2, OUTPUT);

 pinMode(3, OUTPUT);

 pinMode(4, INPUT);

}

The output of the tilt sensor now becomes high whenever the tilt sensor is tilted beyond a specific angle. This output is read through pin 4. Therefore, whenever pin 4 is high, it turns on the LED and the buzzer.

void loop() {

 if (digitalRead(4) == 1)

 {

 digitalWrite(2, HIGH);  

 digitalWrite(3, HIGH);

 delay(300);            

 digitalWrite(2, LOW);  

 digitalWrite(3, LOW);

 delay(300); 

 }

}

This approach can be used in some very interesting projects, such as anti-theft boxes, alarm clock boxes or secret file boxes.

Code

The complete code for the Arduino connection to the tilt sensor is shown below:

void setup() {

 pinMode(2, OUTPUT);

 pinMode(3, OUTPUT);

 pinMode(4, INPUT);


}


void loop() {

 if (digitalRead(4) == 1)

 {

 digitalWrite(2, HIGH);  

 digitalWrite(3, HIGH);

 delay(300);            

 digitalWrite(2, LOW);   

 digitalWrite(3, LOW); 

 delay(300);  

 }

}