Interfacing Mercury Switch with Arduino
Mercury Switch
A Mercury Switch is a type of tilt switch that uses a small amount of liquid mercury inside a sealed glass tube. When the switch is tilted, the mercury moves to complete or break an electrical circuit. It's a simple and reliable way to detect orientation or position changes.
Working Principle of Mercury Switch
The Mercury Switch operates based on gravity and the conductive properties of mercury. When the switch tilts to a certain angle, the mercury flows and connects the internal contacts, closing the circuit. If tilted back, the connection is broken.
Types of Tilt Switches
Mercury Tilt Switch
- Contains a small mercury blob inside a glass enclosure.
- Tilting the switch moves the mercury to bridge or separate contacts.
- Completes or interrupts the circuit based on position.
Ball Tilt Switch
- Tilting moves the metal ball to create or break contact.
- Cheaper alternative but less accurate than mercury switches.
- Used in DIY and basic electronics projects.
Requirements
1. Arduino
2. Mercury Switch or Mercury Switch Module
3. 10K resistor (if needed for pull-down)
4. Jumper wires
Pin Configuration of Mercury Switch
Mercury Tilt Switch Module
- VCC: Connect to +5V on Arduino.
- GND: Connect to GND on Arduino.
- OUT: Connect to a digital pin on Arduino to read the state.
Wiring the Mercury Switch to Arduino
To connect the Mercury Switch to an Arduino, wire VCC to 5V, GND to ground, and OUT to any digital input pin. When the switch is tilted, the output pin will change state, allowing the Arduino to detect orientation changes.
Algorithm
Initialize Components
- Connect VCC to 5V and GND to GND on Arduino.
- Connect OUT pin to a digital input pin, e.g., D2.
Write the Code
- Set the input pin using pinMode in setup().
- Read the switch state using digitalRead() in the loop().
- Trigger an LED or buzzer based on the switch status.
Test the Sensor
- Upload the code to the Arduino.
- Tilt the Mercury Switch to see changes in output.
- Observe response on the serial monitor or output device.
Arduino Code
1const int mercuryPin = 2; // Digital input from mercury switch
2
3void setup() {
4 pinMode(mercuryPin, INPUT); // Set as input
5 Serial.begin(9600);
6}
7
8void loop() {
9 int state = digitalRead(mercuryPin); // Read HIGH or LOW
10
11 if (state == HIGH) {
12 Serial.println("Switch is Closed (Tilted)");
13 } else {
14 Serial.println("Switch is Open (Upright)");
15 }
16
17 delay(500);
18}
19
Applications of Mercury Switches
- Tilt and vibration detection
- Fall or drop alarms
- Position sensing in robotics
- Anti-theft alarms
- Simple motion detectors
- Balance and stability monitoring
Conclusion
Interfacing a Mercury Switch with Arduino offers a simple yet effective way to detect tilt or position changes. This setup is ideal for security systems, orientation sensing, and DIY automation projects.