Classroom voting system

Every board votes yes or no by radio and the counting board keeps the tally: learners build a class vote, then ask whether it is fair.

Go to the code ↓

Lesson at a glance

45 to 60 minutes · Grades 4 to 7

maze.education/microbit/lessons/class-vote

Grades
Grades 4 to 7
Time
45 to 60 minutes
The CAPS gives Coding and Robotics 2 hours a week (Coding and Robotics CAPS, Grades 4 to 6, page 22; Grades 7 to 9, page 22).
Level
Some experience
For classes that have used the micro:bit and MakeCode once or twice.
Board
Any micro:bit
Code with
MakeCode blocks, with Python as an extension
CAPS
Mathematics, Coding and Robotics, Social Sciences
Fits: Grade 7, Term 3 · Where it fits

Learning intentions

Learners will learn to:

  1. Send a number by radio and act on the number that arrives.
  2. Keep a tally of votes in two variables and show the result.
  3. Spot a weakness in a voting system, such as voting twice, and suggest a fix.

Success criteria

Each learner can say:

  • I can send a number by radio when a button is pressed.
  • I can keep a tally of yes and no votes in two variables and show the totals.
  • I can name one way to cheat our voting system and suggest a fix.

Competencies

From the Coding and Robotics CAPS places this lesson cites.

  • R.3Outline the different components of a robot
  • R.7Create, test and execute a set of robotic instructions

Key words

vote
A choice one person makes that is counted with everyone else's.
tally
A running count, one mark or one more for each vote.
radio group
A number from 0 to 255. Only boards in the same group hear each other.
receiver
The board that hears the messages. Here the teacher's board counts the votes.
fair
A vote is fair when everyone can vote, each vote counts once and nobody can change another's vote.
trace table
A table that follows the value of each variable, step by step, as a program runs.

What you need

  • A micro:bit for each pair or group, plus one for the teacher, with USB cables and battery holders
  • A computer with Chrome or Edge for each pair
  • Three questions the class can vote on, such as: should we have the next lesson outside?

From our shop: BBC micro:bit V2.21 Next Gen Classroom Pack, BBC micro:bit V2 Club Pack

Safety

  • Keep USB cables tidy on the desk so nobody trips over them or pulls a laptop off the table.
  • Use the battery holder with two AAA batteries. Never mix old and new batteries, and take the batteries out before the kits are packed away.
  • Unplug the battery holder by holding its plug, never by pulling the wires.

The lesson plan

One lesson of 45 to 60 minutes in three parts: introduction, lesson development and consolidation. The CAPS gives Coding and Robotics 2 hours a week, so it fits one of the week's lessons. Times are a guide.

  1. Introduction

    5 to 10 minutes
    Retrieval practice

    What is a variable? (A named place in a program that holds a value, which can change while the program runs.)

    Problem statement

    The class must choose what to sell at the market day stall, and a hands-up vote is neither secret nor easy to count. Build a radio voting system in which every board sends its vote to one counting board, then decide whether it is fair.

    1. Hold a quick hands-up vote and record it on the board with tally marks. Ask: was that easy to count? Was it secret?
    2. Read the problem statement. Explain that our boards will send their votes by radio to one counting board, the way some meetings use voting handsets.
  2. Lesson development

    35 to 40 minutes
    1. Unplugged first. Vote with paper slips: each learner writes Y or N, folds the slip and posts it in a box. Two counters tally the slips on the board. Then ask what could go wrong: someone posts two slips, a slip is unreadable, or the counters make a mistake.
    2. Plan on paper first. Pairs fill in an IPO table for the voting boards and the counting board. Grade 7 learners add a trace table: the values of yes and no as five votes arrive.
    3. Predict. Ask: if three boards press A and two press B, what will the counting board show when A and B are pressed together on it? Pairs write the prediction down.
    4. Build in blocks. Agree one radio group number for the whole class and write it on the board. Pairs share one computer: the driver builds the program from the Blocks tab, and the navigator checks each block against the IPO table. Swap roles halfway, at the on radio received block. Every board runs the same program: download it to every board, including the teacher's.
    5. Test and debug. Run a test vote of five, as in the prediction: A sends 1 for yes and B sends 2 for no. The teacher's board does not vote; it only counts. Press A and B together on it to see the totals. If the count is wrong, check every board's group number first.
    6. Hold three votes. Before each one, press the reset button on the back of the teacher's board so the tally starts at 0, and record each result in a table. Then test the system: can one pair vote three times? Discuss how to fix it, and try the fix in the extension task.

    Plan on paper: a model answer

    In pairs, fill in an IPO table for the voting system. Grade 7 learners also trace yes and no as five votes arrive at the counting board.

    IPO table
    InputProcessingOutput
    Button A is pressed on a voting boardSend the number 1 by radioA tick shows on the voting board
    Button B is pressed on a voting boardSend the number 2 by radioA cross shows on the voting board
    A number arrives at the counting boardIf it is 1, add 1 to yes; if it is 2, add 1 to noThe top right light blinks
    A and B are pressed together on the counting boardRead yes and noY, the yes total, N and the no total scroll past
    Trace table
    Grade 7: the counting board's variables as five votes arrive, three yes and two no.
    VotereceivedNumberyesno
    Startnone yet00
    1110
    2211
    3121
    4131
    5232
  3. Consolidation

    5 to 10 minutes
    1. Show the results table. Which question had the biggest difference between yes and no?
    2. Ask: why must every board be in the same radio group, and what happens if a board is in a different one?
    3. Back to the problem: was our radio vote fair enough to choose the market day stall? What would make it fairer? Learners check themselves against the success criteria.

Build it, step by step

Pairs build the program in blocks, following the numbered steps, with the same program as text beside them to check against or paste. Test in the simulator before sending it to a board.

Voters press A to send 1 (tick) or B to send 2 (cross) in radio group 7. The counting board adds to yes or no and blinks its top right light, and A and B together scroll Y, the yes total, N and the no total.
Votes travel as numbers: 1 for yes and 2 for no. The counting board keeps the tally in two variables.

These are the MakeCode steps. The other routes are on the lesson's web page.

Build it in MakeCode blocks

  1. Start a New Project called Vote. From Radio, put radio set group in on start with the class number.
  2. In Variables, make yes and no. From Input, add on button A pressed with radio send number 1 and show icon with the tick.
  3. Add on button B pressed with radio send number 2 and show icon with the cross.
  4. From Radio, add on radio received receivedNumber. Inside, add if then else if: if receivedNumber = 1, change yes by 1; else if receivedNumber = 2, change no by 1.
  5. Still inside, add toggle x 4 y 0 from Led, so a light blinks every time a vote arrives.
  6. Add on button A+B pressed: show string Y, show number yes, show string N, show number no.
  7. Test in the simulator (it shows two boards), then Download to every board.
The same blocks as text (to paste into MakeCode)
let no = 0
let yes = 0
input.onButtonPressed(Button.A, function () {
    radio.sendNumber(1)
    basic.showIcon(IconNames.Yes)
})
input.onButtonPressed(Button.B, function () {
    radio.sendNumber(2)
    basic.showIcon(IconNames.No)
})
input.onButtonPressed(Button.AB, function () {
    basic.showString("Y")
    basic.showNumber(yes)
    basic.showString("N")
    basic.showNumber(no)
})
radio.onReceivedNumber(function (receivedNumber) {
    if (receivedNumber == 1) {
        yes += 1
    } else if (receivedNumber == 2) {
        no += 1
    }
    led.toggle(4, 0)
})
radio.setGroup(7)

To use the text instead: open MakeCode, start a new project, click JavaScript at the top, replace what is there with this code, then click Blocks to see it as blocks.

To send it to the board, click Download. In Chrome or Edge, MakeCode can connect to the micro:bit by USB so the program goes straight onto it. Otherwise a .hex file downloads: drag it onto the MICROBIT drive.

Extension or homework

Challenges for learners who finish early, or to take further in a club or as homework.

  1. Challenge 1

    Show the result as a picture: if yes is bigger, show a tick; if no is bigger, a cross; if they are equal, a straight line.

  2. Challenge 2

    Work out each answer as a fraction or a percentage of all the votes, and draw a bar graph of your three questions.

  3. Challenge 3

    Build a messaging system next, in Radio messages or the Morse code messenger.

Support and extension

Support

For learners who need more help

  • Give pairs the program with only the radio group to change, and focus the lesson on the voting and the results table.
  • Count yes votes only first. Add no once the yes count works.

Extension

For learners who are ready for more

  • Stop double voting: add a variable voted, set to false at the start. A and B only send a vote if voted is false, and then set it to true.
  • Add a third choice with on shake that sends 3 for 'not sure', and show it in the totals.

Informal assessment

Ask these as learners work. Informal assessment happens every day and is not recorded.

  1. What number does a board send for yes, and what does the counting board do when it arrives?
  2. Why does the teacher's board not vote?
  3. Give one way someone could cheat in our first version, and one way to stop it.
Exit question

Yes got 14 votes and no got 6. What fraction of the class voted yes?

Observation checklist

Watch pairs as they plan, build and test. Write each pair's initials under the level you see.

Watch forBeginningDevelopingAccomplishedExemplary
Fills in the IPO table for the voting boards and the counting board.
Predicts the totals for a test vote, then checks them.
Keeps the tally in two variables and shows both totals.
Finds a way to cheat the system and suggests a fix.
Beginning:
not yet, even with help
Developing:
with help
Accomplished:
on their own
Exemplary:
on their own, and explains it or takes it further

The four levels are the CAPS rubric levels (Coding and Robotics CAPS, Grades 4 to 6, page 176; Grades 7 to 9, page 163). The short descriptions are ours.

This lesson is not a formal task, but it is good practice for the term's practical task in Grades 4 to 6 (Coding and Robotics CAPS, Grades 4 to 6, page 170), and for the mini-PATs in Grades 7 to 9 (Coding and Robotics CAPS, Grades 7 to 9, page 157).

Common mistakes and fixes

  • Problem: The counting board stays at 0.Fix: Check every board has the same radio group and was given the new program.
  • Problem: The totals include votes from another class.Fix: Another class nearby is using your group number. Choose a different one from 0 to 255.
  • Problem: Pressing A and B together sends a vote.Fix: Press both at exactly the same time. In Python, keep the two lines that clear the button presses after the totals.

Where it sits in CAPS

  • Coding and RoboticsFitsGrade 7, Term 3: one micro:bit sends a number by radio and another acts on it.Source: Coding and Robotics CAPS, Grades 7 to 9 (opens in a new tab), Grade 7, Term 3, Robotics, R.3 Outline the different components of a robot, page 79: Basic introduction to Radio Communication (2 Devices)
  • Coding and RoboticsFitsGrade 7, Term 3: a micro:bit program that keeps each group's score.Source: Coding and Robotics CAPS, Grades 7 to 9 (opens in a new tab), Grade 7, Term 3, Robotics, R.7 Create, test and execute a set of robotic instructions, page 81: Program the microcontroller to keep the total score
  • MathematicsGrades 4 and 5 Mathematics: collecting data with tally marks and tables.Source: CAPS Mathematics, Grades 4 to 6 (opens in a new tab), Section 2, topic 5.1 Collecting and organising data (Grades 4 and 5): Collect data using tally marks and tables for recording
  • Social SciencesFits Social Sciences, and Life Skills (Life Orientation in Grade 7): how groups make fair decisions, and why every vote should count once.

Coding and Robotics quotes come from the Department of Basic Education's final CAPS, with the page number of the 2024 printed edition (the Department's October 2025 library copies number their pages differently). Schools may teach a topic in another term: the CAPS leaves the order to each school's annual teaching plan.

Ready to teach it?

Get a micro:bit for every learner or pair, and let us train your staff to run lessons like this one.

More lessons

All lessons →
  • Grades 4 to 7

    Grades 4 to 745 to 60 minLevel: Getting started

    Step counter

    Every step adds one: learners use a variable to count steps, show the total and reset it, then test how accurate it is.

    Subjects: Coding and Robotics · Mathematics · Life Skills · Life Orientation

    Code with: MakeCodePurple MashPython

  • Grades 4 to 7

    Grades 4 to 745 to 60 minLevel: Some experience

    Music maker

    Buttons play notes, A and B together play a scale and a shake starts a tune: a pocket instrument learners compose for.

    Subjects: Creative Arts · Coding and Robotics

    Code with: MakeCodePurple MashPython

  • Grades 4 to 7

    Grades 4 to 745 to 60 minLevel: Some experience

    30-second fitness challenge

    Press A, count down, and the micro:bit counts your star jumps for 30 seconds using its motion sensor.

    Subjects: Life Skills · Life Orientation · Coding and Robotics · Mathematics

    Code with: MakeCodePython

micro:bit is a trade mark of the Micro:bit Educational Foundation, and BBC is a trade mark of the British Broadcasting Corporation. Maze Education is an independent reseller of genuine BBC micro:bit products. Our teacher training and our other products and services are our own, and are not endorsed by the Foundation or the BBC.

WhatsApp