Menu Close

Arduino Traffic Light Controller

Robo India presents tutorial on the Arduino Traffic Light Controller .

1. Introduction:

In this project, an Arduino based traffic light controller system is designed. It is a simple project of light system, which is used to control traffic.

In this circuit, 6 LED’s of three different colors are used to implement traffic lights at 2-way intersection. Each intersection contains these three different colors (Red, Yellow and Green) and represent as Lane.

2. Required Hardware

Following Hardware will be required to perform this circuit.

S.No.ItemQuantity
1 Arduino UNO 1
2 Breadboard 1
3 LED 6
4 Male to Male Jumper 13

3. Building Circuit

Make the following connections with Arduino-

4. Programming

You may download this Arduino Sketch from here.

//Robo India tutorial to control LEDs using IR Remote
//https://www.roboindia.com/tutorials

#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
 
int IR_Remote = 8;  //IR Sensor connected with arduino 
int RedLED = 4;
int GreenLED = 3;
int YellowLED = 2;
int led[] = {0,0,0,0};

#define code1  0xC101E57B  // Hex Code for Button 1 of IRR Remote
#define code2  0x97483BFB  // Hex Code for Button 2 of IRR Remote
#define code3  0xF0C41643  // Hex Code for Button 3 of IRR Remote
 
IRrecv irrecv(IR_Remote);
 
decode_results results;
 
void setup()
{
  irrecv.enableIRIn();  // Start the receiver
  pinMode(RedLED, OUTPUT);
  pinMode(GreenLED, OUTPUT);
  pinMode(YellowLED, OUTPUT);
}
 
void loop() {
  if (irrecv.decode(&results)) 
  {
    unsigned int value = results.value;
    switch(value) 
      {
       case code1:
         if(led[1] == 1) 
         {        
            digitalWrite(RedLED, LOW);   //led off when button is pressed
            led[1] = 0;                 
         } 
         else 
         {                                // if first led is off
             digitalWrite(RedLED, HIGH); // turn it on when the button is pressed
             led[1] = 1;                 // and set its state as on
         }
       break; 
      
       case code2:
         if(led[2] == 1) 
         {        
            digitalWrite(GreenLED, LOW);   
            led[2] = 0;                 
         } 
         else 
         {                      
             digitalWrite(GreenLED, HIGH); 
             led[2] = 1;          
         }
       break; 
       
       case code3:
         if(led[3] == 1) 
         {
            digitalWrite(YellowLED, LOW);
            led[3] = 0;
         } else 
         {
             digitalWrite(YellowLED, HIGH);
             led[3] = 1;
         }
          break;          
    }
  irrecv.resume(); // Receive the next value
  }
}

6. Output

After uploading the code successfully, the pattern on which LED’s will glow, like:

The first lane has Red Signal and second lane has Green on.

First lane has Red and Yellow on, and lane 2 has Yellow on.

First lane has Green on and lane 2 has Red on.

Then, first lane has Yellow on and lane 2 has Red and Yellow on.

Yellow light is used as warning indicator. In lane 1, It indicates that Red light is about to on and in lane 2 Green light is going to be on. This process, will repeat all over the time.

You can add more led for more buttons.

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com

Leave a Reply