Arduino Application Projects: Car Reverse Sensor
by Abdul Halim_93 in Circuits > Arduino
395 Views, 0 Favorites, 0 Comments
Arduino Application Projects: Car Reverse Sensor
Well Heya Everyone! How are you guys doing? I hope everyone is doing well and great always. Well, what am i up to this time? hmmmm, after some time thinking and tinkering, i decided to simulate a simple car reverse sensor using our Arduino. How? Lets see, a simple car reverse sensor will have:
1. A input sensor detecting the distance between car and obstacle/object
2. An output response based on the sensor reading
These two would be our objectives for our mini project! Well without further ado lets explore on more how!
Sensor for Detecting Distance????
There are many many variants of sensors to detect distance. These variants differ in terms of sensor size, sensor distance range, sensor pinouts and sensor accuracy. For this project, we are going to use a quite common sensor for Arduino users.
We are going to use the HC-SR04 Ultrasonic Distance Sensor(as the image shown)
From the sensor we have 4 pin outs: Namely:
VCC- Power pin, connect the pin to a 5V
GND- Ground pin, Connect to a ground
Trig-This pin functions as to send a trigger pulse for distance detection
Echo- This pin sends another pulse to detect the if there is an object in the distance. If a pulse is returned, then there is an object and vice versa
How to connect to Arduino? Here you go!
VCC->5V
GND-> Ground pin
Trig->pin 7 digital pin
Echo-> pin 8 digital pin
Piezo Electric Buzzer!
A piezo electric buzzer is a very simple buzzer. It has only two pins, the positive and ground pin. On some variants, there are wire outs which has red wire(positive pin) and black wire(ground pin). In some variant, you have positive marking on a pin out and the other has no marking. Both variant is shown in the picture above.
How to connect to Arduino:
Red wire (positive) -> pin 6 of digital pin
Black wire (Gnd) -> any ground
Overall Schematic of the Project
I am using a Mega, but you can apply the same schematic on your UNO as well
The CODEEEEEEEEEEEEEEEEEE
Before writing the code, please download and install these two libraries for piezo tone and HC-SR04 pings
*****************************************************************************************************************
#include <NewTone.h> //downloaded new library
#include "NewPing.h" //downloaded new library
#define TRIGGER_PIN 7 //defining the trigger pin of HC-SR04 #define ECHO_PIN 8 //defining the Echo pin of HC-SR04
#define MAX_DISTANCE 300 // the maximum distance of the HC-SR04 to detect, you can go higher or lower from this value
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); //new ping function for distance detection float duration, distance;
int sound = 6; //declare piezo pin
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// Send ping, get distance in cm
distance = sonar.ping_cm();// to detect distance from the newping library
// Send results to Serial Monitor
Serial.print("Distance = ");
Serial.print(distance);
Serial.println(" cm");
// some conditioning for distance and piezoe tones
if( distance >= 0 && distance < 3)
{
NewTone(sound, 40, 500); //tone(pin,freq in herztz,tone time)
delay(100); }
if( distance >= 3 && distance < 6)
{
NewTone(sound, 40, 500); //tone(pin,freq in herztz,tone time)
delay(500);// different delay showing urgency
}
if( distance >= 6 && distance < 9)
{
NewTone(sound, 40, 500); //tone(pin,freq in herztz,tone time)
delay(1000);
}
if( distance >= 9 && distance < 12) {
NewTone(sound, 40, 500); //tone(pin,freq in herztz,tone time)
delay(2000);
}
if( distance >= 12) {
NewTone(sound, 40, 500); //tone(pin,freq in herztz,tone time)
delay(3000);
}
******************************************************************************************************************************
Upload the code and you are done!
The Project Vid
So how was it? I hope you are able to do it! I'll be back with more experiment in future! if you have any question or suggestion, you can comment, i might be able to tinker around!
See you guys on the next tinker experiment!