Mercury Switch Tilt Sensor With Arduino
by Utsource in Circuits > Arduino
1166 Views, 0 Favorites, 0 Comments
Mercury Switch Tilt Sensor With Arduino
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.
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
For this instructables we will need following things :
Mercury Switch/ Tilt Sensor
Arduino UNO
Buzzer
LED
Resistor - 220 ohm
Breadboard
Connecting wires
Schmatics
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
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);
}
}
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
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.