Vehicle horn control using Arduino and ultrasonic sensor code
Hello everyone.. This is one of the real time project that can be very useful for all the vehicles owners and drivers nowadays.....
Controlling the vehicle horn using Arduino and ultrasonic sensor
Project Objective :
The main objective of the project is that while we are driving a vehicle in a highway, the other vehicles may come very close to us because of various reasons, in order to avoid crashing or accidents, we should sound the horn to alert the opponent vehicle driver. So, what we are made here is that we just automated to sound the horn and alert the driver to move when a vehicle is very close to our vehicle automatically without any human input by just using Arduino and ultrasonic sensor to sense the distance between the two vehicles.
Components required :
As a model version of this project we need the following things :
1) Arduino
2) Ultrasonic sensor
3) Buzzer (acting as horn)
4) LCD display
5) Connecting wires and Breadboard
Connection Diagram :
Code for this Project :
#define trigPin 8
#define echoPin 12
#define led 13
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(13,OUTPUT);
lcd.begin(16,2);
lcd.setCursor(0,0);
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
pinMode(led,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
long duration,distance;
digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);
duration=pulseIn(echoPin,HIGH);
distance=(duration/2)/29.1;
Serial.print(distance);
int temp=1;
while(Serial.available()!=NULL || (distacne&&temp)!=0)
{
data =Serial.read();
if (data=='1' || distance<=30)
{
lcd.print("Alert");
digitalWrite(led,HIGH);
delay(10000);
lcd.clear();
}
else if(data=='2')
{
lcd.print("please,move");
digitalWrite(led,HIGH);
delay(10000);
lcd.clear();
}
temp--;
}
}
Have fun :)
Hope you guys learnt something New !!!!!
See you again in the Next Articles Bye.....!!!!!!!!
0 Comments