Use a Two Colour LED Module with micro:bit

Difficulty
Easy
Steps
11

Want to make an LED light up and easily change their colours?

In this guide, we will learn to use a handy little LED module and make it blink using the micro:bit!

After completing this guide, you will understand how to use an LED and create a simple program using MakeCode. 

If you're using the Micro:bit Advent Calendar, you'll need the contents of the bags labelled 1 and 25.

Parts Used in This Guide

Buy

Step 1  The Module

Before we begin, let's take a closer look at the Two Colour LED module! 

There are three pins:

  • Ground (-) 
  • Middle Pin : This pin emits a red light!
  • Signal Pin (S): This pin emits a green light!

You might have noticed an 'R1' on the module, this stands for 'resistor'. However, the resistor here is actually a 0Ω resistor,  so we will need to use external resistors in the circuit!

Step 2  Connect module to breadboard

Step 3  Insert the Micro:bit into the Breakout board

Insert the micro:bit into the breakout board . Make sure that the micro:bit is inserted in the right orientation, with the buttons facing inward as shown.

Step 4  Connect GND to -

Step 5  Add Resistor

Step 6  Add another Resistor

Step 7  Connect P0 to Resistor

Step 8  Connect P1 to Resistor

Step 9  Make the LED flash red


The first program we will create will make the LED module flash red!

  1. Firstly, open up the Makecode Editor
  2. Click on the Projects button
  3. Create a new document
  4. Now drag a "forever" block from the Basic section of the editor's panel (note: if there are already blocks on the screen you can click on them and hit delete to remove them).
  5. Click on Pins button on the editor panel (found when you click Advanced) , drag a "digital write pin ... to ... " block
  6. Click on Basic button on editor panel and drag a "pause (ms) ... " block
  7. Change  "digital write pin ... to ..." block to "digital write pin P0 to 1"
  8. Change 'pause (ms) ... " block into "pause (ms) 250"
  9. Repeat steps 5 to 8 
  10. Change  "digital write pin ... to ..." block to "digital write pin P0 to 0"
  11. Jump to step 6 if you would like to upload the code and test this program now!

Step 10  Make the LED flash red and then yellow


The next program we will create will make the LED module flash red and then yellow with a pause in between! Continuing on from the block code in step 3:

  1. Click on Pins button on the editor panel, drag a "digital write pin ... to ... " block
  2. Drag a "pause (ms) ... " block from Basic section of the editor's panel
  3. Change  "digital write pin ... to ..." into "digital write pin P1 to 1"
  4. Change 'pause (ms) ... " into "pause (ms) 250"
  5. Repeat steps 1 to 2
  6. Change  "digital write pin ... to ..." block to "digital write pin P1 to 0"
  7. Change 'pause (ms) ... " block into "pause (ms) 250"

Step 11  Upload the code to micro:bit

  1. Connect a microUSB cable to the micro USB port of the micro:bit
  2. Then connect the other end of the cable to your computer or laptop's USB port
  3. Click on the Download button on the bottom left-hand corner of the Makecode screen
  4. Find the hex file in the Downloads folder or other folder that you might have moved it to
  5. Not unlike dragging a file into a USB drive, this is how you will upload the program to the micro:bit. So open up Finder on the MacOS or Explorer on Windows, and drag the hex file into MICROBIT under 'Devices' on the macOS.
  6. Watch the micro:bit flash for a few seconds and the LED light up red, a slight pause and then yellow ad infinitum or until you unplug it.