Basic information
Connecting modules
Pin numbering
Programming
We program the micro:bit in the MakeCode environment. This environment contains ready-made functions for controlling the micro:bit. In addition to the built-in functions, new functions can be added to the MakeCode environment by adding a so-called library.
For most function blocks, you need to select which connector the module is connected to.
Library
In this tutorial, we will use our own Beginner library. The library is designed specifically for this set and contains functions to control all blocks.
On the right is an empty project with an already inserted Beginner's libraryPrograms for specific notebooks can be found below.
Button
Function
The button is the simplest control element. Pressing the button represents the connection (closing) of an electrical circuit, just like connecting 2 wires together. This allows the passage of electrical current to the micro:bit input. The button can be used to control all other blocks in the package, such as the Neopixel, the motor, or individual colored lights.
A button represents an input that has only 2 levels – ON, OFF. We call such an input logical.
Library
Programme
Task 1: Lighting up the display
Task 2: Playing dice
In this example, we don't need to use the released button state. We just need to display a number on the display when the button is pressed. To generate the number, we will use a mathematical library that includes the "random number" function. We choose the same number interval as on a classic dice.
LED light
Function
Library
Using the library, we can turn on the LED with the “turn on LED” function, or turn it off with the “turn off LED” function. Additionally, the LED can be set to a given intensity using the “write a number to LED” block.
LED also has advanced blocks. “Toggle LED” turns on the LED if it is not lit and turns it off if it is lit. The “Turn on LED? true/false” block turns on the LED if we enter the value true into it.
Programme
We connect the LED to connector 2.
Indicator light
Do connector 1 we connect the button. As in the chapter for the button, we will use the structure with the condition “if x then A, otherwise B”. We will use the value of the button in the condition. If it is pressed, we will light the LED using the “light up LED” block. We must not forget to change the connector number. To turn off the LED, we will use the “turn off LED” block.
Intensity settings
Setting the flashing frequency
Blink frequency setting (advanced)
If we don't want to use the "switch LED" block, we can program this logic ourselves using a condition. In order to determine whether the LED is on or off, we need to store this state in a variable. We will create a variable with the value false. This means that nothing is lit at the beginning of the program. Then, in the loop, we will determine whether we want to turn the LED on or off. If the LED is on, i.e. the variable "lit" is true (lit = true), we will want to turn the LED off using the "turn LED off" block. At the same time, we will write this change of state to our variable "lit". So we will set "lit" to false. Otherwise, we will turn the LED on and write true to the variable.
Finally, we set the program pause again using “wait x ms”, where we use the potentiometer value.
Again, don't forget to set the correct connector numbers everywhere.
Motorbike
Function
Library
Programme
We connect the motor to connector 2.
Switching the motor with a button
Speed adjustment with potentiometer
Light sensor
Function
This sensor is capable of sensing the intensity of incident light. Thanks to this, we are able to measure many things. For example, whether it is day or night, whether the light is on in the room, whether there is an obstacle in front of it, and so on.
The main member of the sensor is photoresistor. Similar to a potentiometer, this is a special type of resistor that changes its resistance value. In this case, the resistance depends on the intensity of the incident light. This again changes the value of the current flowing through the circuit and this is again measured by the micro:bit on its input pin.
On the front of the notebook there is also potentiometerWe use it to perform calibration. For measurements in the dark, we need a different sensitivity than for measurements in the light.
Library
In the case of sensors "Light sensor, IR sensor and UV sensor” we use the same blocks. Their output is a truth value true/false.
In advanced blocks, the same block exists, just with an output 1/0.
Programme
We connect the sensor to connector 1.
Automatic fan
We connect the motor to connector 2. The structure is again the same as for switching the motor with a button. Instead of the value from the button, we use the value from the sensor.
Production line
Do connector 2 connect the red LED to connector 3 green. If the sensor sees an obstacle on the belt, the red LED lights up. Otherwise, the green LED lights up.
IR sensor
Function
This sensor is capable of sensing infrared (IR) radiation, which is invisible to the human eye. This allows us to detect heat, movement, or the presence of objects that emit or reflect IR light.
The main member of the sensor is infrared diode and detector. The diode emits IR rays that bounce off the object and return to the detector. When the detector detects the reflected light, the value of the electrical signal changes, which the micro:bit evaluates on its input pin.
The sensor is on again potentiometer, which we use to set the measured level. If we want to detect an object further from the sensor, we need a more sensitive setting.
Library
In the case of sensors "Light sensor, IR sensor and UV sensor” we use the same blocks. Their output is a truth value true/false.
In advanced blocks, the same block exists, just with an output 1/0.
Programme
The task examples are the same as for the previous sensor.
UV sensor
Function
This sensor is capable of sensing ultraviolet (UV) radiation, which is invisible to the human eye. This radiation comes from the sun, for example. This allows us to measure how strong the UV radiation is hitting the sensor, which can be useful for monitoring sun safety or detecting UV light sources.
The main element of the sensor is a special photodetector sensitive to UV radiation. When UV light hits it, it generates an electrical signal. This changes the value of the current flowing through the circuit and this change is again measured by the micro:bit on its input pin.
The sensor is on again potentiometer, which we use to set the measured level. If we want to detect an object further from the sensor, we need a more sensitive setting.
Library
In the case of sensors "Light sensor, IR sensor and UV sensor” we use the same blocks. Their output is a truth value true/false.
In advanced blocks, the same block exists, just with an output 1/0.
Programme
The task examples are the same as for the previous sensor.
IR sensor
Function
This sensor is capable of sensing infrared (IR) radiation, which is invisible to the human eye. This allows us to detect heat, movement, or the presence of objects that emit or reflect IR light.
The main member of the sensor is infrared diode and detector. The diode emits IR rays that bounce off the object and return to the detector. When the detector detects the reflected light, the value of the electrical signal changes, which the micro:bit evaluates on its input pin.
The sensor is on again potentiometer, which we use to set the measured level. If we want to detect an object further from the sensor, we need a more sensitive setting.
Library
In the case of sensors "Light sensor, IR sensor and UV sensor” we use the same blocks. Their output is a truth value true/false.
In advanced blocks, the same block exists, just with an output 1/0.
Programme
The task examples are the same as for the previous sensor.
Neopixels
Function
This block contains 8 lights (so-called pixels for us). These are special LEDs that can shine in any color. They are abbreviated RGB, because one such component hides 3 classic LEDs inside, which shine in red (R – red), green (G – green) and blue (B – blue). By combining these colors, we get any color and any brightness level. Some screens of mobile phones, computers and televisions work on this principle.
RGB LED strips are popular these days and have many uses. We can use them, for example, to display the speed of a motor, the rotation of a potentiometer, or the value of other sensors.
Library
To control the Neopixel, it is necessary to create a variable at the beginning of the program that contains all the necessary information, such as the connector number. Then we only need to refer to this variable. In the basic functions there are blocks to display color, rainbow and bar graph.
In the advanced features, you will find the option to reduce brightness, rotate or shift pixels (suitable, for example, for rotating the displayed rainbow), or convert colors from different color spaces.
Programme
This module requires different handling than all other modules. Instead of a start block, you need to create a variable neo that contains all the necessary information about the module used.
Subsequently, there is no need to enter the connector number again, but it is enough to refer to the given neo variable, such as when the red color is lit. We connect the Neopixel to connector 2.
Potentiometer value display
We connect the potentiometer to connector 1. Instead of displaying a graph on the micro:bit display, we can use Neopixel. Thanks to the “show bar graph” function, we can display the potentiometer value in a more clear way. Again, first we refer to the “neo” object, then we insert the displayed value, i.e. “number from the potentiometer”, and in the last cell “to after” we enter the value 100 (the original value), since this is the maximum that we read from the potentiometer.
Smooth color transition (advanced)
This program smoothly changes the hue of the light. We will use the advanced functions of Neopixel, i.e. the selection of a color in the HSL format, i.e. simply hue, saturation and brightness. First, we will create a hue variable and set it to 0. In the loop, we will use the “neo display color” block and instead of the preset color, we will insert the “hue H saturation S brightness L” block. We will insert our variable into the first cell that represents the hue. We will set the saturation to 99 (i.e. the maximum value) and the brightness to 49 (i.e. the middle of the range). Each program cycle, we will add the value 1 to the hue variable. At the beginning, we must then add a condition that will ensure that when the maximum hue value (360) is reached, the variable is reset to zero again.
OLED display
Function
This display is capable of displaying text or simple graphics using individual light points that light up directly on the screen. Thanks to this, we can display various information such as numbers, texts or simple images.
Each pixel of the display is made up of a small LED that lights up according to a signal from the micro:bit, creating the desired image on the display.
Library
For control OLED displays, BME and Color Sensor again we will use a different approach than for the previous modules. The modules communicate using the I2C protocol and use different pins for this. So there is no need to set which connector to connect them to, but this communication needs to be enabled with a block start.
Programme
We will connect the OLED to connector 4. At the beginning of each program we use the OLED start block. If we want to print text or numbers in a loop, we always have to fill all 8 lines. To do this we use the “OLED draw x empty lines” block.
The picture shows a sample of the BME module startup, but it looks the same for OLED
Greeting new member of
To test the OLED function, we will write a greeting on the display.
Displaying a numerical value
Connect the potentiometer to connector 1In this program, we first print the text “potentiometer”, then we skip 1 line, then we write the numerical value from the potentiometer and finally we skip 5 lines.
Writing text and numbers in 1 line
We connect the potentiometer to connector 1. To write both text and numeric value in one line, we will use only the “OLED draw text” block, into which we will insert the “xy connection” block from the Text library. In the x column, we will insert the text “value: “ with a space at the end, in the y column, we will insert the number we want to display. This function will automatically convert the numeric value to text. The rest of the code is the same as the previous example.
BME weather station
Function
This sensor is capable of measuring basic meteorological parameters such as temperature, humidity, and atmospheric pressure. Thanks to this, we can monitor weather changes and create various projects, such as a home weather station.
The main element of the sensor is a special chip that contains sensors for measuring temperature, humidity and pressure. Each of these sensors converts the measured values into an electrical signal, which the micro:bit then processes on its input pin and converts into readable values that can be displayed, for example, on an OLED display.
Library
For control OLED displays, BME and Color Sensor again we will use a different approach than for the previous modules. The modules communicate using the I2C protocol and use different pins for this. So there is no need to set which connector to connect them to, but this communication needs to be enabled with a block start.
Programme
We will involve BME in connector 3At the beginning of each program we use the BME start block.
Displaying values on the OLED display
We connect the OLED display to connector 4. We simply write the desired values in all 8 lines. First, we write the name of the measured quantity along with the unit and then the numerical value.
Color sensor
Function
This sensor is capable of recognizing colors and measuring light intensity, allowing us to detect different colors of objects and create interactive projects such as recognizing color codes or sorting objects by color.
The main element of the sensor is a special photo detector that measures the intensity of light in different parts of the spectrum (red, green, blue and infrared). The APDS-9960 sensor evaluates this data and the micro:bit then processes it on its input pin, allowing us to determine what color it is detecting.
Library
For control OLED displays, BME and Color Sensor again we will use a different approach than for the previous modules. The modules communicate using the I2C protocol and use different pins for this. So there is no need to set which connector to connect them to, but this communication needs to be enabled with a block start.
Programme
We will connect the color sensor to connector 3At the beginning of each program, we use the COLOR start block.
Listing color components on an OLED display
We will connect the OLED display to connector 4. In addition to the “COLOR start” block, we will also use “COLOR light up additional LED 3”, since the sensor is connected to connector 3. The additional LED will allow us to measure the color of objects near the sensor. If we bring an object that is red closer to the sensor, the R (red) value will be the highest. Writing to the display is explained in the OLED chapter.
Reflected light temperature
Ke connector 4 We connect the Neopixel. If the light hitting the sensor is warm, it will have a higher red component. If the light is cold, the blue component will be higher. We will use the same logic in the program and display the light temperature on the Neopixel. If the red value is higher than the blue value, the red color on the Neopixel will light up. Otherwise, the blue color will light up.

