Skip to content

Activity

Send a smile

Beginner | MakeCode, Python | Buttons, LED display, Radio | 3 Health, Communication, Input/output, Radio waves

Step 1: Make it

What is it?

Sharing and receiving kindness is a good way to support your well-being and that of your friends. Create a program using radio to send a smile from one micro:bit to another to support a friend.

This project is part of a series created to offer problem-solving and prototyping activities designed to explore technology as a solution to the challenges of the Global Goals for Sustainable Development.

Introduction

Coding guide

What you'll learn

  • How radio communication between electronic devices uses protocols to ensure messages are routed correctly
  • How technology and electronic communication can be used for good

How it works

  • This program uses the micro:bit's radio feature to share a smile. You can use it in the MakeCode simulator or flash the code on to 2 or more micro:bits.
  • First, it sets the radio group to 2. Groups are like channels, so any micro:bit using the same group will get the smile. You can use any group number you like from 0-255.
  • When you press button A, it sends a radio text message 'smile'. It also clears the screen so you can send another smile.
  • When it receives a radio message, it shows a smile emoji on the LED display.
  • The combination of radio group and the text of the radio message sent make up a protocol: a set of rules for how two devices communicate.

What you need

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

Step 2: Code it

1from microbit import *
2import radio
3radio.config(group=2)
4radio.on()
5
6while True:
7    message = radio.receive()
8    if message:
9        display.show(Image.HAPPY)
10    if button_a.is_pressed():
11        display.clear()
12        radio.send('smile')

Step 3: Improve it

  • Customise the smile emoji to your own happy face.
  • If you're working in pairs in a class, select your own unique radio group numbers for each pair of students so you can send messages to your partner but not anyone else.
  • You could also do this by keeping the same radio group, but modifying the code so the text message sent is unique to your pair. Modify the code so it only shows a smile if the correct message is received.
  • How might you send a different emoji if you press button B?