A micro:bit sends each sensor reading down the USB cable as a line of text, such as light:128. The computer turns the stream of lines into a graph.
Weather stations, heart-rate monitors and the sensors in a science lab all do the same simple thing: send a reading, wait, send the next. A computer collects the readings and draws the graph.
In micro:bit Foundations, everything you made stayed on the micro:bit. Now it talks to the computer it is plugged into. A cable that sends text one line at a time is called serial.
Make your prediction first. Help opens once you've locked it in.

basic.forever(function () {
serial.writeValue("light", input.lightLevel())
basic.pause(500)
})
Run it in the simulator. Under the micro:bit, click Show data (it appears once a program sends values) to see the readings as numbers and as a graph. Drag the simulator's light level up and down.

basic.forever(function () {
serial.writeValue("light", input.lightLevel())
basic.pause(500)
})
Click Download in the editor and copy the program to your micro:bit. Leave it plugged in, then click Connect a micro:bit below and choose it. Cover the micro:bit with your hand, then shine a torch on it.
Download the program to a micro:bit, connect it, and collect at least 10 light readings.
Use the board. This ticks when you get there.

basic.forever(function () {
serial.writeValue("light", input.lightLevel())
basic.pause(500)
})
Ben's program:

serial.writeValue("light", input.lightLevel())
Send the temperature too, with its own name. In Show data (or on the board), each name gets its own line.
Add a second serial write value inside forever, named temperature, with temperature (°C) from Input.
Make it send ten readings a second.
Change the pause so it sends ten readings a second.
Send the temperature as well as the light level, each with its own name.
This ticks by itself when your blocks do what is asked.
Send ten light readings a second.
This ticks by itself when your blocks do what is asked.
Make a tilt logger: send the micro:bit's x and y acceleration five times a second, and send the line mark when A is pressed, so you can mark a moment on the record. Tilt it in the simulator and watch Show data.
Acceleration (mg) is in Input; choose x, then y.
Two serial write value blocks in forever: x and y. On button A pressed: serial write line mark.
A tilt logger: send x and y acceleration five times a second, and send the line mark when A is pressed.
This ticks by itself when your blocks do what is asked.
Students make a micro:bit send sensor readings to the computer over USB as named lines of text, and watch them graphed. About 45 minutes.
Open the teacher guide: answers, solutions, slides and a worksheet.
The idea: a micro:bit plugged into a computer can send text down the USB cable, one line at a time (this is called serial). serial write value sends a line such as light:128: a name, a colon and a number. Whatever is on the other end (MakeCode's Show data, the board in this lesson, a spreadsheet) turns those lines into a table or a graph.
Without micro:bits: the MakeCode simulator shows the values under Show data, so every required step works in the browser. The board step ("On a real micro:bit") is optional and needs a micro:bit, a data USB cable and Chrome or Edge.
With micro:bits: students download the program, leave the micro:bit plugged in, and click Connect a micro:bit on the board. Only one page can use the cable at a time, so if MakeCode is connected to the micro:bit, disconnect it there first.
The text format links the micro:bit and the board. When nothing shows, ask whether the program is running and the write block is inside forever.
Stretch: Send the sound level too, and find out which is noisier: the classroom or the corridor.
Support: Give the Make program with x done; students add y and the button.
Next: the computer sends commands to the micro:bit. Real world: data loggers in science labs, weather stations and fitness trackers.