Skip to content

Tilt sensor alarm system with synchronized LED/buzzer alerts, 7-segment frequency display (0-9), and real-time potentiometer adjustment for Arduino Uno

Notifications You must be signed in to change notification settings

atasayugras/tilt_sensor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Tilt Sensor Alarm System

An Arduino-based tilt detection system with adjustable alarm frequency, featuring a 7-segment display for visual feedback and synchronized buzzer/LED alerts.

Demo

Overview

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).

Features

  • 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

Hardware Requirements

  • 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

Pin Configuration

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

7-Segment Display Wiring

Segment Layout

     a (D4)
   ┌────────┐
 f │        │ b
(D3)│        │(D5)
   ├────────┤ g (D2)
 e │        │ c
(D6)│        │(D8)
   └────────┘
     d (D7)

Connections

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

Circuit Wiring

Tilt Sensor

Tilt Sensor Pin 1 → D10 (INPUT_PULLUP)
Tilt Sensor Pin 2 → GND

Buzzer

Buzzer (+) → D9
Buzzer (-) → GND

LED

D12 → [220Ω] → LED Anode → LED Cathode → GND

Potentiometer

Pot Left → GND
Pot Center → A0
Pot Right → 5V

How It Works

Tilt Detection

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)

Frequency Control

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)

7-Segment Display Logic

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.

Alert Synchronization

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)

Installation

  1. Clone this repository:
git clone https://github.com/atasayugras/tilt_sensor.git
cd tilt_sensor
  1. Open tilt_sensor.ino in Arduino IDE

  2. Connect hardware according to pin configuration

  3. Upload to Arduino Uno

  4. Adjust potentiometer to set desired sensitivity

Usage

  1. Power on the Arduino
  2. The 7-segment display shows current frequency level (0-9)
  3. Adjust potentiometer to change alert frequency
  4. When device is tilted:
    • Red LED blinks
    • Buzzer beeps at 1kHz
    • Rate determined by potentiometer setting
  5. Return device to level position to silence alarm

Calibration

Adjusting Buzzer Pitch

Change the tone frequency (default 1000 Hz):

tone(BUZZER, 1500);  // Higher pitch
tone(BUZZER, 500);   // Lower pitch

Adjusting Alert Duration

Modify the ON time (default 100ms):

delay(150);  // LED/buzzer stay on longer

Frequency Range

Adjust beep interval mapping:

int beepDelay = map(mappedPotValue, 0, 9, 1000, 100);  // Slower range

Code Structure

  • setup(): Initializes all pins (buzzer, sensor, LED, 7-segment segments)
  • loop(): Reads potentiometer, updates display, checks tilt sensor, triggers alerts
  • displayDigit(int): Controls 7-segment display to show digits 0-9
  • Uses common cathode logic (LOW = segment on, HIGH = segment off)

Technical Notes

  • 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)

Applications

  • Anti-theft alarm systems
  • Earthquake/vibration detection
  • Orientation monitoring
  • Tilt-activated switches
  • Package handling alerts
  • Vehicle rollover detection
  • DIY security systems

Troubleshooting

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() and noTone() 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

Future Improvements

  • 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

Common 7-Segment Pinouts

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

License

MIT License - feel free to modify and use for your projects.

Author

Built as a learning project for Arduino sensor integration and multi-component synchronization.

About

Tilt sensor alarm system with synchronized LED/buzzer alerts, 7-segment frequency display (0-9), and real-time potentiometer adjustment for Arduino Uno

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages