How to design an Automatic Traffic Light with Arduino ?




Steps to make a basic traffic light :
BREADBOARD CONNECTIONS
  • Take three colour LEDs and connect each  their negative terminal with 1 k-ohm resistance.
  • Connect a common ground to each resistance as shown in the figure.
  • Now connect the positive terminal with the pin number 10,9 and 8 pin of the arduino.
PROGRAMING PART

Arduino Code for Traffic Light: 
int ledDelay = 10000; // delay in between changes
int redPin = 10;
int yellowPin = 9;
int greenPin = 8;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop() {
digitalWrite(redPin, HIGH); // turn the red light on
delay(ledDelay); // wait 5 seconds
delay(2000); // wait 2 seconds
digitalWrite(greenPin, HIGH); // turn green on
digitalWrite(redPin, LOW); // turn red off
digitalWrite(yellowPin, LOW); // turn yellow off
delay(ledDelay); // wait ledDelay milliseconds
digitalWrite(yellowPin, HIGH); // turn yellow on
digitalWrite(greenPin, LOW); // turn green off
delay(2000); // wait 2 seconds
digitalWrite(yellowPin, LOW); // turn yellow off
}// now our loop repeats

PIN DIAGRAM
Traffic Lights With Arduino - Image

0 Comments

Oldest