Introduction: Smart Interactive Traffic Light

Ready to build world's best and most interactive traffic light? Good! In this tutorial, we'll explain how you can build one by yourself using Arduino.

Required components:
- Arduino (..duh)
- LM317 Mosfet
- 2x 60cm Analog RGB LED Strips (12V)
- PVC tube (1m x 125mm)
- Cables (red and black)
- Metal plates for light-caps
- Acryl for the light-icons (check flaticon.com for .svg icons)
- Spraycan black and white paint.
- Electrical tape
- All required soldering components
- Display with required shield (not used in tutorial)

Step 1: Step 1: Make the Light-caps

The design is really up to you. We've made a 15x15cm cap to hold the lights. We've cut the metal plates to the correct size and used a metal bender (no, not from Avatar) to bend the caps in the right shapes. The backplates were made from a different component.

Step 2: Step 2: Prepping the PVC Pole

Cut 2 holes in the PVC pole to fit the light-caps. Then use a black paint spraycan to paint the entire thing black. If you want, you can add white stripes on the bottom of the pole (common in The Netherlands).

Step 3: Step 3: Assembling the RGB LED Strips and Sandblasting the Acrylic Plates

Next you'll need to assemble the RGB LED strips inside the light-cap. Fit them tight around the cap, and place them as close to the front as possible.

Next up you'll need to sandblast the selected symbol for on the acrylic plate. Get some tape and cover the entire acrylic plate. Then cut out the shape/figure you want. After this, you can sandblast the plate to get a frosted-glass-like effect.

Step 4: Step 4: Connect the RGB LED Strips to the Arduino.

Now comes the tricky part: connecting the RGB LED Strips to the Arduino. When you're connecting the pins make sure that you put the 12v on the 12v of your strip. Between each color, so red or green, you need to put a mosfet. Connect the data of the led strip to the middle pin of the mosfet, and the left pin to your Arduino. The right pin has to go back to the ground of the Arduino.

Step 5: Step 5: Write the Arduino Code

This Arduino code is controlled by bluetooth, because we didn't use a internal display. So the code is controlled via bluetooth messages in the loop() function.

#define r 6
#define g 11 #include

SoftwareSerial mySerial(10, 11); // RX, TX

#define angryLength 4 #define fallingLength 3 #define happyLength 4 #define onPhoneLength 13 #define talkingLength 5 #define walkingLength 4 #define walkingOutLength 4 #define wavingLength 6

bool buttonPressed; int currentMillis; int previousMillis;

int animation1Delay; int animation2Delay; int animation3Delay; int animation4Delay;

bool animation1Done = false; bool animation2Done = false; bool animation3Done = false; bool animation4Done = false; bool animation5Done = false;

bool blockLight = false;

bool lightRed = true;

int currentAnimationDelay;

void setup() { // put your setup code here, to run once: pinMode(r,OUTPUT); pinMode(g,OUTPUT);

Serial.begin(9600); mySerial.begin(38400); Serial.setTimeout(25); buttonPressed = false; currentMillis = 0; previousMillis = 0;

animation1Delay = walkingLength * 1000; animation2Delay = wavingLength * 1000; animation3Delay = happyLength * 1000; animation4Delay = walkingOutLength * 1000;

//currentAnimationDelay = animation1Delay * 1000; lightRed = true; }

void loop() {

//delay(20); // put your main code here, to run repeatedly: unsigned long currentMillis = millis(); if(buttonPressed == true) { if(animation1Done == false) { if(currentMillis - previousMillis > animation1Delay) { Serial.println("0"); previousMillis = currentMillis; animation1Done = true; } } else if(animation2Done == false and animation1Done == true) { if(currentMillis - previousMillis > animation2Delay) { Serial.println("1"); previousMillis = currentMillis; animation2Done = true; } } else if(animation3Done == false and animation2Done == true) { if(currentMillis - previousMillis > animation3Delay) { Serial.println("2"); //Serial.println("sound:green"); previousMillis = currentMillis; animation3Done = true; lightRed = false; } } else if(animation4Done == false and animation3Done == true) { if(currentMillis - previousMillis > animation4Delay) { previousMillis = currentMillis; animation4Done = true; Serial.println("FLSH"); } } }

if (Serial.available()) { String str = Serial.readString(); if(str == "CMD:BUTTON_PRESSED") {

animation1Done = false; animation2Done = false; animation3Done = false; animation4Done = false; animation5Done = false;

animation1Delay = walkingLength * 1000; animation2Delay = wavingLength * 1000; animation3Delay = happyLength * 1000; animation4Delay = walkingOutLength * 1000;

//currentAnimationDelay = animation1Delay * 1000; lightRed = true; Serial.println("3"); buttonPressed = true; previousMillis = currentMillis; }

if(str == "RED") { blockLight = false; lightRed = true; }

if(str == "GREEN") { blockLight = false; lightRed = false; }

if(str == "LIGHT:GREEN:OFF") { blockLight = true; analogWrite(g, 255); } if(str == "LIGHT:GREEN:ON") { blockLight = true; analogWrite(g, 0); } //Serial.println(str); }

if(blockLight == false) {

if(lightRed == true) { analogWrite(r, 0); analogWrite(g, 255); } if(lightRed == false) { analogWrite(r, 255); analogWrite(g, 0); } } }