Sanyam Chugh
Published

Smart Road

A model road with lights that only work when there is a car on the road. It also sounds an alarm when the car drifts out of the lane.

IntermediateWork in progress2 hours3,374
Smart Road

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Breadboard (generic)
Breadboard (generic)
×3
3 mm LED: Red
3 mm LED: Red
×5
3 mm LED: Green
3 mm LED: Green
×1
3 mm LED: Yellow
3 mm LED: Yellow
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1

Story

Read more

Code

Smart CITY Road

Arduino
int const trigPin = 10;
int const echoPin = 9;
int const ledPin = 2;
int const Red = 12;
int const Yellow =11;
int const Green =13;
int const buzzerPin=4;
void setup()
{
digitalWrite(Green,LOW);
pinMode(trigPin, OUTPUT); 
pinMode(echoPin, INPUT); 
pinMode(ledpin, OUTPUT); 
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
pinMode(4,OUTPUT);
}
void loop()
{
  digitalWrite(Red,HIGH);
delay(2000);

digitalWrite(Red,LOW);
digitalWrite(Yellow,HIGH);
delay(2000);
digitalWrite(Yellow,LOW);
digitalWrite(Green,HIGH);
delay(2000);
digitalWrite(Green,LOW);
int duration, distance;

digitalWrite(trigPin, HIGH);
delay(1);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance <= 5 && distance >= 0) {

digitalWrite(ledpin, HIGH);
} 
else if(distance<=1)
{
  digitalWrite(ledpin, HIGH);
  digitalWrite(buzzpin, HIGH);
  
  }
else {
digitalWrite(ledpin, LOW);
}
Serial.print(distance);
delay(60);
}

Credits

Sanyam Chugh

Sanyam Chugh

13 projects • 2 followers

Comments