
This tutorial introduces some ways to communicate with your micro:bit module through a computer. It’s a lot like texting, but you’ll be exchanging messages with your micro:bit instead of another person. The app for this is called the serial monitor, and you already experimented with it in Use the Serial Monitor.
You will need:
Complete these tutorials first:
You will be able to make Makecode projects that make your micro:bit receive, process, and respond to text and numeric values you type into a serial monitor. Along the way, you will build basic skills for tutorials on these subjects:
Most of the Cybersecurity tutorials will use the serial monitor to interact with a micro:bit while its project is running. For example, if the micro:bit picks up any radio messages, it will be able to display them quickly on the serial monitor. For the cyber:bot, it is also useful for testing sensor circuits before relying on them for navigation.
The serial monitor is a kind of terminal. In computing, a terminal is “A combination of a keyboard and output device (such as a video display unit) by which data can be entered into or output from a computer or electronic communications system” according to Merriam-Webster.
Large computers with numerous “terminals” connected to them used to be common in business and academics. Each terminal had a monitor and keyboard, and sometimes other devices.
Image source: “DEC VT100” by Gorthmog is licensed under CC BY-SA 4.0
With the advent of more sophisticated computers and networks, terminal emulator apps like the Windows command prompt became common.

The “terminal” we use is also considered a computer terminal emulator app, even though it is communicating with a microcontroller.
Hardware terminals are still in use today. For example, an ATM (Automated Teller Machine) is a terminal that’s connected to the bank’s system. At the ATM, a user can access their bank account and interact with a bank to withdraw or deposit money, check account balances, etc.
Image source: “ATM_750x1300.jpg” by Rfc1394 is released into Public Domain
Recall from Using the Serial Monitor that you can flash a project to the micro:bit that prints a message, and open the Serial monitor to see that message. Makecode projects can also use serial write to display messages and values as the projects run. This can be helpful for displaying longer messages, and also for displaying what’s happening to values at certain points in your project. And, since you flash the project to the micro:bit, your code travels with your device.
In this activity, you will print messages, values, and combinations of both in the terminal.


Pressing and releasing the micro:bit module’s Reset button, (which is next to its USB connector) restarts the project that’s currently flashed. After that, the micro:bit runs the project again and whenever it executes a serial write block, the result appears in the terminal. In this case, it’s the Hello Terminal! message.
What if you want to display a different message in the online editor? Try modifying the text inside the serial write block.
The micro:bit’s serial write block is completely different from the show blocks and its methods. One of those outputs is not as fast as the other. The show methods are for the 5×5 LED grid, and each block has to display each character long enough for a human to read it. In contrast, the micro:bit serial write block can send characters very rapidly, with each character taking only about 1/10,000th of a second to transmit.
You might have noticed that serial write can display values stored by variables, along with strings of characters. That same functionality is also available when you add serial write blocks to projects.


Let’s try a countdown timer in the terminal using a while loop. The while block repeatedly executes blocks that are indented immediately below it. The loop repeats “while” its condition is true. In this program, the while loop repeats while the value variable is greater than or equal to 0.


You might have been wondering if there’s a way to type messages into the terminal and send them to the micro:bit. Well, there is — with the help of the read until block.


The serial write block can send a prompt, like “Enter some text: “, then the read until block receives the characters you type, and returns them as a string. That string normally gets stored in a variable with a block like set message to ( serial read until () ). The text you type (up to when you press Enter) will get stored in the message variable, and Makecode will automatically set that variable’s type to string. For more on data types, see the Remember and Use Values page.
Customize the example project to ask for and store your name.
Did you use your real name? Don’t worry, the micro:bit is not collecting your personal information! But do keep in mind that there are social aspects to cybersecurity, not just technical!
Let’s say you’re working on a project where you have to enter the cyber:bot robot’s left and right wheel speeds into the terminal. It might seem like all you’d have to do would be to type in numbers like 50 and 100. The problem is that those numbers are received as strings of characters “50” and “100” and then stored in string variables. Before your project can use those values to set robot wheel speeds, it needs to convert them from string to int values with the parse to number block.


If you typed 23 in response to the prompt, the set text to (serial read until () ) block stored “23” in the text variable. This is a string of characters, not a usable number. The next block, set value to (parse to number (text)), converts the “23” string to the integer 23 and stores it in the value variable.
Think about this as two steps. First, the parse to number(text) block takes the text variable, which stores the “23” string, and returns the int value 23. That result gets copied to the int variable named value. Keep in mind that Makecode automatically sets the variable type to int.
Next, serial write line (“value = “, value) prints “value = . Then, the serial write block has to convert the int value 23 stored by value into the character string “23” before sending it to the terminal.
The most important point in this exercise is that you entered characters that the project was able to convert to values it can use to make calculations, control repetitions, and more.
Now that your micro:bit projects can receive values from the terminal, let’s put those values to work in an app. This first example is a countdown timer that allows you to set the number of seconds in the countdown.


First, the project captures the text representation of a number you type into the terminal. This gets converted into an int value that the project can store and use for counting repetitions. This int value gets stored in the value variable.

The text you type in response to the message prompt gets stored as a string of characters in the message variable, which is a string.

Since the value variable now stores an int variable, it can be used to control how many times this while loop repeats:

After the while loop is done, your custom message gets displayed.

This is another way of using text and values from the terminal — a calculator app.



Interval timers repeatedly count down the same amount of time, and are used to control the amount of time one has to repeatedly run a sprint or swim a lap, including rest. They are also used in stretching after a workout so that each stretch is only done for a fixed amount of time.
It helps to break this program into steps. Here is some pseudo-code that you can work from to build the program:
Outer loop always repeats Display a string asking for the countdown seconds. Get the countdown seconds and store in an int variable. Display a string asking for the reps. Get the reps and store in an int variable. while reps > 0 copy countdown seconds to a temporary variable. Print start interval message while temporary variable > 0 Print temporary variable Wait a second Subtract 1 from temporary variable. Subtract 1 from reps Print done with set
Hint: Make the indentation levels in the pseudo code match the indentation levels in your code.