A tilt sensor (also called a ball switch or mercury switch) is a digital switch that changes its output based on orientation. When tilted beyond a certain angle, the internal mechanism (metal ball or mercury drop) makes or breaks contact, changing the signal.
📌 Key Features:
Simple ON/OFF output
Detects if the object is upright or tilted
Digital signal (HIGH or LOW)
No orientation angle info — only tilt or no tilt
📦 Types of Tilt Sensors:
Type
Inside it
Behavior
Metal ball type
Rolling metal ball
Conducts when level
Mercury type
Liquid metal drop
Conducts when tilted
MEMS Tilt Module
Accelerometer-based
Gives angle info
We’ll focus on the basic ball type, which is easiest to use with ESP32.
🧰 Components Needed:
ESP32 board
Tilt sensor module (KY-017, SW-520D, or similar)
Jumper wires
LED (optional for output)
🧪 How It Works:
Inside the sensor is a small metal ball.
When upright → ball connects two metal contacts → Circuit closed → Output LOW
When tilted → ball breaks contact → Circuit open → Output HIGH (or floating)
Some modules have built-in pull-up resistors and LED to indicate state.
🔌 Wiring Tilt Sensor to ESP32
Tilt Sensor Pin
ESP32 Pin
VCC
3.3V or 5V
GND
GND
OUT
GPIO 14 (or any digital pin)
🧠 What This Code Does:
Reads digital value from the sensor.
If LOW: the sensor is upright.
If HIGH: the sensor is tilted.
LED shows the state.
💡 Real-world Applications
Use Case
Description
🛠️ Anti-Tamper Alarm
Alert when a box/device is moved
🔒 Laptop Security
Lock or alert if tilted or stolen
🎮 Game Controller
Basic motion control in DIY games
🛑 Vehicle Crash Alert
Detect if a device tips over
📦 Package Monitoring
Detect tilting during delivery/shipping
🛠️ Sensor Not Working? Troubleshooting:
Problem
Fix
No response
Check VCC, GND, and OUT connection
Inverted readings
Try changing logic (HIGH/LOW check)
Floating output
Add external pull-up/down resistor
No LED on module
Try tilting more or check supply voltage
HOW TO OPERATE// #include <LiquidCrystal_I2C.h>#defineMOI 15// LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line displayvoidsetup(){pinMode(MOI,INPUT);Serial.begin(9600);Serial.println("MOISTURE START");// lcd.init();// lcd.backlight();// lcd.setCursor(3,0);// lcd.print("moisture data");// lcd.setCursor(3, 1);}voidloop(){int data=analogRead(MOI);Serial.println(data);// lcd.print(data);delay(1000);// lcd.clear();}
📡 What is SIM900?The SIM900 is a GSM/GPRS module from SIMCom. It allows microcontrollers like ESP32 or Arduino to:✅ Send/receive SMS✅ Make/receive phone calls✅ Connect to... Read More
⏰ What is DS1307 RTC?The DS1307 is a real-time clock IC by Maxim Integrated that keeps track of:SecondsMinutesHours (12 or 24-hour mode)Day, Date, Month, YearAutomatically adjusts... Read More
IntroductionWith the rise of IoT-based energy monitoring systems, measuring electrical parameters like voltage, current, power, and energy consumption has become... Read More
The Gravity Voice Recognition Module is a user-friendly module developed by DFRobot that allows microcontrollers like Arduino or ESP32 to recognize voice commands offline (without internet... Read More
The SSD1306 is a popular controller used in OLED (Organic Light Emitting Diode) displays, most commonly found in small monochrome displays like 128x64 or 128x32 resolution screens. These displays are... Read More
🧠 What is a PIR Sensor?PIR = Passive Infrared SensorA PIR sensor detects motion by measuring changes in infrared radiation.Every warm object (like... Read More
📌 What is ESP-NOW?ESP-NOW is a wireless communication protocol developed by Espressif, allowing ESP32 boards to send and receive data directly without Wi-Fi... Read More
ESP32 Joystick Controlled Robot Using ESP-NOW Protocol & L298N Motor DriverWireless bot control with speed adjustment via joystick tilt📝 IntroductionIn... Read More
Leave a Reply
You must be logged in to post a comment.