Traffic Lights Add-on Board

Create your own micro:bit traffic light add-on board.

Overview

By the end of this tutorial you will know what an LED is and how to connect and program them using a BBC micro:bit.

What You Will Need

  • 1 x Red LED
  • 1 x Yellow LED
  • 1 x Green LED
  • 1 x Piece of cardboard
  • Copper tape / aluminium foil and glue
  • 4 x Crocodile / alligator leads
  • 1 x micro:bit (version 1 and 2 will work)
  • 1 x Micro USB cable
  • 1 x Battery pack for the micro:bit (optional)

What is an LED?

LED diagram

An LED or Light Emitting Diode is a semiconductor light source that emits (gives off) light when current flows through it.

An LED has a longer leg called the anode (+) and a shorter leg called the cathode (-) as shown above.

Creating the Circuit

  1. Place the bit of cardboard on the desk
  2. Take the red LED and bend the legs out to the sides. Place the LED on the cardboard with the longer leg to the right.
    Red LED placed on the cardboard
  3. Take a bit of copper tape or glue and some aluminium foil over the long leg of the red LED
    Taping the longer leg of the red LED
  4. Complete steps 2 and 3 for the yellow and green LEDs.
  5. Take a longer bit of copper tape or foil and tape/glue all three of the short legs of the LEDs together.
    Completed Traffic lights

Connecting to the micro:bit

  1. Take one of the crocodile/alligator leads and clip one end to the long piece of copper tape/aluminium foil covering the short legs of the LEDs and clip the other end to the GND pin of the micro:bit.
  2. Take another crocodile/alligator lead and clip one end to the copper tape/aluminium foil of the longer leg of the red LED and attach the other end to pin 0 on the micro:bit.
  3. Take another crocodile/alligator lead and clip one end to the copper tape/aluminium foil of the longer leg of the yellow LED and attach the other end to pin 1 on the micro:bit.
  4. Take the last crocodile/alligator lead and clip one end to the copper tape/aluminium foil of the longer leg of the green LED and attach the other end to pin 2 on the micro:bit.
Completed Circuit

We are now ready to code our traffic lights

Coding The Traffic Lights

  1. Within your favourite browser (we recommend Google Chrome) go to python.microbit.org and press Enter . This will load the Python coding editor.
  2. Delete the text on lines 6, 7, & 8 .
  3. Type the following code:
    Python code
Completed Code

Now that we have completed the code we need to download it to our micro:bit

Downloading the Code

  1. Connect the micro:bit to the computer using the micro USB cable.
  2. Click on Connect . Click on your micro:bit and click Connect .
  3. Click on Download .

Now that our code is downloaded to the micro:bit we will see the LEDs blink in a traffic light sequence.

Go back to your code and see what other patterns you can make the LEDs blink in.