BBC micro:bit – Voting System

yes-noIn this challenge you will create a voting system using the BBC micro:bit. You can complete the code online on the BBC micro:bit website.

The idea is to use the BBC micro:bit in the classroom to conduct a survey by asking a yes/no question such as:

  • Should our school change our school uniform?
  • Should we have more computer science lessons on our timetable?
  • Should we have more healthy eating options on our school menu?

Then you will pass the micro:bit around so that each pupil can vote using the A and B buttons of the microbit:

  • A: Vote Yes
  • B: Vote No

Using two variables called voteA and voteB the BBC micro:bit will keep track how many times the A button is pressed and how many times the B button is pressed.

After each vote the BBC micro:bit will display a tick for two seconds to confirm the vote.


To finish the vote the user will press both A and B buttons at the same time. In this case the BBC micro:bit will display how many A votes have been recorded (variable voteA), how many B votes have been recorded (variable voteB) and then use an If Statement to decide if option A (Yes) Or B (No) wins. To do so it will use comparison operators such as > or <. (if voteA > voteB then A wins)

Building the voting system step by step:

Step 1: Initialising the BBC micro:bit
bbcmicrobit-vote-1Let’s initialise our voteA and voteB variables that will be used to count how many tumes the A nad B buttons have been pressed.
Step 2: When button A is pressed
When button A is pressed we need to increment A by 1. Then we can display a tick to confirm the vote was recorded.
We then display a question mark to inform the user the BBC micro:bit is ready to accept another vote.
Step 3: When button B is pressed
Very similar to the previous code, this time to record the B vote.
Step 4: When A+B are pressed simultaneously
The user pressed both A and B at the same time to end the vote. In this case the BBC micro:bit will display how many A votes were recorded, how many B votes were recorded and decide if A or B wins or if it is a draw.

Complete and Test your Voting System

Complete the system using the code provided above.

Test the game using the online emulator. Then when you are confident if fully works, download your code to the BBC micro:bit and conduct your first survey with your classmates. Make sure you ask for a question with only two possible answers (e.g. Yes/No question).

Did you like this challenge?

Click on a star to rate it!

Average rating 4.2 / 5. Vote count: 13

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: