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!
Component | Notes | Amazon Link |
---|---|---|
Arduino UNO (Real & Clone) | Main microcontroller board | Real: Link, Clone: Link |
HC-SR04 Ultrasonic Sensor | Measures distance | Link |
LCD1602 with I2C module | Displays the distance on-screen | Link |
Speaker (3W 8Ω) | Plays beeping sound | Link |
Breadboard + jumper wires | For connections | Link |
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.
Sensor Pin | Connect to |
---|---|
VCC | 5V |
GND | GND |
TRIG | D9 |
ECHO | D10 |
Speaker Wire | Connect to |
---|---|
+ | D8 |
– | GND |
LCD Pin | Label | Connect to UNO |
---|---|---|
1 | GND | GND |
2 | VCC | 5V |
3 | VO | Potentiometer middle pin (for contrast) |
4 | RS | D7 |
5 | RW | GND |
6 | E | D6 |
11 | D4 | D5 |
12 | D5 | D4 |
13 | D6 | D3 |
14 | D7 | D2 |
15 | A | 5V (backlight) |
16 | K | GND (backlight) |
The pins not listed above (7–10) are unused and should be left unconnected.
Use the 10k potentiometer from your Elegoo kit:
Turn the pot to adjust screen visibility!
LCD Pin | Connect to |
---|---|
VCC | 5V |
GND | GND |
SDA | A4 |
SCL | A5 |
#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);