Beating heart

A big heart and a small heart take turns forever: learners meet loops, timing and animation.

Go to the code ↓

Lesson at a glance

45 to 60 minutes · Grades 3 to 5

maze.education/microbit/lessons/beating-heart

Grades
Grades 3 to 5
Time
45 to 60 minutes
The CAPS gives Coding and Robotics 2 hours a week (Coding and Robotics CAPS, Grades R to 3, page 20; Grades 4 to 6, page 22).
Level
Getting started
A good first or second micro:bit lesson. No coding needed before.
Board
Any micro:bit
Code with
MakeCode and Purple Mash blocks, with Python as an extension
CAPS
Coding and Robotics
Fits: Grade 5, Term 4 · Where it fits

Learning intentions

Learners will learn to:

  1. Use a forever loop to repeat instructions.
  2. Explain the difference between repeating a few times and repeating forever.
  3. Change pauses to make an animation faster or slower.

Success criteria

Each learner can say:

  • I can put blocks inside forever so that they repeat.
  • I can explain when to use repeat 4 times and when to use forever.
  • I can change the pauses to make the heart beat faster or slower.

Competencies

From the Coding and Robotics CAPS places this lesson cites.

  • C.2Present a simple coding solution
  • C.3Interpret and execute a given symbolic or written set of commands
  • C.5Evaluate a given solution towards potential improvement

Key words

loop
Instructions that repeat.
forever
A loop that never stops while the micro:bit has power.
pause
Waiting for a set time, measured in milliseconds.
millisecond
One thousandth of a second. 1000 milliseconds make 1 second.
animation
Pictures shown one after another, so they seem to move.

What you need

  • One micro:bit per learner or pair, with a USB cable and a battery holder
  • A computer with Chrome or Edge for each learner or pair

From our shop: BBC micro:bit V2 Go, BBC micro:bit V2.21 Next Gen Classroom 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 sequence? (Steps that happen in a set order, one after another.)

    Problem statement

    For Heart Awareness Month in September, the school wants a display at the gate that catches the eye. Program a heart that beats by itself, at a speed you choose.

    1. Learners find their pulse on the wrist or neck and count the beats for 15 seconds. A heart repeats the same action over and over without being told.
    2. Read the problem statement. Ask: what else repeats? Day and night, a clock's tick, the chorus of a song.
  2. Lesson development

    35 to 40 minutes
    1. Unplugged first. Clap a pattern: clap, pause, clap, pause. Then say the instructions out loud as a loop: repeat forever, clap, wait. A learner plays the computer and runs the loop until you say stop.
    2. Plan on paper first. Pairs write the heartbeat as an algorithm in numbered steps, then circle the steps that repeat and draw an arrow from the last step back to the first.
    3. Predict. Ask: with pauses of 200 milliseconds, will the heart beat faster or slower than yours? What will happen with pauses of 1000?
    4. Build in blocks. Pairs share one computer. The driver builds the beating heart in forever from the Blocks tab; the navigator checks each block against the numbered plan. Swap roles halfway, after the first heart and its pause.
    5. Test and debug. Watch the simulator. Change both pauses to 100, then to 1000, and compare with the predictions. In MakeCode show icon also waits about 600 milliseconds by itself, which is why even a short pause gives a steady beat.
    6. Experiment: drag the four blocks out of forever into a repeat 4 times loop from Loops, inside on start. The heart beats four times and stops. Which loop does a real heart need? Put the blocks back into forever and download the program to the micro:bit.

    Plan on paper: a model answer

    In pairs, write the heartbeat as numbered steps, then mark the steps that repeat.

    Algorithm
    1. Show the big heart.
    2. Wait 200 milliseconds.
    3. Show the small heart.
    4. Wait 200 milliseconds.
    5. Go back to step 1, forever.
  3. Consolidation

    5 to 10 minutes
    1. Ask: what is the difference between repeat 4 times and forever?
    2. Learners show their fastest and slowest hearts. Which pause numbers did they use?
    3. Back to the problem: which speed would you choose for the display at the gate, and why? Where else would a loop that never stops be useful? A robot at a crossing, a clock, a lighthouse.

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.

The big heart and the small heart joined in a loop with a pause of 200 milliseconds after each, and a timeline showing each picture stays about 800 milliseconds.
In MakeCode, show icon waits about 600 milliseconds by itself, so each picture lasts about 800 milliseconds and one beat about 1.6 seconds.

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 Beating heart.
  2. From Basic, drag show icon into forever and choose the big heart.
  3. From Basic, drag pause (ms) under it and set it to 200.
  4. Add another show icon with the small heart, then another pause (ms) of 200.
  5. Watch the simulator: the heart starts beating by itself.
  6. Click Download and send it to the micro:bit.
The same blocks as text (to paste into MakeCode)
basic.forever(function () {
    basic.showIcon(IconNames.Heart)
    basic.pause(200)
    basic.showIcon(IconNames.SmallHeart)
    basic.pause(200)
})

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

    Make a heartbeat that speeds up after exercise: a shake makes the pause shorter for ten beats.

  2. Challenge 2

    Count the beats in a variable and show the total when you press B.

  3. Challenge 3

    Make the light show react to sound instead, in the Sound-reactive light show lesson (micro:bit V2).

Support and extension

Support

For learners who need more help

  • Give the finished program as a picture, and ask learners to copy it and then change just one number.
  • Use only the big heart and the clear screen block first, so there are fewer icons to choose from.

Extension

For learners who are ready for more

  • Make a variable called gap, use it for both pauses, and set it with button A (fast) and button B (slow).
  • Use show leds to draw a three-frame animation of your own, such as a bouncing ball.

Informal assessment

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

  1. What does the forever block do?
  2. How many milliseconds are there in 2 seconds?
  3. What would happen if you took both pause blocks out?
Exit question

When would repeat 4 times be better than forever?

Observation checklist

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

Watch forBeginningDevelopingAccomplishedExemplary
Writes the steps in order and marks the part that repeats.
Puts the blocks inside forever, not on start.
Predicts what a change to the pause will do, then checks it.
Explains when a loop should stop and when it should not.
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 R to 3, page 127; Grades 4 to 6, page 176). The short descriptions are ours.

In Grade 3, all assessment is school-based, through observation, oral, practical and written tasks (Coding and Robotics CAPS, Grades R to 3, page 121). 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).

Common mistakes and fixes

  • Problem: The heart only beats once.Fix: The blocks are in on start, which runs once. Move them into forever.
  • Problem: The heart does not change size.Fix: Both show icon blocks have the same picture. Choose the small heart in the second one.
  • Problem: The beat is too fast or too slow.Fix: Change the pause numbers: bigger is slower. 1000 milliseconds is one second. In MakeCode, show icon also waits about 600 milliseconds by itself, so even a pause of 0 still beats.

Where it sits in CAPS

  • Coding and RoboticsFitsGrade 5, Term 4: a forever loop that animates a pattern on the micro:bit.Source: Coding and Robotics CAPS, Grades 4 to 6 (opens in a new tab), Grade 5, Term 4, Coding, C.3 Interpret and execute a given symbolic or written set of commands, page 119: forever spike pattern
  • Coding and RoboticsFitsGrade 5, Term 4: the difference between a loop that repeats a set number of times and one that repeats forever.Source: Coding and Robotics CAPS, Grades 4 to 6 (opens in a new tab), Grade 5, Term 4, Coding, C.2 Present a simple coding solution, page 118: Loops also ask questions, such as how many
  • Coding and RoboticsFitsGrade 4, Term 1: the forever loop (the CAPS teaches it with on-screen sprites in Grade 4; here it animates the micro:bit's LEDs).Source: Coding and Robotics CAPS, Grades 4 to 6 (opens in a new tab), Grade 4, Term 1, Coding, C.3 Interpret and execute a given symbolic or written set of commands, page 60: Introduce FOREVER loop and Next backdrop
  • Coding and RoboticsFitsGrade 4, Term 3: a repeat with a fixed number, compared here with repeating forever.Source: Coding and Robotics CAPS, Grades 4 to 6 (opens in a new tab), Grade 4, Term 3, Coding, C.2 Present a simple coding solution using symbolic or written statements representing sequences of commands, single repetition, and conditional constructs, page 78: Introduce Repeat with fixed number (constant value)
  • Coding and RoboticsSupportsGrade 3, Term 4: spot a repeated step and turn it into a loop, done unplugged in the CAPS, as in the unplugged clapping activity.Source: Coding and Robotics CAPS, Grades R to 3 (opens in a new tab), Grade 3, Term 4, Coding, C.5 Evaluate a given solution towards potential improvement, page 116: find pattern / combine single steps into a loop.

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 3 to 5

    Grades 3 to 545 to 60 minLevel: Getting started

    Name badge

    A first program: the micro:bit says hello, then shows the learner's name at the press of a button.

    Subjects: Coding and Robotics

    Code with: MakeCodePurple MashPython

  • Grades 3 to 5

    Grades 3 to 545 to 60 minLevel: Getting started

    Emotion badge

    Learners make a badge that shows how they feel, with a different face for each button and for a shake.

    Subjects: Coding and Robotics · Life Skills

    Code with: MakeCodePurple MashPython

  • Grades 3 to 6Needs a micro:bit V2

    Grades 3 to 6Needs a micro:bit V245 to 60 minLevel: Getting started

    Sound-reactive light show

    The micro:bit V2 listens through its microphone: lights sparkle brighter as the room gets louder, and a clap sets off a flash.

    Subjects: Coding and Robotics · Creative Arts · Natural Sciences and Technology

    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