Mercury Switch Tilt Sensor With Arduino

by Utsource in Circuits > Arduino

1166 Views, 0 Favorites, 0 Comments

Mercury Switch Tilt Sensor With Arduino

Screenshot_20191122-140820__01.jpg
Hi guys in this instructables we will learn how to use Mercury Switch Tilt sensor with Arduino.

A Tilt Sensor switch is an electronic device that detects the orientation of an object and gives its output High or Low accordingly. Basically, it has a mercury ball inside it which moves and makes the circuit. So tilt sensor can turn on or off the circuit based on the orientation.
In this project, we are interfacing Mercury switch / Tilt sensor with Arduino UNO. We are controlling a LED and buzzer according to the output of the tilt sensor. Whenever we tilt the sensor the alarm will be turned on. You can also see the working of tilt sensor in this tilt sensor circuit.

Things You Need

Km5Zu-2RIncAUweU7uG7IhyWPySZ0SqIgAI0-vk9w7767_IkthCPCcsirj2GGmXF4IdQDg8UVpHVLVM6CXnzFsG1hnAdSkK7BIhIOtEldXoZiDsvzsPo-6o0rD6Mda7UyOE=w456-h323-nc.png
images.jpeg

For this instructables we will need following things :

Mercury Switch/ Tilt Sensor
Arduino UNO
Buzzer
LED
Resistor - 220 ohm
Breadboard
Connecting wires

Schmatics

Interfacing-circuit-diagram-of-Tilt-Sensor-with-Arduino.png
To connect a Tilt sensor with the Arduino, it requires 5v dc input to operate. That 5v is supplied using Arduino UNO and the output of Tilt sensor is taken at PIN 4 of the Arduino. LED is connected with the PIN 2 of the Arduino UNO with 220-ohm resistor to limit the current to a safe value. And, the buzzer is directly connected to the PIN 3 of the Arduino UNO.

Code

20191121_193959.jpg
Please copy the following code and upload it to your arduino Board :

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);
}
}

Testing the Sensor

Screenshot_20191122-140820__01.jpg
Screenshot_20191122-140805__01.jpg
After connecting everything together and uploading the code to arduino IDE , whenever you will tilt the sensor then the buzzer will beep and the LED will blink according to the rotation of sensor.