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();}
IntroductionMeasuring AC voltage using ESP32 is a common requirement in IoT, energy monitoring, and automation projects. In this guide, we... Read More
Water quality is one of the most important factors in drinking water, aquaculture, industries, and environmental monitoring. A Turbidity Sensor... Read More
 08-06-2025ð§Â Basic IntroductionL298N is a dual H-Bridge motor driver IC that allows controlling the direction and speed of two DC motors or... Read More
ESP32 with a water level sensor:Hardware Setup:Gather the necessary components:ESP32 development boardWater level sensor moduleJumper wiresBreadboard (optional)Power supply (3.3V or... Read More
IntroductionThe ESP32-S3 Super Mini is a powerful compact development board based on the ESP32-S3 chip. It provides high performance, WiFi,... Read More
 23-07-2025ð What is a Rotary Encoder?A rotary encoder is an electro-mechanical sensor that converts the angular position or motion of a rotating shaft into digital... Read More
The ESP32 HW-138 4 Touch Control System is a modern capacitive touch-based control solution that replaces traditional mechanical switches. Using... Read More
Leave a Reply
You must be logged in to post a comment.