BottiMakerRobotics
Published

Arduino Crossroad and Traffic Lights

Demonstration of Arduino crossroad with traffic lights.

EasyShowcase (no instructions)2 hours499
Arduino Crossroad and Traffic Lights

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
LED (generic)
LED (generic)
×4
ultrasonic sensor
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Code

Arduino code

Arduino
int s1=9;
int s2=7;
int s3=10;
int s4=11;
int trig=8;
int echo=12;                 
int vreme,dinstanca;
void setup() {

pinMode(s1,OUTPUT);
pinMode(s2,OUTPUT); 
pinMode(s3,OUTPUT);
pinMode(s4,OUTPUT);  
pinMode(trig,OUTPUT);
pinMode(echo,INPUT);
}

void loop() {
digitalWrite(trig,LOW);
delayMicroseconds(2);
digitalWrite(trig,HIGH);
delayMicroseconds(10);
digitalWrite(trig,LOW);
vreme=pulseIn(echo,HIGH);
dinstanca=vreme/2/29;
if(dinstanca<5){
botti();
}
  
}
void botti(){
  
digitalWrite(s1,HIGH);
digitalWrite(s2,LOW);
digitalWrite(s3,HIGH);
digitalWrite(s4,LOW);
delay(5000);   
digitalWrite(s1,LOW);
digitalWrite(s2,HIGH);
digitalWrite(s3,LOW);
digitalWrite(s4,HIGH);

  }

Credits

Botti

Botti

0 projects • 2 followers
Contact
MakerRobotics

MakerRobotics

6 projects • 87 followers
Contact

Comments