← Micro:bit

Chapter 6

2.4GHz Radio Communication

สื่อสารผ่านคลื่นวิทยุ

  • Both micro:bit V1 and V2 can talk to each other with 2.4 GHz radio (คลื่นวิทยุ 2.4GHz).
  • You use the blocks in the Radio group.
  • No Wi-Fi, no internet and no router are needed.

Radio Fundamentals & Block Taxonomy บล็อกคำสั่งในกลุ่ม Radio

  • Boards talk by sending small packets through the air.
  • First choose a channel (a group), then learn the Radio blocks.
Board A Board B packet Wi-Fi router not needed sender receiver
Two boards talk directly to each other. The packet travels through the air, so no router, Wi-Fi or internet is involved.

Radio groups: your private channel กลุ่มช่องสัญญาณ 0–255

  • radio set group picks a channel from 0 to 255.
  • Sender and receiver must use the same group.
  • Boards in a different group simply do not hear the packet.
group 1 A B B hears A group 5 C D C and D hear nothing from group 1
Only boards in the same group hear each other. A sends to group 1, so B hears it, but C and D (group 5) ignore it.

💡 Remember

  • Use a group number nobody else in the room uses, or you will hear their messages.
  • Call radio set group in on start, before anything is sent.

Transmit power: how far the packet goes

  • radio set transmit power takes a level from 0 to 7.
  • Higher level = longer range (about 70 m in the open at level 7).
  • The default is level 6 if you never set it.
0 1 2 3 4 5 6 7 transmit power level 7 = maximum → 6 = default → low power high power: about 70 m
Each power level is a little stronger than the last. A stronger signal reaches farther.

The Radio blocks ชุดคำสั่งในกลุ่ม Radio

radio send number [0] 7 on radio received [receivedNumber] radio send value ["A"] = [1] "A", 1 on radio received [name] [value] radio send string ["Hello"] "Hello" on radio received [receivedString]
Three kinds of packet. Each send block has a matching receive block with the same shape.
MakeCode Block Description
radio set group [1]
  • Picks the channel, 0 to 255.
  • Call it first, and use the same number on sender and receiver.
radio send number [0] Broadcasts one number (whole or decimal).
on radio received [receivedNumber] Runs when a number arrives. The number is stored in receivedNumber.
radio send value ["name"] = [0] Broadcasts a name (text) and a number together, e.g. "A" = 1.
on radio received [name] [value] Runs when a name and value arrive, stored in name and value.
radio send string ["Hello"] Broadcasts a piece of text.
on radio received [receivedString] Runs when text arrives. The text is stored in receivedString.
radio set transmit power [7]
  • Highest level is 7, about 70 metres.
  • If you never set it, the level is 6.

Next: 6.1 Signal Strength (RSSI) Meter →

6.1 Signal Strength (RSSI) Display แสดงระดับความแรงสัญญาณบน LED 5x5 จุด

  • This is the simplest radio test: both boards show how strong the other board's signal is.
  • RSSI means "received signal strength", measured in dBm.
-128 dBm -42 dBm weakest strongest -42: boards touching -80 to -95: across a room (more negative = weaker)
The RSSI scale. The signal is a negative number: the closer to -42, the stronger it is.
across the room: -80 to -95 -42 (touching) -42 -128 -85 distance between the boards → ↑ signal (dBm)
Typical shape: the signal drops fast over the first few steps, then more slowly. Exact values change with walls, bodies and the room.

Step-by-Step Exercise

  1. Step 1 — Set the group: put radio set group in on start and set it to 1.
  2. Step 2 — Transmit: put radio send number 0 in forever.
  3. Step 3 — Add a delay: add pause (ms) 500 under it, so a packet goes out every half second.
  4. Step 4 — Receive: drag out on radio received [receivedNumber].
  5. Step 5 — Show a number: put show number inside it.
  6. Step 6 — Use the signal: drop received packet signal strength into show number.
Board A Board B send number 0 B shows e.g. -60 send number 0 A shows e.g. -60 ...every 500 ms, both ways
Both boards run the same program. Each one sends a packet every 500 ms and shows the strength of the packets it hears.

Testing the signal meter: download the code to both boards, then move them closer and farther apart.

  • Touching: the number is the highest, around -42 dBm.
  • Across the room: the number gets more negative, around -80 to -95 dBm.

💻 6.1 Signal strength meter — both boards run this same program

on start
radio set group 1
forever
radio send number 0
pause (ms) 500
on radio received receivedNumber
show number received packet signal strength
See it in JavaScript
radio.setGroup(1)
basic.forever(function () {
	radio.sendNumber(0)
	basic.pause(500)
})
radio.onReceivedNumber(function (receivedNumber) {
	basic.showNumber(radio.receivedPacket(RadioPacketProperty.SignalStrength))
})

Next: 6.2 Two-Way Wireless Messaging →

6.2 Two-Way Messaging Between Boards ส่งข้อความระหว่างบอร์ด

  • Example 6.1 sent signal strength. Now we send real text.
  • Each board waits for text from any board in the same group.
Board 1 Board 2 press A send string "Hello" scrolls Hello press B send string "Goodbye" scrolls Goodbye A board does not hear its own message.
Button A sends "Hello"; button B sends "Goodbye". The other board scrolls whatever it receives.
Sender on button A pressed radio send string "Hello" 📡 radio Receiver 📡 radio on radio received show string
Inside one board: a button press goes out through the radio, and a received message goes to the screen.

Step-by-Step Exercise

  1. Step 1 — Set the group: put radio set group in on start and set it to 1.
  2. Step 2 — Button A sends "Hello": drag on button A pressed from Input, then put radio send string inside and type "Hello".
  3. Step 3 — Button B sends "Goodbye": repeat step 2, but choose button B and type "Goodbye".
  4. Step 4 — Receive text: take on radio received [receivedString] from Radio, and put show string from Basic inside it.
  5. Step 5 — Show the text: drag receivedString into show string.

Testing the two-way pager:

  • Download the code to both boards.
  • Press A or B on one board: the message scrolls on the other board.
  • Press A or B on the other board: the message scrolls back on the first one.

💻 6.2 Two-way pager — A sends "Hello", B sends "Goodbye"

on start
radio set group 1
on button A pressed
radio send string Hello
on button B pressed
radio send string Goodbye
on radio received receivedString
show string receivedString
See it in JavaScript
radio.setGroup(1)
input.onButtonPressed(Button.A, function () {
	radio.sendString("Hello")
})
input.onButtonPressed(Button.B, function () {
	radio.sendString("Goodbye")
})
radio.onReceivedString(function (receivedString) {
	basic.showString(receivedString)
})

Next: 6.3 Proximity Friend Finder →

6.3 Proximity Friend Finder ค้นหาเพื่อนด้วยความแรงสัญญาณ

  • A packet carries more than the number or text you send.
  • The receiver can also read these extras:
Your data: number, string, or name + value Serial number: unique to each micro:bit Time: microseconds since the sender started Signal strength: -128 to -42 dBm (-42 = strongest)
What a received packet holds. The first row is what you chose to send; the other rows are added for free.
  • Serial Number: a number unique to each micro:bit.
  • Time: in microseconds, counted from when the sender started.
  • Signal strength: -128 to -42 dBm, and -42 is the strongest.
hidden sends x = 5 every 0.1 s finder far beep ... beep finder nearer beep beep beep finder very close bzzzzzz walk this way →
Hide-and-seek: the hidden board calls out ten times a second. The finder beeps faster the closer you walk.

How the Geiger-Counter Effect Works

  • Each board sends x = 5 every 0.1 s. The value itself does not matter.
  • The receiver's on radio received runs and stores signal strength in the variable signal.
  • In forever, map turns the signal into a number from 1 to 15, and round makes it a whole number.
  • That number sets how long each beep (and each rest) lasts.
  • Weak signal: long beeps, far apart. Strong signal: short beeps, close together. It sounds like you are closing in on the target.
signal (dBm) -100 -70 -40 15 8 1 item (beep length = item × 20 ms)
map turns the signal range -100 to -40 into the numbers 15 to 1. Note that the ranges run in opposite directions.
-100 dBm item 15 -70 dBm item 8 -40 dBm item 1 0 – 640 ms
Beep timeline for each signal strength: a beep lasts item × 20 ms, then rests for the same time.

1. Transmitter Code โค้ดของตัวส่ง

💻 6.3 The hidden board (transmitter) — it calls out ten times a second

on start
radio set group 81
forever
radio send value x = 5
pause (ms) 100
See it in JavaScript
radio.setGroup(81)
basic.forever(function () {
	radio.sendValue("x", 5)
	basic.pause(100)
})

2. Receiver Code โค้ดของตัวรับ

💻 6.3 The finder (receiver) — the beeps get faster as you close in

on start
radio set group 81
on radio received name value
set signal to received packet signal strength
pause (ms) 200
forever
set item to round(map signal from low -100 high -40 to low 15 high 1)
play tone High A for item × 20 ms
rest (ms) item × 20
See it in JavaScript
let signal = 0
let item = 0
radio.setGroup(81)
radio.onReceivedValue(function (name, value) {
	signal = radio.receivedPacket(RadioPacketProperty.SignalStrength)
	basic.pause(200)
})
basic.forever(function () {
	item = Math.round(Math.map(signal, -100, -40, 15, 1))
	music.playTone(Note.A5, item * 20)
	music.rest(item * 20)
})

📘 Book correction: the first second

  • Before the first packet arrives, signal is still 0, which is outside the −100 … −40 range.
  • map then gives a negative beep length, so the very first beeps are wrong.
  • Fix: add set signal to -100 in on start, so the finder starts at "far away" (slow beeps).

Next: 6.4 Classroom Voting System →

6.4 Classroom Voting & Scoring System สร้างระบบให้คะแนน

  • You need 5 micro:bits: 4 transmitters (the judges' clickers) and 1 receiver (the scoreboard).
  • Each judge can only vote yes or no.
  • The scoreboard shows the four votes on its 5×5 LEDs.
Judge 1 "A" = 1 or 0 Judge 2 "B" = 1 or 0 Judge 3 "C" = 1 or 0 Judge 4 "D" = 1 or 0 Scoreboard group 81
Star layout: four clickers all send to one scoreboard in the same group (81). Each clicker has its own name so the scoreboard knows who voted.

Transmitters Code (#1, #2, #3, #4)

  • Transmitters use radio send value: a name plus a number, so the scoreboard knows which board sent it.
  • The names are A, B, C, D.
  • Press A: sends 1 and shows show icon (Yes).
  • Press B: sends 0 and shows show icon (No).
Button A: sends 1
Button B: sends 0

Transmitter #1 (judge 1)

on start:
    radio set group 81

on button A pressed:
    radio send value "A" = 1
    show icon (Yes)

on button B pressed:
    radio send value "A" = 0
    show icon (No)

Transmitter #2 (judge 2)

on start:
    radio set group 81

on button A pressed:
    radio send value "B" = 1
    show icon (Yes)

on button B pressed:
    radio send value "B" = 0
    show icon (No)

Transmitter #3 (judge 3)

on start:
    radio set group 81

on button A pressed:
    radio send value "C" = 1
    show icon (Yes)

on button B pressed:
    radio send value "C" = 0
    show icon (No)

Transmitter #4 (judge 4)

on start:
    radio set group 81

on button A pressed:
    radio send value "D" = 1
    show icon (Yes)

on button B pressed:
    radio send value "D" = 0
    show icon (No)

Try judge 1’s clicker

💻 6.4 Judge 1’s clicker — A votes yes, B votes no

on start
radio set group 81
on button A pressed
radio send value A = 1
show icon
on button B pressed
radio send value A = 0
show icon
See it in JavaScript
radio.setGroup(81)
input.onButtonPressed(Button.A, function () {
	radio.sendValue("A", 1)
	basic.showIcon(IconNames.Yes)
})
input.onButtonPressed(Button.B, function () {
	radio.sendValue("A", 0)
	basic.showIcon(IconNames.No)
})

Scoreboard Receiver Code โค้ดของตัวรับและแสดงผล

  • The receiver uses if to check the name first.
  • Then it checks whether the value is 0 or 1.
  • Value 1: switch that judge's LED on. Value 0: switch it off.
on radio received name, value name = ? "A" → plot x 0, y 0 "B" → plot x 1, y 0 "C" → plot x 2, y 0 "D" → plot x 3, y 0 value = 1 ? yes: plot (LED on) no: unplot (LED off)
Decision flow in the scoreboard: the name picks the LED column, the value picks on or off. All four LEDs are in the top row (y = 0).

💻 6.4 The scoreboard (receiver) — one LED per judge

on start
radio set group 81
on radio received name value
if name = "A" then
if value = 1 then
plot x 0 y 0
else
unplot x 0 y 0
else if [name = "B"] then
if value = 1 then
plot x 1 y 0
else
unplot x 1 y 0
else if [name = "C"] then
if value = 1 then
plot x 2 y 0
else
unplot x 2 y 0
else if [name = "D"] then
if value = 1 then
plot x 3 y 0
else
unplot x 3 y 0
See it in JavaScript
radio.setGroup(81)
radio.onReceivedValue(function (name, value) {
	if (name == "A") {
		if (value == 1) {
			led.plot(0, 0)
		} else {
			led.unplot(0, 0)
		}
	} else if (name == "B") {
		if (value == 1) {
			led.plot(1, 0)
		} else {
			led.unplot(1, 0)
		}
	} else if (name == "C") {
		if (value == 1) {
			led.plot(2, 0)
		} else {
			led.unplot(2, 0)
		}
	} else if (name == "D") {
		if (value == 1) {
			led.plot(3, 0)
		} else {
			led.unplot(3, 0)
		}
	}
})
Judge 1 yes Judge 2 yes Judge 3 no Judge 4 yes radio, group 81 columns 0 – 3 = judges 1 – 4
Example result: judges 1, 2 and 4 voted yes, judge 3 voted no. Only the top row is used.
Scoreboard: 1, 2 and 4 voted yes
  • Result on the scoreboard: the top row of the 5×5 LEDs (columns 0, 1, 2, 3 in row y = 0).
  • A judge's LED lights when they press the approve button (1) and goes dark on reject (0).
  • The teacher and audience see all four judges' decisions live.

Next: Interactive Radio Hardware Explorer →

Interactive Radio & RF Hardware Explorer

Hover over or tap any part of the 2.4 GHz radio subsystem on the real micro:bit V2 photograph below.

Your blocks nRF52833 chip group filter, error check PCB antenna 2.4 GHz waves
The radio chain inside a board, from your blocks to the air.
🔍

micro:bit V2 2.4 GHz Radio Subsystem

Interactive Map
micro:bit V2 Back View - Radio Antenna and nRF52833 SoC
👉

Hover or tap the 2.4 GHz PCB Antenna, nRF52833 SoC, or Speaker to inspect wireless communication hardware.

Next: Test Your Knowledge with the Quiz →

Chapter 6 Review & Self-Check

vote yes = 1
vote no = 0
scoreboard row
  • Group 0–255: same number on both boards, or nothing is heard.
  • Transmit power 0–7: higher goes farther. Default 6.
  • RSSI: -128 (weak) to -42 (strong) dBm.
  • Three packet types: number, value (name + number), string.

Test your understanding of radio groups, RSSI, the proximity formula and the voting system.

1. What is required for two micro:bit boards to communicate with each other over the radio?
2. What are the minimum and maximum power levels for `radio set transmit power`?
3. What does RSSI measure, and what does a reading of -42 dBm signify compared to -100 dBm?
4. In the Proximity Treasure Finder project (Section 6.3), how is distance conveyed to the user?
5. In the Classroom Voting System (Section 6.4), how do 4 student clickers send their choices to the teacher’s receiver?
6. Two boards must share which setting before they can hear each other?
7. What does `radio send value "A" = 1` send out?
8. Which group numbers can `radio set group` use?