Parking Assist Sensor - Park Perfectly Everytime!
by TechMartian in Circuits > Sensors
1011 Views, 7 Favorites, 0 Comments
Parking Assist Sensor - Park Perfectly Everytime!
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
* Buzzer
* Arduino
* Ultrasonic Sensor
* Jumper Wires
* Breadboard
Wiring
Follow the table below for the hardware connections:
I/O | I/O Pin | Arduino Pin |
---|---|---|
Ultrasonic | Trig | 10 |
Echo | 9 | |
VCC | 3.3V | |
GND | GND | |
Buzzer | 1 | 6 |
2 | GND |
Code
// 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); }