Arduino code and video for a tilt sensor
This project demonstrates how to build a simple tilt sensor using an Arduino. This sensor can be used in a variety of applications where detecting changes in orientation is crucial. Here are some ideas:

- Robotics: Incorporate the tilt sensor into a robotic arm to detect its position and orientation.
- Security Systems: Use it as a basic tilt switch for a security alarm, triggering an alert if an object is moved.
- Industrial Monitoring: Monitor the tilt of machinery or equipment to detect potential malfunctions or instability.
- Game Controllers: Integrate it into a custom game controller for tilt-based inputs.
The project utilizes a tilt sensor module, an Arduino microcontroller, and a few basic components to create a functional tilt detection system. The sensor outputs a low signal when tilted, which the Arduino interprets to trigger an LED and a buzzer (in video at 00:18).
Hardware/Components
The hardware required for this project includes: (in video at 00:49)
- Arduino Uno (or compatible)
- Tilt Sensor Module
- Buzzer
- LED
- 220Ω Resistor (for the LED)
- Jumper Wires
Wiring Guide
The wiring is straightforward. Refer to the video for a visual guide. (in video at 02:36) The key connections are:
- Tilt Sensor VCC to Arduino 5V
- Tilt Sensor GND to Arduino GND
- Tilt Sensor DO to Arduino pin 2
- LED positive leg to Arduino pin 8 through a 220Ω resistor
- LED negative leg to Arduino GND
- Buzzer positive leg to Arduino pin 8
- Buzzer negative leg to Arduino GND

Code Explanation
The Arduino code is designed to read the tilt sensor's output and control the LED and buzzer accordingly. (in video at 04:30)
#define TILT 2 // pin 2 for tilt sensor
#define LED 8 // pin 8 for LED and buzzer
The TILT and LED constants define the Arduino pins connected to the tilt sensor and the output components, respectively. You can change these pin numbers to match your wiring. The core logic is in the loop() function: (in video at 05:36)
int TILT_SENSED = digitalRead(TILT);
if(TILT_SENSED == LOW) {
digitalWrite(LED, HIGH);
Serial.println("Tilt detected");
} else {
digitalWrite(LED, LOW);
Serial.println("Normal");
}
The code reads the tilt sensor's state using digitalRead(). If the sensor is tilted (LOW), the LED and buzzer are activated (HIGH); otherwise, they are deactivated (LOW).
The delay(200); function (in video at 07:16) controls the reading frequency of the sensor. Adjust this value to change how often the sensor is checked.
Live Project/Demonstration
The video demonstrates the functionality of the tilt sensor. (in video at 07:34) When the device is tilted in the designated direction, the LED illuminates, and the buzzer sounds, indicating that a tilt has been detected. The sensitivity of the sensor can be adjusted using a potentiometer (in video at 07:50), allowing you to fine-tune its responsiveness.
Chapters
- [00:06] Introduction
- [00:49] Hardware Overview
- [01:08] Tilt Sensor Details
- [02:36] Wiring Explanation
- [04:30] Code Explanation
- [07:34] Live Demonstration
- [08:21] Conclusion
Things you might need
-
eBay
-
AliExpressPurchase Ball Telt Sensor from AliExpresss.click.aliexpress.com
Resources & references
No resources yet.
Files📁
No files available.
