BeginnerSensors

Ultrasonic Parking Distance Beeper

Measure nearby objects with an HC-SR04 and make a buzzer beep faster as an object gets closer.

Estimated time: 60โ€“90 minutes ยท Skills: Digital inputs and outputs, pulse timing, simple thresholds

Parts from the database

Other supplies

Amazon links may be affiliate links. As an Amazon Associate, Electronics Hobby Hub earns from qualifying purchases.

Connections

  1. HC-SR04 VCC to 5 V and GND to GND; TRIG to D9 and ECHO to D10 on a 5 V Uno-compatible board.
  2. Piezo buzzer positive to D3 and negative to ground. Use a small piezo buzzer, not a loudspeaker.
  3. If using a 3.3 V board instead, level-shift the HC-SR04 ECHO output before connecting it to the MCU.

Build steps

  1. Upload the sketch and open Serial Monitor at 9600 baud.
  2. Place a flat target 20โ€“150 cm from the sensor; keep the sensor face clear.
  3. Confirm the displayed distance changes consistently as you move the target.
  4. Listen for beeps that speed up below the selected threshold; tune the thresholds for your enclosure.

Software and firmware setup

const int trigPin=9, echoPin=10, buzzerPin=3;
void setup(){ Serial.begin(9600); pinMode(trigPin,OUTPUT); pinMode(echoPin,INPUT); pinMode(buzzerPin,OUTPUT); }
void loop(){
  digitalWrite(trigPin,LOW); delayMicroseconds(3);
  digitalWrite(trigPin,HIGH); delayMicroseconds(10); digitalWrite(trigPin,LOW);
  unsigned long us=pulseIn(echoPin,HIGH,30000);
  if(us==0){ noTone(buzzerPin); Serial.println("No echo"); delay(100); return; }
  float cm=us*0.0343f/2.0f; Serial.println(cm);
  if(cm<100){ int interval=map((int)cm,5,100,80,700); tone(buzzerPin,2200,40); delay(max(interval,80)); }
  else { noTone(buzzerPin); delay(100); }
}

Review the pin assignments in the sketch against the wiring table before uploading.

Test your build

A target moving from about 100 cm toward the sensor should produce progressively faster chirps. The result is a bench demonstrator, not an automotive parking safety system.

Troubleshooting

  • If readings are zero, check TRIG/ECHO order and the 5 V supply.
  • Soft fabric and angled surfaces reflect ultrasound poorly; test with a flat cardboard book.
  • If the buzzer is silent, check whether it is an active buzzer or a passive piezo; this sketch uses tone().

Safety and limitations

This is only a tabletop demo. Do not use it to guide a real vehicle or rely on it to prevent a collision.

Manufacturer and platform documentation

Community Notes for This Project

These are unverified visitor contributions, separate from the build guide and manufacturer specifications. Verify technical advice against the linked datasheets before relying on it.

Set up the comments service to load community notes.

Share a tip or question about this build

โ† Browse all projects