🚗 Proximity Beeper with Ultrasonic Sensor (like a parking sensor)

Published: July 24, 2025

Build a simple Arduino-based proximity beeper that uses an ultrasonic sensor to measure distance and beep faster as you get closer to an object — just like a car's reverse parking sensor!


📸 Preview

Proximity Beeper Project

🧰 Parts & Materials Used

ComponentNotesAmazon Link
Arduino UNO (Real & Clone)Main microcontroller boardReal: Link, Clone: Link
HC-SR04 Ultrasonic SensorMeasures distanceLink
LCD1602 with I2C moduleDisplays the distance on-screenLink
Speaker (3W 8Ω)Plays beeping soundLink
Breadboard + jumper wiresFor connectionsLink

Disclaimer: The Amazon links provided above are affiliate links. This means I may earn a small commission at no extra cost to you if you make a purchase through them.


🔌 Wiring Diagram

🔴 Ultrasonic Sensor (HC-SR04)

Sensor PinConnect to
VCC5V
GNDGND
TRIGD9
ECHOD10

🔊 Speaker

Speaker WireConnect to
+D8
GND

🔌 16-Pin LCD1602

📊 Connect these LCD pins to Arduino:

LCD PinLabelConnect to UNO
1GNDGND
2VCC5V
3VOPotentiometer middle pin (for contrast)
4RSD7
5RWGND
6ED6
11D4D5
12D5D4
13D6D3
14D7D2
15A5V (backlight)
16KGND (backlight)

The pins not listed above (7–10) are unused and should be left unconnected.

🔀 Contrast Control (Pin 3 — VO):

Use the 10k potentiometer from your Elegoo kit:

Turn the pot to adjust screen visibility!

🔹 LCD1602 with I2C

LCD PinConnect to
VCC5V
GNDGND
SDAA4
SCLA5

✅ Code


        #include <LiquidCrystal.h>

        // Initialize with the pins used
        LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
        // RS, E, D4, D5, D6, D7

        #define trigPin 9
        #define echoPin 10
        #define speakerPin 8

        void setup() {
        pinMode(trigPin, OUTPUT);
        pinMode(echoPin, INPUT);
        pinMode(speakerPin, OUTPUT);

        lcd.begin(16, 2);
        lcd.setCursor(0, 0);
        lcd.print("Distance: ");
        }

        void loop() {
        long duration;
        int distance;

        // Ultrasonic reading
        digitalWrite(trigPin, LOW); delayMicroseconds(2);
        digitalWrite(trigPin, HIGH); delayMicroseconds(10);
        digitalWrite(trigPin, LOW);

        duration = pulseIn(echoPin, HIGH);
        distance = duration * 0.034 / 2;

        // Show on LCD
        lcd.setCursor(0, 1);
        lcd.print("                "); // Clear row
        lcd.setCursor(0, 1);
        lcd.print(distance);
        lcd.print(" cm");

        // Sound logic
        if (distance < 30) {
            int beepDelay = map(distance, 0, 30, 50, 300);
            tone(speakerPin, 1000);
            delay(beepDelay);
            noTone(speakerPin);
            delay(beepDelay);
        } else {
            noTone(speakerPin);
        }

        delay(100);
        

🚫 Don't forget:

← Back to Projects