Inquire: Call 0086-755-23203480, or reach out via the form below/your sales contact to discuss our design, manufacturing, and assembly capabilities.
Quote: Email your PCB files to Sales@pcbsync.com (Preferred for large files) or submit online. We will contact you promptly. Please ensure your email is correct.
Notes: For PCB fabrication, we require PCB design file in Gerber RS-274X format (most preferred), *.PCB/DDB (Protel, inform your program version) format or *.BRD (Eagle) format. For PCB assembly, we require PCB design file in above mentioned format, drilling file and BOM. Click to download BOM template To avoid file missing, please include all files into one folder and compress it into .zip or .rar format.
A tilt sensor Arduino setup provides one of the simplest ways to detect orientation changes in your projects. Unlike accelerometers that measure actual angles and g-forces, tilt sensors function as basic switches that tell you whether something is upright or tilted past a threshold.
I’ve used these sensors in security systems, automatic shutoff circuits, and novelty projects where simplicity matters more than precision. This guide covers practical wiring, code examples, and project ideas that work reliably.
How Tilt Sensors Work
Tilt sensors are mechanical devices containing either a metal ball or liquid mercury inside a sealed tube. Two electrical contacts protrude into this chamber.
When the sensor is upright (contacts pointing down), gravity pulls the conductive element onto both contacts, completing the circuit. When tilted beyond a certain angle, the ball or mercury rolls away, breaking the connection.
Tilt Sensor Types Comparison
Type
Internal Element
Sensitivity
Environmental Concern
Ball Switch (SW-520D)
Metal balls
~15° trigger angle
None
Mercury Switch
Liquid mercury
More precise
Toxic if broken
The SW-520D has become the standard choice for Arduino projects because it’s inexpensive, durable, and environmentally safe. Mercury switches offer better precision but pose hazards if damaged.
SW-520D Tilt Sensor Specifications
Parameter
Value
Operating Voltage
3.3V to 12V
Trigger Angle
±15° from vertical
Contact Current
20mA maximum
Conduction Time
~20ms
Insulation Resistance
10MΩ
Operating Temperature
Up to 100°C
The two leads have no polarity. Either pin can connect to power or ground, making wiring straightforward.
Tilt Sensor Arduino Wiring
The basic circuit requires only a pull-up resistor to provide a stable signal.
Basic Connection Table
Tilt Sensor
Arduino Uno
Pin 1
Digital Pin 2
Pin 2
GND
10kΩ Resistor
Between Pin 2 and 5V
The pull-up resistor ensures the Arduino reads HIGH when the circuit is open and LOW when the tilt sensor closes.
Module Version Connections
Pre-built tilt sensor modules include the resistor and sometimes a comparator chip. They typically have three pins:
Module Pin
Arduino Pin
VCC
5V
GND
GND
DO (Digital Out)
Digital Pin 2
Basic Tilt Detection Code
This sketch reads the sensor and prints status to Serial Monitor:
const int tiltPin = 2;
void setup() {
pinMode(tiltPin, INPUT);
Serial.begin(9600);
}
void loop() {
int tiltState = digitalRead(tiltPin);
if (tiltState == LOW) {
Serial.println(“Tilted”);
} else {
Serial.println(“Upright”);
}
delay(100);
}
Adding Debounce for Stability
Metal ball sensors bounce when transitioning between states. Debouncing prevents false triggers:
const int tiltPin = 2;
const int ledPin = 13;
int lastState = HIGH;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
void setup() {
pinMode(tiltPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
int reading = digitalRead(tiltPin);
if (reading != lastState) {
lastDebounceTime = millis();
}
if ((millis() – lastDebounceTime) > debounceDelay) {
digitalWrite(ledPin, !reading);
}
lastState = reading;
}
The 50ms delay filters out contact bounce while remaining responsive to actual orientation changes.
Practical Tilt Sensor Projects
Anti-Theft Alert System
Attach a tilt sensor to valuables. Any movement triggers an alarm:
const int tiltPin = 2;
const int buzzerPin = 8;
bool armed = false;
void setup() {
pinMode(tiltPin, INPUT);
pinMode(buzzerPin, OUTPUT);
delay(5000); // 5 second delay to position
armed = true;
}
void loop() {
if (armed && digitalRead(tiltPin) == LOW) {
tone(buzzerPin, 2000);
delay(500);
noTone(buzzerPin);
delay(500);
}
}
Directional Tilt Indicator
Using two sensors oriented 90° apart detects four directions:
Sensor 1
Sensor 2
Direction
HIGH
HIGH
Upright
LOW
HIGH
Tilted Left
HIGH
LOW
Tilted Right
LOW
LOW
Tilted Forward
Auto-Shutoff for Power Tools
Tilt sensors protect equipment by cutting power when tipped:
No. Tilt sensors only detect whether orientation exceeds a threshold (typically 15°). For actual angle measurement, use an accelerometer like the MPU6050 or ADXL345.
Why does my reading flicker when tilted?
The metal ball bounces during transitions. Implement software debouncing with a 50-100ms delay, or use a mercury switch for cleaner transitions.
How do I detect tilt in multiple directions?
Mount two or more tilt sensors at different orientations. Each covers one axis, and combining their states reveals the tilt direction.
Are tilt sensors affected by vibration?
Yes. Strong vibrations can momentarily break contact even when upright. For vibration-prone applications, increase debounce time or consider accelerometer-based detection.
Can I use tilt sensors with 3.3V boards?
Yes. The SW-520D works from 3.3V to 12V. Just ensure your pull-up resistor connects to the appropriate voltage for your board.
Limitations to Consider
Tilt sensors have inherent limitations worth understanding before building them into projects.
Temperature extremes can affect the ball’s movement characteristics. In very cold conditions, any condensation inside the sensor might temporarily affect contact reliability.
The trigger angle varies slightly between individual sensors. If your project requires precise triggering at exactly 15°, you’ll need to test and select sensors or consider accelerometer alternatives.
Continuous vibration environments pose challenges. A running motor nearby might cause false triggers even with debouncing. For such applications, increase debounce time significantly or add hysteresis logic that requires sustained tilt before triggering.
Mounting Best Practices
How you mount the sensor affects performance:
Secure mounting prevents the sensor housing from moving independently of the object being monitored. Hot glue or mechanical fasteners work better than tape for long-term installations.
Orient the sensor so the default position keeps the circuit closed. This way, a disconnected or broken wire fails safe by triggering the alert rather than silently failing.
Consider enclosing the sensor to protect the leads from bending or breaking during handling.
Comparing Tilt Sensors to Accelerometers
Feature
Tilt Sensor
Accelerometer
Output Type
Digital (on/off)
Analog/Digital (degrees)
Cost
$0.50-2.00
$3.00-15.00
Complexity
Very simple
Moderate
Precision
~15° threshold
0.1° typical
Power Consumption
Microamps
Milliamps
Vibration Resistance
Poor
Good (with filtering)
Choose tilt sensors when simplicity and cost matter most. Choose accelerometers when you need actual angle values or vibration rejection.
When to Choose Tilt Sensors
Tilt sensor Arduino projects work best when you need simple orientation detection without precise angle measurement. They excel in applications like theft deterrent systems where any movement triggers action, equipment safety shutoffs, toy and game controllers, position-dependent switching, and educational projects teaching basic sensor concepts.
Common real-world implementations include vending machine anti-tampering systems, boat capsize alarms, motorcycle lean detection for automatic indicators, picture frame level indicators, and children’s toys that respond to shaking or tipping.
For projects requiring actual angle data or smooth analog output, invest in an accelerometer instead. But for basic “tilted or not” detection, these inexpensive sensors deliver reliable results with minimal complexity.
The combination of low cost, zero power consumption in open state, and extreme simplicity makes tilt sensors an excellent choice when their binary nature matches your requirements.
Inquire: Call 0086-755-23203480, or reach out via the form below/your sales contact to discuss our design, manufacturing, and assembly capabilities.
Quote: Email your PCB files to Sales@pcbsync.com (Preferred for large files) or submit online. We will contact you promptly. Please ensure your email is correct.
Notes: For PCB fabrication, we require PCB design file in Gerber RS-274X format (most preferred), *.PCB/DDB (Protel, inform your program version) format or *.BRD (Eagle) format. For PCB assembly, we require PCB design file in above mentioned format, drilling file and BOM. Click to download BOM template To avoid file missing, please include all files into one folder and compress it into .zip or .rar format.