Guys,what do you think about a vehicle which gives an alarm and a light signal when a vehicle vehicle a cross a safe distance behind your vehicle. I think this is a helpful project to make you and your vehicle safe. Okey,let's make it.
Components Required
1. | Arduino UNO | * 1 |
2. | Ultrasonic Sensor(HC-SR04) | * 1 |
3. | LED(Red) | * 1 |
4. | Buzzer | * 1 |
5. | Resister(220 Ohm) | * 1 |
6. | Jumper Wires | * 1 |
Circuit Diagram
Program
int echoPin = 12;
const int ledPin = 13;
const int buzzer = 10;
void setup()
{
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
pinMode(buzzer,OUTPUT);
pinMode(trigPin,OUTPUT);pinMode(echoPin,INPUT);
}
void loop()
{
digitalWrite(trigPin,LOW);
delayMicroseconds(5);
digitalWrite(trigPin,HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
cm = (duration/2) / 29.1;
Serial.print(cm);
Serial.print("cm");
Serial.println();
if(cm <= 20)
{
digitalWrite(ledPin,HIGH);
digitalWrite(buzzer,HIGH);
}
else{
digitalWrite(ledPin,LOW);
digitalWrite(buzzer,LOW);
} delay(250);
}