HC-SR04 + Buzzer + Arduino: Parking Assist Sensor
by UnicornClockworks in Circuits > Sensors
11795 Views, 6 Favorites, 0 Comments
HC-SR04 + Buzzer + Arduino: Parking Assist Sensor
![Screen Shot 2017-08-17 at 11.50.51 PM.png](/proxy/?url=https://content.instructables.com/FE5/3JF5/J6GQCJEW/FE53JF5J6GQCJEW.png&filename=Screen Shot 2017-08-17 at 11.50.51 PM.png)
![HC-SR04 + Buzzer + Arduino: Parking Assist Sensor](/proxy/?url=https://content.instructables.com/F8U/BKZP/J6GQCJHN/F8UBKZPJ6GQCJHN.jpg&filename=HC-SR04 + Buzzer + Arduino: Parking Assist Sensor)
Hello World!
This is Unicorn Clockworks back with another project. Here, we will make a parking assist sensor using an ultrasonic (HC-SR04) sensor and a buzzer.
As your car gets closer to the Ultrasonic sensor beyond the safety net, it will begin beeping warning you that you are getting too close! No more backing into the wall of your garage with this nifty invention!
Materials
![Slide2.jpg](/proxy/?url=https://content.instructables.com/FZN/XP7O/J6GQCIOQ/FZNXP7OJ6GQCIOQ.jpg&filename=Slide2.jpg)
- Arduino or any Arduino-compatible microcontroller
- HC-SR04 Ultrasonic Sensor
- Buzzer
- Jumper Wires
- [Optional] Breadboard -- you can use female to male jumper wires instead.
HC-SR04 (Ultrasonic Sensor) Connections
![Slide3.jpg](/proxy/?url=https://content.instructables.com/FGX/22O9/J6GQCIOS/FGX22O9J6GQCIOS.jpg&filename=Slide3.jpg)
![Slide4.jpg](/proxy/?url=https://content.instructables.com/FWH/6QQM/J6GQCIQA/FWH6QQMJ6GQCIQA.jpg&filename=Slide4.jpg)
![Slide5.jpg](/proxy/?url=https://content.instructables.com/FMY/WUIU/J6GQCIR9/FMYWUIUJ6GQCIR9.jpg&filename=Slide5.jpg)
![Screen Shot 2017-08-17 at 6.37.24 PM.png](/proxy/?url=https://content.instructables.com/F36/OIHA/J6GQHTH6/F36OIHAJ6GQHTH6.png&filename=Screen Shot 2017-08-17 at 6.37.24 PM.png)
- Connect the Red wire from the VCC pin of the ultrasonic sensor (pin 1) to the 3.3V pin on the Arduino
- Connect the Green wire from the trigger pin of the ultrasonic sensor (pin 2) to pin 9 on the Arduino
- Connect the Blue wire from the echo pin of the ultrasonic sensor (pin 3) to pin 10 on the Arduino
- Connect the Black wire from the ground pin of the ultrasonic sensor (pin 4) to the GND pin on the Arduino
Buzzer Connections
![Slide6.jpg](/proxy/?url=https://content.instructables.com/F77/U2A7/J6GQCIS6/F77U2A7J6GQCIS6.jpg&filename=Slide6.jpg)
![Slide7.jpg](/proxy/?url=https://content.instructables.com/FFS/LA45/J6GQCITH/FFSLA45J6GQCITH.jpg&filename=Slide7.jpg)
![Screen Shot 2017-08-17 at 11.33.57 PM.png](/proxy/?url=https://content.instructables.com/F2L/3AJ1/J6GQCGJ8/F2L3AJ1J6GQCGJ8.png&filename=Screen Shot 2017-08-17 at 11.33.57 PM.png)
- Connect the Purple wire from the buzzer pin ( any of them) to pin 6 on the Arduino
- Connect the Grey wire from the remaining unconnected buzzer pin to the GND pin on the Arduino.
Code
![Screen Shot 2017-08-17 at 11.28.38 PM.png](/proxy/?url=https://content.instructables.com/F5V/G9R3/J6GQCFSC/F5VG9R3J6GQCFSC.png&filename=Screen Shot 2017-08-17 at 11.28.38 PM.png)
// defines pins numbers
const int trigPin = 9; const int echoPin = 10; const int buzzer = 6;
// defines variables long duration; int distance; int safetyDistance;
void setup() { pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output pinMode(echoPin, INPUT); // Sets the echoPin as an Input pinMode(buzzer, OUTPUT);
safetyDistance = ultrasonic();
Serial.begin(9600); // Starts the serial communication }
void loop() {
int dist = ultrasonic();
if (dist <= safetyDistance){ tone(buzzer, 2500); delay(500); tone (buzzer, 2500); } else{ noTone (buzzer); }
// Prints the distance on the Serial Monitor Serial.print("Distance: "); Serial.println(dist); }
int ultrasonic(){ // Clears the trigPin digitalWrite(trigPin, LOW); delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds duration = pulseIn(echoPin, HIGH);
// Calculating the distance distance= duration*0.034/2;
return distance; }
Downloads
It Works!
![Slide8.jpg](/proxy/?url=https://content.instructables.com/FGS/36KS/J6GQCIVA/FGS36KSJ6GQCIVA.jpg&filename=Slide8.jpg)
Upload the code while blocking the ultrasonic sensor at a calibrated 'safety distance.' Move your hands towards it and watch it work!
That's it for now. Stay tuned for more!
Unicorn Clockworks Out!