Introduction: Controlling a Traffic Light

In this tutorial we learn how to create a traffic light and how to control it managed by the Drivemall card.

We will see how to create traffic lights for cars and pedestrians with a booking button.

If we do not have the drivermall we can use the arduino, but below the link for the development of the Drivemall.

The advantage of prefering the Drivemall over the classic Arduino board is that of reducing the complexity of the connections leading to a more tidy setup. However, this is optional: all the results are still valid with the arduino board, a breadboard and enough dupont jumpers for connections.

Step 1: Bill of Materials

  1. Baord Drivemall / ArduinoMega
  2. 4 led red
  3. 4 led green
  4. 4 led yellow
  5. 8 transistor npn
  6. 16 resistors 220 ohm
  7. 8 resistors 22k ohm
  8. 1 resistor 1k ohm
  9. cable
  10. 1 button

Step 2: Connections

The traffic light is controlled using two PNP transistors connected according to the diagram in figure 2. The operation of the PNP transistor is very simple when the base is connected to GND the passage of current between the emitter and the collector is enabled.

We use transistors to decrease the number of board pins required to turn on each single traffic light.

So if both the BASES are VDD the red LED will light up or to be clearer the LED 21 17 14 6.

If we power the BASE of the second transistor, LEDs 3 15 18 19 will turn on.

As last, if we connect both the BASES to GND, the LEDs 20 16 13 10 will light up

The connection of the button is instead the classic resistance connected to GND on one pin of the button and the other to VDD.

The Arduino Pins registered are those from 1 to 10.

Step 3: Firmware

Periodically only one of the traffic light is green. When the pedestrian button is pressed, at the next period the traffic light for pedestrians change green

In order to manage the button call for pedestrian without delay in real time, the millis () function was used, which returns the time in milliseconds since the device was turned on, so that it can be used

example

unsigned long currentMillis = millis () ;.

if (currentMillis - previousMillis> 2000 and bt03 == true and bbot == false)

{

Serial.println (1);

T1 ();

previousMillis = currentMillis;

bt1 = true;

BT03 = false;

}

We load the current time at each loop and if the current minus the previous one is greater than the chosen time enter the if to change the state of the traffic light going to activate the Boolean variable for the next transition, of course the first Boolean variable is already true before entrance of the loop.

Step 4: Disclaim

This tutorial has been produced as part of the Makerspace for Inclusion project, co-financed by the Erasmus + Programme of the European commission.

The project aims to promote an informal form of education as a means to foster the social inclusion of young people, informal education as can be found within makerspaces.

This tutorial reflects the views only of the authors, and the European Commission cannot be held responsible for any use which may be made of the information contained therein.