Lesson 01 – LED


In this lesson we are going to be taking a look at the LED (light emitting diode), which are used in almost every application in consumer electronics. In this lesson we are going to use the BBC micro:bit to make two LEDs flash, alternate.

What you need

  • micro:bit board
  • Micro USB Cable
  • Pi Supply micro:bit breadboard adaptor
  • Breadboard
  • 2x LED
  • 2x 100 ohm resistors
  • Male to male jumper wires


LED is a light emitting diode, it is a semi-conductor diode. LEDs convert electricity into light and consume a very low amount of current making them popular to use over conventional lighting applications as well as being inexpensive components. LEDs can come in all sorts of different shapes and sizes with various technical characteristics but they all work in the same way. Below is an image of a typical LED that you will use with the micro:bit board and is known as a through-hole component due to its two legs.

If you look carefully at the image of an LED above, you can clearly see that one of the legs is longer than the other and also one side of the LED housing has a flat edge to it. These are indicators to show you which leg is the anode (positive) and which is the cathode (negative). The longer leg gets connected to the positive power supply (3.3V) and the leg with the flat side of the housing or the shorter leg is the cathode and goes to ground.


Resistors are a passive component that control the current in a circuit. It can limit the current of a circuit connected to protect a component (such as an LED) from blowing out or getting damaged. In our experiment in this lesson we are going to use a 100ohm resistor to limit the current to the LED so it does not damage it in the circuit.

Hardware Connection

You will need to connect the components according to the breadboard diagram below. Remember that the orientation of the LED matters because it is a diode, the current will only flow through from the anode to cathode.

Once you have connected all the component you should have a circuit which looks like the below image:


Click to open up Microsoft Makecode, then add the following code to the edit area:

You can see the whole program in the page below. Click “Edit” on the right top corner, and then “download”, you can download your code into Micro:bit.


Here is the link to the whole program: https://makecode.microbit.org/_AwyeCU2zaeV4

Code Explanation

Forever – The forever block is a block that loops any other command blocks inserted into it over and over again…forever. It starts from the top and executes your code in order working its way to the bottom and then starts at the top again.

Digital Write – The DigitalWrite block enables you to turn a pin on or off. There is a dropdown option for which pin you want to control, and it accepts a variable as the pins state. You use 1 as on and 0 as off. If you prefer, you can also use Boolean states of true and false, but we will use 0 and 1 as our standard throughout this guide.

Pause – If you were to just turn pins on and off with the digital write block without a pause, the LED would blink really, really fast. The pause block enables you to slow the micro:bit down and lets you control the timing of things happening. It accepts a number or variable as the number of milliseconds you want the micro:bit to pause. Think of this block as a stoplight for your code!


When you upload the program to your micro:bit you should see that the LEDs are flashing alternatively, if it is not for whatever reason, go back and check that you have the circuit built correctly and also the code is correct.

Taking it further

If you want to control 4 LEDs  and make them flash in sequence, then how will you design the circuit and make the program. Try flashing 3 LEDs first and possible use different colours such as the colours of a traffic light.

micro:bit Starter Kit Lessons

  • Lesson 01 – LED
  • Lesson 02 – Button
  • Lesson 03 – Trimpot
  • Lesson 04 – Photocell
  • Lesson 05 – RGB LED
  • Lesson 06 – Self-lock Switch
  • Lesson 07 – Temperature Sensor
  • Lesson 08 – Servo
  • Lesson 09 – Buzzer
  • Lesson 10 – Motor
  • Lesson 11 – Rainbow LED
  • Lesson 12 – Accelerometer
  • Lesson 13 – Compass
  • Lesson 14 – Ambient Light



First published at 4:16pm on July 8, 2019
Last updated at 4:16pm on July 8, 2019