Ultrasonic Distance Alarm System

by 1040234 in Circuits > Arduino

28 Views, 0 Favorites, 0 Comments

Ultrasonic Distance Alarm System

Screenshot 2025-06-17 130203.png
(Upload-from-mobile-1750177924)IMG_3055.jpeg

This project uses an Arduino Uno to create a smart sensing system that:

  1. Measures distance using an ultrasonic sensor
  2. Lights up 7 LEDs based on how close something is
  3. Activates a servo motor to rotate based on distance
  4. Beeps a buzzer and flashes LEDs when someone is too close
  5. Displays the current mode and distance on a 4-digit TM1637 display
  6. Changes mode using a push button, turns on/off with a slide switch
  7. Uses an RGB LED to show mode colour (green/red/blue)

Supplies

(Upload-from-mobile-1750175761)IMG_3040.jpeg
(Upload-from-mobile-1750175761)IMG_3038.jpeg

Project Development Reference Videos

Stage 1: LEDs + Sensor

  1. Ultrasonic sensor controlled 7 LEDs (one LED turned on for each distance level)
  2. Purpose: Learn how to use pulseIn() and control multiple LEDs

Stage 2: Servo + Sensor

  1. Added servo rotation based on distance
  2. Learned map() and how to use servo.write()

I made stage one and 2 from this video

than I kept on adding components to the project to make it a level 4 project

How to Build the Circuit

(Upload-from-mobile-1750175837)IMG_3041.jpeg
(Upload-from-mobile-1750175837)IMG_3042.jpeg
IMG_3043.jpeg
IMG_3045.jpeg
(Upload-from-mobile-1750176392)IMG_3033.jpeg
(Upload-from-mobile-1750176392)IMG_3036.jpeg
(Upload-from-mobile-1750176392)IMG_3053.jpeg

Place the Arduino and breadboard side by side.

Connections

πŸ”ΉRGB LED (Common anode)

  1. R β†’ Pin 13 (through 220Ξ©)
  2. G β†’ A0
  3. B β†’ A1
  4. Anode β†’ 5v

πŸ”Ή Ultrasonic Sensor

  1. Trig β†’ Pin 11
  2. Echo β†’ Pin 12
  3. VCC β†’ 5V
  4. GND β†’ GND

πŸ”Ή Button

  1. One side β†’ Pin 9
  2. Other side β†’ GND
  3. Use INPUT_PULLUP or external pull-down resistor

πŸ”Ή Slide Switch

  1. Center pin β†’ A4
  2. One side β†’ 5V
  3. Other side β†’ GND


πŸ”Ή Buzzer

  1. Positive β†’ A2
  2. Negative β†’ GND

πŸ”Ή LEDs

  1. Pins 2–8 each control one LED with 220Ξ© resistor
  2. Common GND

πŸ”Ή TM1637 4 Digit Display

  1. CLK β†’ A5
  2. DIO β†’ A3
  3. VCC β†’ 5V
  4. GND β†’ GND

πŸ”Ή Servo

  1. Signal β†’ Pin 10
  2. VCC β†’ 5V
  3. GND β†’ GND

Connect the red rail with other side of bread board red rail with wire and connect black rail with the other side of bread board black rail with a black wire.

How the Circuit Works

June 17, 2025

Ultrasonic sensor: It sends out a sound pulse (ultrasonic) on β€œTrig” and listens for the echo on β€œEcho.” The time between sending and hearing the pulse tells us the distance.

LEDs (7 total):

Each LED represents a distance threshold (e.g., 25cm, 20cm, 15cm, etc.). The closer the object, the more LEDs light up.

RGB LED:

Shows the current mode with color:

  1. Green = Mode 1 (LEDs + 4-Digit Display)
  2. Red = Mode 2 (Servo + 4-Digit Display)
  3. Blue = Mode 3 (LEDs + Servo + 4-Digit Display)

4-Digit Display (TM1637):

Displays distance and current mode:

  1. First digit = Mode (1, 2, or 3)
  2. Second digit = Static dash (-)
  3. Last two digits = Distance in cm

Servo motor : Rotates from 0Β° to 180Β° based on how close the object is (closer = larger angle).

Push button: Each press changes the mode (1 β†’ 2 β†’ 3 β†’ back to 1). Single beep when changed to mode 1, double for mode 2, long beep for mode 3 confirms the change.

Slide Switch:

When OFF, the whole system shuts down: RGB turns off, LEDs off, servo is detached, display is cleared, and buzzer silences.

When ON, the system turns back on and resumes its last mode.

Buzzer :

Gives feedback:

  1. Beeps when changing mode
  2. Melody when switching system ON/OFF
  3. Alarm when object is very close (<5 cm)


Code

Copy–paste this into your Arduino IDE and upload:

Testing & Tips

  1. Open Serial Monitor to see β€œMode:” and β€œDist:” outputs.
  2. Tweak the th[] array or map(…) values to change at which distances LEDs or servo react.