LED Micro:bit

Control the lighting of two LEDs using the Micro:bit buttons

To control the lighting of two LEDs using the Micro:bit, you will need to connect the LEDs to the Micro:bit‘s I/O (input/output) pins. The Micro:bit has a total of 25 I/O pins, which can be used to connect various types of electronic devices, such as LEDs, sensors, and motors.

Here are the steps you can follow to control the lighting of two LEDs using the Micro:bit:

  1. Connect the positive leg (longer leg) of the first LED to one of the Micro:bit‘s I/O pins. Connect the negative leg (shorter leg) of the first LED to the GND (ground) pin of the Micro:bit.
  2. Connect the positive leg of the second LED to another I/O pin of the Micro:bit. Connect the negative leg of the second LED to the GND pin of the Micro:bit.
  3. Open the Micro:bit‘s programming software, such as the Microsoft MakeCode editor or the Python editor.
  4. In the programming software, create a new project and write a program that controls the lighting of the two LEDs. For example, you can use the built-in “digital write” function to send a voltage signal to the I/O pins that the LEDs are connected to, turning them on or off.
  5. Download the program to the Micro:bit by connecting it to your computer via USB cable.
  6. Once the program is downloaded, disconnect the Micro:bit from the computer, and the LEDs will start to blink according to the program you have written.

Purpose of this tutorial:

In this tutorial we will control the lighting of two LEDs (red and green) via the two buttons A and B of the micro: bit card:

1- When you press button A, the green LED turns on and the red LED turns off.

2- When you press button B, the red LED turns on and the green LED turns off.

Components required

Micro:bit board

Micro:bit is a small, low-cost microcontroller board that was developed by the Micro:bit Educational Foundation for use in computer education. It is designed to be easy to use and accessible to a wide range of users, including children and beginners. The Micro:bit board measures about 4cm by 5cm and features a 25-pin edge connector, a 5×5 LED matrix, two programmable buttons, an accelerometer, a compass, a Bluetooth Low Energy (BLE) module, and a USB connector.

The Micro:bit is programmed using a variety of programming languages such as Python, JavaScript, and Microsoft Block Editor. It can be used to control a wide range of devices and projects, including robots, drones, lights, and more. The board can be powered by a USB cable or a 3V coin cell battery and can be programmed using a computer or mobile device.

The Micro:bit is widely used in education, providing a hands-on learning experience for students of all ages to learn computer programming, logic, and problem-solving. It’s also used by hobbyist and makers to create fun and interactive projects.

Microbit GPIO board

A Micro:bit GPIO (General Purpose Input/Output) Expansion Board is an accessory that can be used to extend the capabilities of a Micro:bit by providing additional input/output (I/O) pins. These pins can be used to connect sensors and actuators, such as LEDs, buttons, motors, and other electronic components.

The expansion board typically connects to the Micro:bit using a standard edge connector and provides a set of male headers that can be used to connect external components.

two LEDs

An LED (Light Emitting Diode) is a type of semiconductor device that emits light when an electric current passes through it. LEDs are commonly used in a wide range of applications, including electronic displays, indicator lights, traffic lights, and lighting fixtures.

LEDs have several advantages over traditional incandescent light bulbs, including:

  • They are more energy-efficient and have a longer lifespan.
  • They emit a much brighter light per watt of power consumed.
  • They produce very little heat, making them safer to use and touch.
  • They are available in a wide range of colors and are commonly used in RGB (red, green, blue) applications.

LEDs consist of a semiconductor material, typically made of a type of crystalline compound, such as silicon or gallium arsenide. When an electric current is applied to the LED, it causes electrons to move from the negative side (n-type) to the positive side (p-type) of the semiconductor. As the electrons move across the junction, they release energy in the form of light.

LEDs can be connected in series or parallel to a power source. When connecting the LEDs in series, the voltage is distributed among the LEDs, but the current remains the same. In contrast, when connecting the LEDs in parallel, the voltage remains the same, but the current is distributed among the LEDs. It’s important to note that, connecting the LEDs in parallel without a current limiting resistor in series with each LED can cause them to burn out quickly.

two resistances of 220Ω 

Resistance is a measure of a material’s opposition to the flow of electric current. It is measured in ohms (Ω) and is represented by the symbol “R”. The more resistance a material has, the less current will flow through it when a given voltage is applied. Conversely, the less resistance a material has, the more current will flow through it when a given voltage is applied.

connecting wires

Connecting wires are used to connect various components in an electronic circuit. They allow for the transfer of electricity, data, or signals between different devices and components.

When connecting wires to an Arduino or other microcontroller, it is important to pay attention to the correct pinout. The pinout refers to the arrangement of pins on the microcontroller and the corresponding function of each pin. The Arduino pinout can be found in the documentation provided by the manufacturer, or in various resources available online.

test plate

A test plate, also known as a test jig, is a device used to test electronic circuits and components. It is a board or plate that has been designed to hold and connect various components and devices in a specific configuration, allowing for the easy testing and measurement of their performance.

A test plate can be used to test various types of electronic circuits and components, such as microcontrollers, sensors, and actuators. It typically includes connectors and sockets for connecting wires, power supply and measurement devices such as multimeters, oscilloscopes, and power supplies.


To perform the assembly, you can connect the green LED to pin P0 and the red LED to pin P1 of the micro: bit card.

There are many mounting methods and here are some examples:

Mounting (1)

Mounting (2)

Mounting (3)

Makecode Program

Here is the makecode program which allows you to light 2 LEDs:

  • Green LED connected to the P0 pin of the micro: bit.
  • Red LED connected to pin P1 of the micro: bit.

0 commentaire

Leave a comment

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Scroll to Top