This project will teach you how to create traffic lights using Arduino.

Duration: 12 mins

Level: Beginner

Programming Language: Block-based programming

What you will need:

  1. A laptop or desktop or an iPad
  2. An Arduino set
  3. mBlock

Part 1: Buiding the Arduino Circuit

To build the traffic lights, you will need to grab the following from your Arduino set

  • Arduino Uno with a connector cable x1
  • 220 ohm resistors x3
  • Breadboard x1
  • LED x3 (red, green and yellow)
  • Jumper wires

  1. Insert the LED into the breadboard like the picture below making sure that the short end (negative leg) are all on the left side and that the longer leg are on the right side (positive leg)
  1. Next, connect the resistors and the LED together by putting one end of the resistor to the same column of the negative leg of the LED. the other end of the resistor should be put on the negative line of the breadboard.
  1. The positive leg of the LED now needs to be connected to our arduino. The red LED is connected to pin 10, yellow to pin 9 and green to pin 8.
  1. The finish the circuit, the negative terminal of the breadboard needs to be connected to the ground pin in the arduino board and the positive terminal to 5V

Part 2: Code

Connect the arduino to your laptop using the cable and go mblock to input the codes below. When the green flag is clicked the red LED will light up. After 1 second, the red LED will turn off and the yellow LED will turn on. After another second, the same pattern will continue up to the green LED and will repeat forever until the stop button is pressed in mBlock.

You can also watch and code along with our instructor here and you can also pin it below!