Interfacing Tilt Switch with Arduino
Tilt Switch Module
A Tilt Switch is a simple sensor used to detect orientation or inclination. It acts like a basic on/off switch that changes state when tilted beyond a certain angle, making it useful for motion detection and safety alerts.
Working Principle of Tilt Switch
The Tilt Switch works using a conductive rolling element (like a metal ball) inside the sensor. When the sensor is tilted, the ball moves and either makes or breaks a connection between internal terminals, changing the output state.
Types of Tilt Switches
Mercury Tilt Switch
- Mercury acts as the conductive material.
- Completes the circuit only when the sensor is in a specific orientation.
- Highly sensitive but less environmentally friendly.
Ball Tilt Switch
- Metal ball rolls inside the tube.
- Connects or disconnects internal terminals.
- Durable and widely used in hobby projects.
Requirements
1. Arduino Board
2. Tilt Switch Module
3. LED (for output indicator)
4. 220 ohm resistor and jumper wires
Pin Configuration of Tilt Switch Module
Tilt Switch Module
- VCC: Connect to +5V on Arduino.
- GND: Connect to GND on Arduino.
- DO: Digital Output pin — goes HIGH or LOW based on tilt.
Wiring the Tilt Switch to Arduino
Connect the VCC of the Tilt Switch to the 5V pin on Arduino and GND to ground. The digital output (DO) pin connects to a digital input on the Arduino (e.g., D2). You can also add a pull-down resistor to stabilize the reading.
Algorithm
Initialize Components
- Connect the VCC and GND of the Tilt Switch to 5V and GND on the Arduino.
- Connect the DO pin to a digital pin like D2.
Write the Code
- Set the sensor pin as INPUT in the setup() function.
- In the loop() function, read the sensor's digital value using digitalRead().
- Use conditions to trigger actions when the sensor detects tilt.
Display or React to Sensor Output
- Print the sensor output to the Serial Monitor for testing.
- Activate an LED, buzzer, or other device when tilt is detected.
Test the Circuit
- Upload the code to the Arduino.
- Tilt the sensor and observe the LED or output behavior.
1// Tilt Switch with Arduino
2const int tiltPin = 2; // Tilt switch connected to digital pin 2
3const int ledPin = 13; // On-board LED to indicate tilt state
4
5void setup() {
6 pinMode(tiltPin, INPUT);
7 pinMode(ledPin, OUTPUT);
8 Serial.begin(9600);
9}
10
11void loop() {
12 int state = digitalRead(tiltPin);
13
14 if (state == HIGH) {
15 digitalWrite(ledPin, HIGH);
16 Serial.println("Tilt detected!");
17 } else {
18 digitalWrite(ledPin, LOW);
19 Serial.println("No tilt.");
20 }
21
22 delay(200); // Slight delay for stability
23}
24
Applications of Tilt Switches
- Fall detection systems
- Anti-theft motion alarms
- Smart devices with orientation control
- Game controllers and gesture detection
- Home automation triggers
- Vibration or tilt-based safety systems
Conclusion
The Tilt Switch is a cost-effective way to detect orientation or motion in Arduino projects. Whether you're building a smart alarm system or a motion-triggered device, it provides a simple yet reliable input.