Project showcase

Traffic Lights Controlled by Arduino © GPL3+

Traffic lights system for a two-street crossing with pedestrian lights, controlled by Arduino.

  • 3,362 views
  • 2 comments
  • 13 respects

Components and supplies

A000066 iso both
Arduino UNO & Genuino UNO
×1
09590 01
LED (generic)
12 traffic 5mm LED (4 Red, 4 Yellow, 4 Green ) + 16 pedestrian lights 3mm LED (8 Red, 8 Green) See main picture if numbers dont sound right
×28

Necessary tools and machines

09507 01
Soldering iron (generic)

Apps and online services

About this project

Traffic lights controlled by Arduino

This project was born as a school project. Among the several possible projects, we chose to build the traffic lights controlled by Arduino, to increase our knowledge about this platform. We never used Arduino before, so it was a real challenge. We were asked to use an industrial controller instead, so we decided to build the circuit in a way that can be controlled by both. In Hardware terms, the main difference between the two controllers is voltage output. So we have a DB25 female with different pins for Arduino and for the controller. We use different cables for the Arduino and for the controller that use the different DB25 pins. The pins are connect to the LEDs with resistors of different value. For Arduino we use 220 ohm resistors, for controller 2200 ohm.

We wanted a good looking device, that can be part of a living room decoration. We decided to use a frame to enclose the circuit and build a live painting of a two-street crossing with semaphores. You can see in fig.1 the frame we used to build the project.

As this project should look like a painting, I asked a little help from my friend Cristina, and we ended up with the lovely painting shown in fig. 2

The space behind the frame was used to do the wiring, as shown in fig 3. To protect the wiring, the back was closed.

The final result, as shown in Fig. 4, was a nice wood frame, containing a live painting, with lights that go on and off. The system starts with blinking yellows, until someone presses one of the 2 pushbuttons. After that, the system starts its normal operating mode of a traffic lights system.

In order to be also controlled by an industrial automaton, we used an old printer cable to do the wiring, as shown in Fig. 5.

To be controlled by Arduino, we used another printer cable to do the wiring needed for Arduino, as shown in Fig. 6.

In Fig. 7 you can see the Arduino connection details.

The Arduino input and output port mapping is the following:

Outputs:

  • Red (STREET 1) Digital Output 0
  • Yellow (STREET 1) Digital Output 1
  • Green (STREET 1) Digital Output 2
  • Red (STREET 2) Digital Output 3
  • Yellow (STREET 2) Digital Output 4
  • Green (STREET 2) Digital Output 5
  • Pedestrians Red (STREET 1) Digital Output 6
  • Pedestrians Green (STREET 1) Digital Output 7
  • Pedestrians Red (STREET 2) Digital Output 8
  • Pedestrians Green (STREET 2) Digital Output 9

Inputs:

  • Pedestrians request (Street 1) Digital input 10
  • Pedestrians request (Street 2) Digital input 11

The DB 25 pin socket had the pinout as Illustrated in Fig 8.

Fig. 9 shows the circuit Diagram of this project

This is an easy to understand circuit, where the LEDs of the same color in the opposite side of each street, are connected in series. This permits to use less Arduino output current, than the parallel option.

The wiring can be a little time consuming, so a little patience is needed.

Hope you enjoyed this project. We had fun building it.

The Team:

Luís Sousa, Emanuel Carpinteiro, Pedro Mealha

Code

Semaforos_VAP.inoArduino
//Semaforos 2 Vias
//Projecto Integrado ENIDH CET EAN 2013/2014
//Luis Sousa
//Pedro Mealha
//Emanuel Carpinteiro

// Variaveis

int RED1 = 0;
int YEL1 = 1;
int GRE1 = 2;
int RED2 = 3;
int YEL2 = 4;
int GRE2 = 5;

int PRED1 = 6;
int PGRE1 = 7;
int PRED2 = 8;
int PGRE2 = 9;

int PREQ1=10;
int PREQ2=11;

int BT1=HIGH; //Botao 1
int BT2=HIGH; //Botao 2
int FLASH=HIGH; //Amarelos Intermitentes 
int TEST=HIGH; //Funo de teste de LEDs

int tgre = 12000; // 12s
int tyel = 2000;  // 2s
int tred = 12000; // 12s

int mem0 = LOW;
int mem1 = LOW;
int mem2 = LOW;
int mem3 = LOW;
int mem4 = LOW;
int mem5 = LOW;
int mem6 = LOW;
int mem7 = LOW;
int mem8 = LOW;
int mem9 = LOW;

// basic functions
void setup()
{
  pinMode(RED1, OUTPUT);
  pinMode(YEL1, OUTPUT);
  pinMode(GRE1, OUTPUT);
  pinMode(RED2, OUTPUT);
  pinMode(YEL2, OUTPUT);
  pinMode(GRE2, OUTPUT);
  pinMode(PRED1, OUTPUT);
  pinMode(PGRE1, OUTPUT);
  pinMode(PRED2, OUTPUT);
  pinMode(PGRE2, OUTPUT);

  pinMode(PREQ1, INPUT);
  pinMode(PREQ2, INPUT);

  test1(); // Sequencia de teste de LEDs
//test2();
  blinkYellow(); //Amarelo intermitente
}

void loop()
{
  //Tempo 1
  //Via 1 com vermelho
  digitalWrite(RED1, HIGH);
  digitalWrite(YEL1, LOW);
  digitalWrite(GRE1, LOW);
  delay(1000);//Delay de segurana;
  //peoes Via 1 verde,
  digitalWrite(PRED1, LOW);
  digitalWrite(PGRE1, HIGH); 
  //peoes Via 2 vermelho 
  digitalWrite(PRED2, HIGH);
  digitalWrite(PGRE2, LOW);
  //delay(500);//Delay de segurana;  
  //Via 2 com verde  
  digitalWrite(RED2, LOW);
  digitalWrite(YEL2, LOW);
  digitalWrite(GRE2, HIGH);

  //espera tempo do vermelho
  //delay(tred);
  for (int i=0; i <= (tred/100); i++)
  {
    BT1=digitalRead(PREQ1);
    BT2=digitalRead(PREQ2);
    BT1=!BT1;
    BT2=!BT2;
    FLASH=BT1&&BT2;
    if (FLASH) 
    {
      blinkYellow();
      BT1=(LOW);
    } 
    if (BT1) 
    {
      i=(tred/100);
    }
    delay(100);
  } 
  //pisca verde peoes
  for (int i=0; i <= 5; i++)
  { 
    digitalWrite (PGRE1,LOW);
    delay (500);
    digitalWrite (PGRE1,HIGH);
    delay (500);
  }

  //Tempo 2
  //Via 2 com amarelo  
  // digitalWrite(RED1, HIGH);
  // digitalWrite(YEL1, LOW);
  // digitalWrite(GRE1, LOW);
  digitalWrite(PGRE1, LOW);
  digitalWrite(PRED1, HIGH);
  //delay (500);  
  //digitalWrite(RED2, LOW);
  digitalWrite(YEL2, HIGH);
  digitalWrite(GRE2, LOW);
  //digitalWrite(PRED2, HIGH);
  //digitalWrite(PGRE2, LOW);
  delay (tyel);

  //Tempo 3
  //Via 2 com vermelho  
  digitalWrite(RED2, HIGH);
  digitalWrite(YEL2, LOW);
  //digitalWrite(GRE2, LOW);
  delay(1000);//Delay de segurana;
  //peoes Via 2 verde,  
  digitalWrite(PRED2, LOW);
  digitalWrite(PGRE2, HIGH);
  //peoes Via 1 vermelho   
  //digitalWrite(PRED1, HIGH);
  //digitalWrite(PGRE1, LOW);
  //delay(500);//Delay de segurana; 
  //Via 1 com verde 
  digitalWrite(RED1, LOW);
  //digitalWrite(YEL1, LOW);
  digitalWrite(GRE1, HIGH);

  //espera tempo do verde  
  //delay (tgre);
  for (int i=0; i <= (tgre/100); i++)
  {
    BT1=digitalRead(PREQ1);
    BT2=digitalRead(PREQ2);
    BT1=!BT1;
    BT2=!BT2;
    FLASH=BT1&&BT2;
    if (FLASH) 
    {
      blinkYellow();
      BT2=LOW;
    }    
    if (BT2) 
    {
      i=(tgre/100);
    }
    delay(100);
  }

  //pisca verde peoes
  for (int i=0; i <= 5; i++)
  { 
    digitalWrite (PGRE2,LOW);
    delay (500);
    digitalWrite (PGRE2,HIGH);
    delay (500);
  }

  //Tempo 4
  //Via 1 com amarelo  
  //  digitalWrite(RED2, HIGH);
  //  digitalWrite(YEL2, LOW);
  //  digitalWrite(GRE2, LOW);
  digitalWrite(PGRE2, LOW);
  digitalWrite(PRED2, HIGH);
  //delay (500);
  //digitalWrite(RED1, LOW);
  digitalWrite(YEL1, HIGH);
  digitalWrite(GRE1, LOW);
  //digitalWrite(PRED1, HIGH);
  //digitalWrite(PGRE1, LOW);
  delay (tyel);
}

void blinkYellow()
{
  //memoriza valores actuais dos LEDS
  mem0 = digitalRead(RED1);
  mem1 = digitalRead(YEL1);
  mem2 = digitalRead(GRE1);
  mem3 = digitalRead(RED2);
  mem4 = digitalRead(YEL2);
  mem5 = digitalRead(GRE2);
  mem6 = digitalRead(PRED1);
  mem7 = digitalRead(PGRE1);
  mem8 = digitalRead(PRED2);
  mem9 = digitalRead(PGRE2);

  //Apaga todos os LEDS 
  digitalWrite(RED1, LOW);
  digitalWrite(YEL1, LOW);
  digitalWrite(GRE1, LOW);
  digitalWrite(RED2, LOW);
  digitalWrite(YEL2, LOW);
  digitalWrite(GRE2, LOW);
  digitalWrite(PRED1, LOW);
  digitalWrite(PGRE1, LOW);
  digitalWrite(PRED2, LOW);
  digitalWrite(PGRE2, LOW);

  //Inicia sequencia de pisca pisca
  for (int i=0; i <= 100; i++)
  {
    digitalWrite (YEL1,HIGH);
    digitalWrite (YEL2,HIGH); 
    delay (500);
    digitalWrite (YEL1,LOW);
    digitalWrite (YEL2,LOW); 
    delay (500);

    BT1=digitalRead(PREQ1);//l estado do botao 1
    BT2=digitalRead(PREQ2);//l estado do botao 2
    BT1=!BT1;//inverte estado do botao 1
    BT2=!BT2;//inverte estado do botao 2
    TEST=BT1&&BT2;
    FLASH=BT1||BT2;//Executa operao OR entre BT1 e BT2 e poe resultado na Variavel FLASH
    if (TEST) 
    {
      test1(); 
      FLASH=LOW;
    }   
    if (FLASH) 
    {
      i=100; 
    }
  }

  //Repoe LEDS como estavam originalmente
  digitalWrite(RED1, mem0);
  digitalWrite(YEL1, mem1);
  digitalWrite(GRE1, mem2);
  digitalWrite(RED2, mem3);
  digitalWrite(YEL2, mem4);
  digitalWrite(GRE2, mem5);
  digitalWrite(PRED1, mem6);
  digitalWrite(PGRE1, mem7);
  digitalWrite(PRED2, mem8);
  digitalWrite(PGRE2, mem9); 
}

void test1()
{
  //Inicia sequencia de luzes
  delay(400);
  for (int a=0; a <= 30; a++)
  {
    for (int i=0; i <= 9; i++)
    {
      digitalWrite (i,HIGH);
    }
    delay(100);
    for (int i=9; i >= 0; i--)
    {
      digitalWrite (i,LOW);
    }
    delay (100);

    BT1=digitalRead(PREQ1);//l estado do botao 1
    BT2=digitalRead(PREQ2);//l estado do botao 2
    BT1=!BT1;//inverte estado do botao 1
    BT2=!BT2;//inverte estado do botao 2
    FLASH=BT1||BT2;//Executa operao OR entre BT1 e BT2 e poe resultado na Variavel FLASH

    if (FLASH) 
    {
      a=30; 
    }
  }
}

void test2()
{
  //Inicia sequencia de luzes
  delay(400);
  for (int a=0; a <= 30; a++)
  {
    for (int i=0; i <= 9; i++)
    {
      digitalWrite (i,HIGH);
      delay(100);      
    }

    for (int i=9; i >= 0; i--)
    {
      digitalWrite (i,LOW);
      delay (100);      
    }

    BT1=digitalRead(PREQ1);//l estado do botao 1
    BT2=digitalRead(PREQ2);//l estado do botao 2
    BT1=!BT1;//inverte estado do botao 1
    BT2=!BT2;//inverte estado do botao 2
    FLASH=BT1||BT2;//Executa operao OR entre BT1 e BT2 e poe resultado na Variavel FLASH

    if (FLASH) 
    {
      a=30; 
    }
  }
}

Schematics

LED Circuit Diagram
DB 25 pin socket mounted on the frame. A cable is needed to connect to Arduino
1 s03ks89k9z

Comments

Author

Lmsousa
lmsousa
  • 3 projects
  • 10 followers

Additional contributors

  • Project design, wiring, building by Emanuel Carpinteiro
  • Project design, wiring, building by Pedro Mealha
  • Drawing and painting consultant by Cristina

Published on

February 27, 2018

Members who respect this project

AdambenzDefault15027854 589829924537462 425725861149706688 nDefault14264847 1572617573047112 8269558775493905167 n

and 8 others

See similar projects
you might like

Similar projects you might like

Central Heating Boiler Control Box

Project tutorial by Peter Groeneveld

  • 1,246 views
  • 4 comments
  • 6 respects

Protect Your Room with Fingerprints for Under $20

Project tutorial by Srivishnu Piratla

  • 1,891 views
  • 1 comment
  • 3 respects

Smart Talking Humanoid Robot Just with Arduino!

Project tutorial by ashraf_minhaj

  • 908 views
  • 4 comments
  • 10 respects

Smart Access [Home/Office Automation]

Project in progress by Ajmal Muhammad P

  • 1,846 views
  • 5 comments
  • 10 respects

Email Home Automation

Project tutorial by Chirila Radu

  • 840 views
  • 0 comments
  • 7 respects

Internal Timers of Arduino

Project tutorial by Marcazzan_M

  • 5,332 views
  • 10 comments
  • 37 respects
Add projectSign up / Login