Parking Assist Sensor - Park Perfectly Everytime!

by TechMartian in Circuits > Sensors

996 Views, 7 Favorites, 0 Comments

Parking Assist Sensor - Park Perfectly Everytime!

Screen Shot 2017-08-30 at 7.29.22 AM.png

This is a parking assist sensor that changes frequency and tone as you get closer to the desired target mark for parking. It uses an ultrasonic sensor to sense how far your car is from this safety distance.

BoM

Screen Shot 2017-08-30 at 7.29.02 AM.png

* Buzzer

* Arduino

* Ultrasonic Sensor

* Jumper Wires

* Breadboard

Wiring

Screen Shot 2017-08-30 at 7.29.22 AM.png
Screen Shot 2017-08-30 at 7.29.17 AM.png
Screen Shot 2017-08-30 at 7.30.09 AM.png

Follow the table below for the hardware connections:

I/O I/O PinArduino Pin
Ultrasonic Trig 10
Echo9
VCC3.3V
GNDGND
Buzzer16
2GND

Code

Screen Shot 2017-08-30 at 7.32.43 AM.png
Screen Shot 2017-08-30 at 7.32.44 AM.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 = 150;
 tone(buzzer, 2500);
  delay(500);
  tone (buzzer, 2500);  
Serial.begin(9600); // Starts the serial communication
}
void loop() {
// 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;
int beep = map (distance, 0, 3000, 0, 10000);
int time1 = map (distance, 0, 3000, 0, 300);
tone(buzzer, beep, time1);
delay(time1);
noTone (buzzer);  
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(dist);
}