Thingerbits
Published © GPL3+

Traffic Light Control using Arduino

In this tutorial, we will take a look at building an Arduino traffic light circuit. very simple circuit that’s great for beginners.

BeginnerProtip30 minutes470
Traffic Light Control using Arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
LED Traffic Lights Signal Module
×1
male to male jumper wire
×4

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

schematics

Connect the LEDs to the Arduino using the following connections:

Red LED: Pin 2
Yellow LED: Pin 3
Green LED: Pin 4
Connect a 220-ohm resistor to the longer (anode) leg of each LED and the other end of the resistor to the ground (GND) on the Arduino.

Code

Arduino Code

Arduino
Open the Arduino IDE on your computer.
Copy and paste the code into the IDE.
Select the correct board and port from the Tools menu.
Click the "Upload" button to upload the code to your Arduino.
int red = 2;
int yellow = 3;
int green = 4;

void setup(){
  
  pinMode(red, OUTPUT);
  pinMode(yellow, OUTPUT);
  pinMode(green, OUTPUT);
  
}
void loop(){
digitalWrite(red, HIGH);
 delay(15000);
digitalWrite(red, LOW);
  
  digitalWrite(yellow, HIGH);
delay(1000);
  digitalWrite(yellow, LOW);
delay(500);

  digitalWrite(yellow, HIGH);
delay(1000);
  digitalWrite(yellow, LOW);
delay(500);

  digitalWrite(yellow, HIGH);
delay(1000);
  digitalWrite(yellow, LOW);
delay(500);
  
  digitalWrite(yellow, HIGH);
delay(1000);
  digitalWrite(yellow, LOW);
delay(500);
  
  digitalWrite(yellow, HIGH);
delay(1000);
  digitalWrite(yellow, LOW);
delay(500);
  
digitalWrite(green, HIGH);
delay(20000);
digitalWrite(green, LOW);
//  
digitalWrite(yellow, HIGH);
delay(1000);
  digitalWrite(yellow, LOW);
delay(500);

  digitalWrite(yellow, HIGH);
delay(1000);
  digitalWrite(yellow, LOW);
delay(500);

  digitalWrite(yellow, HIGH);
delay(1000);  
  digitalWrite(yellow, LOW);
delay(500);
  
  digitalWrite(yellow, HIGH);
delay(1000);
  digitalWrite(yellow, LOW);
delay(500);
  
  digitalWrite(yellow, HIGH);
delay(1000);
  digitalWrite(yellow, LOW);
delay(500);
  
  
}

Credits

Thingerbits
2 projects • 7 followers
Thingerbits is one stop shop for Arduino, Raspberry pi, NodeMCU, Micro:Bit sensors, and other electronic development and prototyping tools.
Contact
Thanks to thingerbits.

Comments

Please log in or sign up to comment.