Using our website means you agree to using cookies which help us improve microbit.org.Learn more
Skip to content

Activity

Proximity beacon

Advanced | MakeCode, Python | LED display, Radio | Arithmetic operators, Communication, Radio waves

Step 1: Make it

What is it?

Play ‘hotter or colder’ using a pair of micro:bits sending and receiving radio signals.

Two micro:bits and a ruler showing distance between them

How it works

  • Like the Heartbeat beacon project, this uses a pair of micro:bits to sense when one is near another using radio but this program also measures how strong the radio signal is, so you really know when you’re getting closer (‘hotter’) or further away (‘colder’).
  • Flash the receiver program onto one micro:bit, and the transmitter (beacon) on to the other. The beacon sends a low-power radio message. When the message is received, the receiver program analyses the strength of the radio signal: strong signals suggest you are near the beacon, weaker ones further away.
  • The MakeCode version of the program displays a bar graph which gets bigger the stronger the signal and the closer you are. It uses the map block to map radio signal strength numbers from the range -95 (weak) to -42 (strong) to a range 0 to 9 and then plots them using the bar graph block.
  • Python doesn’t have a built-in bar graph or map function, so it works a bit differently. All the LEDs light up when you get close to the beacon, and the closer you get the brighter they glow.
  • It does this by taking radio strength readings using the radio.receive_full() command. This provides the message, the signal strength and a timestamp. We only want to know the signal strength, so we use signal = message[1] to extract this and store it in a variable called signal.
  • The signal strength may be in the range -98 (weakest) to -45 (strongest), and the Python program defines a function called map to convert numbers in this range to the range 0 – 9 which we can use for changing the brightness of the LEDs: 0 means off, 9 is the brightest an LED can be. (You might want to re-use this function in other Python projects as it works very much like the map block in MakeCode).
  • The Python program creates a blank 5x5 image called light using the command light = Image(5,5)
    Its brightness is changed using the light.fill() command.

What you need

  • 2 micro:bits and battery packs
  • MakeCode or Python editor
  • battery pack (optional)

Step 2: Code it

Transmitter / beacon

Receiver

Step 3: Improve it

  • Change the transmitter power to cover a larger area. The power can be any number from 0 to 7.
  • Try changing the signal strength range numbers to improve its performance. You could test what signal strengths you’re getting by writing a program to store the signal strength in a variable and show it on the LED display when you press a button.
  • Use these programs to make a treasure hunt game: hide the beacon transmitter and challenge someone to find it. You could add more beacons.