An Arduino-based tilt detection system with adjustable alarm frequency, featuring a 7-segment display for visual feedback and synchronized buzzer/LED alerts.
This project implements a tilt-activated alarm system using a tilt sensor (ball switch). When the device is tilted, it triggers synchronized visual (LED + 7-segment display) and auditory (buzzer) alerts. A potentiometer allows real-time adjustment of alarm frequency, with the current sensitivity level displayed on a 7-segment LED digit (0-9).
- Tilt detection using ball switch sensor with INPUT_PULLUP
- Adjustable alarm frequency via potentiometer (0-9 levels)
- 7-segment display showing current sensitivity setting
- Synchronized alerts: LED and buzzer blink/beep in perfect sync
- Variable beep rate: 50ms (fast) to 500ms (slow) based on pot setting
- Real-time feedback: Frequency adjustment visible on display
- Low power standby: Silent operation when device is level
- Arduino Uno
- Tilt Sensor (Ball Switch / Mercury Switch)
- 7-Segment Common Cathode LED Display (single digit)
- Active/Passive Buzzer
- LED (Red)
- 10kΩ Potentiometer
- 7× 220Ω Resistors (for 7-segment display)
- 1× 220Ω Resistor (for LED)
- Breadboard
- Jumper wires
| Component | Arduino Pin | Notes |
|---|---|---|
| Potentiometer | A0 | Analog input for frequency control |
| Buzzer | D9 | PWM capable for tone() |
| Tilt Sensor | D10 | INPUT_PULLUP mode |
| Red LED | D12 | Digital output |
| 7-Segment Display: | ||
| Center (g) | D2 | Middle horizontal segment |
| Top Left (f) | D3 | Upper left vertical |
| Top (a) | D4 | Top horizontal |
| Top Right (b) | D5 | Upper right vertical |
| Bottom Left (e) | D6 | Lower left vertical |
| Bottom (d) | D7 | Bottom horizontal |
| Bottom Right (c) | D8 | Lower right vertical |
a (D4)
┌────────┐
f │ │ b
(D3)│ │(D5)
├────────┤ g (D2)
e │ │ c
(D6)│ │(D8)
└────────┘
d (D7)
Each segment connects through a 220Ω resistor to its respective Arduino pin. Common cathode pin connects to GND.
Arduino Pin → [220Ω] → Display Segment
Common Cathode → GND
Tilt Sensor Pin 1 → D10 (INPUT_PULLUP)
Tilt Sensor Pin 2 → GND
Buzzer (+) → D9
Buzzer (-) → GND
D12 → [220Ω] → LED Anode → LED Cathode → GND
Pot Left → GND
Pot Center → A0
Pot Right → 5V
The tilt sensor (ball switch) contains a small metal ball that completes a circuit when tilted. With INPUT_PULLUP enabled, the sensor reads:
- HIGH when tilted (ball disconnected, internal pull-up active)
- LOW when level (ball connects pin to GND)
int mappedPotValue = map(potValue, 0, 1023, 0, 10); // 0-9 display
int beepDelay = map(mappedPotValue, 0, 9, 500, 50); // 500ms-50ms- Potentiometer position → 0-9 level on display
- Higher number → Faster beeping (lower delay)
- Level 0: Slow (500ms between beeps)
- Level 9: Fast (50ms between beeps)
The displayDigit() function uses switch-case to light up specific segments for each digit (0-9). All segments start HIGH (off for common cathode), then specific segments are set LOW to illuminate and form the digit.
tone(BUZZER, 1000); // Start 1kHz tone
digitalWrite(LED, HIGH); // LED on
delay(100); // Both stay on 100ms
noTone(BUZZER); // Stop tone
digitalWrite(LED, LOW); // LED off
delay(beepDelay); // Both stay off (variable)- Clone this repository:
git clone https://github.com/atasayugras/tilt_sensor.git
cd tilt_sensor-
Open
tilt_sensor.inoin Arduino IDE -
Connect hardware according to pin configuration
-
Upload to Arduino Uno
-
Adjust potentiometer to set desired sensitivity
- Power on the Arduino
- The 7-segment display shows current frequency level (0-9)
- Adjust potentiometer to change alert frequency
- When device is tilted:
- Red LED blinks
- Buzzer beeps at 1kHz
- Rate determined by potentiometer setting
- Return device to level position to silence alarm
Change the tone frequency (default 1000 Hz):
tone(BUZZER, 1500); // Higher pitch
tone(BUZZER, 500); // Lower pitchModify the ON time (default 100ms):
delay(150); // LED/buzzer stay on longerAdjust beep interval mapping:
int beepDelay = map(mappedPotValue, 0, 9, 1000, 100); // Slower rangesetup(): Initializes all pins (buzzer, sensor, LED, 7-segment segments)loop(): Reads potentiometer, updates display, checks tilt sensor, triggers alertsdisplayDigit(int): Controls 7-segment display to show digits 0-9- Uses common cathode logic (LOW = segment on, HIGH = segment off)
- 7-Segment Type: Common cathode (not common anode)
- Tilt Sensor: INPUT_PULLUP eliminates need for external resistor
- Buzzer Control: Uses
tone()function for precise frequency generation - Display Refresh: 100ms delay prevents flickering
- PWM Pin: Buzzer on D9 for tone() compatibility
- Segment Mapping: Standard 7-segment pinout (a-g segments)
- Anti-theft alarm systems
- Earthquake/vibration detection
- Orientation monitoring
- Tilt-activated switches
- Package handling alerts
- Vehicle rollover detection
- DIY security systems
Display shows wrong numbers:
- Verify 7-segment is common cathode (not common anode)
- Check pin mappings match your display's pinout
- Test individual segments by setting pins LOW one at a time
Buzzer always on/always off:
- Ensure buzzer is connected to PWM-capable pin (D9)
- Check polarity of buzzer (+ to D9, - to GND)
- Verify
tone()andnoTone()calls are balanced
Tilt sensor not responding:
- Test sensor with multimeter (should show continuity when tilted)
- Verify INPUT_PULLUP is enabled
- Check sensor orientation (some are directional)
Display flickers:
- Increase delay(100) in loop if refresh is too fast
- Add decoupling capacitor (0.1µF) near display VCC/GND
- Ensure proper current-limiting resistors (220Ω per segment)
Erratic potentiometer readings:
- Add smoothing: average multiple analogRead() calls
- Check for loose connections
- Clean potentiometer contacts if dirty
- Add second digit for 00-99 range display
- Implement EEPROM storage for pot setting persistence
- Add acceleration sensitivity modes
- Include RGB LED for color-coded alerts
- Implement pattern-based alarm sounds
- Add I2C LCD for detailed status messages
- Include temperature compensation for sensor drift
If your display differs, map segments accordingly:
Standard Layout: Arduino Pins:
a D4
┌───┐ D3 D5
f │ │ b ┌─D2─┐
├─g─┤ D6 D8
e │ │ c D7
└───┘
d
MIT License - feel free to modify and use for your projects.
Built as a learning project for Arduino sensor integration and multi-component synchronization.
