Hour of Code: Virtual Pet Lesson Plan


In this code activity, students are introduced to embedded programming on the BBC micro:bit. The activity is available in the Blockly visual programming language or the Python programming language. A full micro:bit simulator is provided for both, so you do not require a physical micro:bit device.

The activity is structured as sequence of interactive notes and questions that students are challenged to answer. Students learn how to display images to the screen and handle button presses. They are introduced to computational thinking concept of branching control structures to make decisions that control the flow of a program.

Learning Objectives

Students will:

  • learn how to show an image on the micro:bit's LED screen
  • learn how to get the state of an input button
  • learn how to repeat code in the background forever
  • learn how to make decisions and take different actions based on those decisions
  • learn how to use logic and problem solving skills to answer simple questions

Extended activities

The BBC micro:bit is an embedded device designed for the classroom. (What is an embedded device?)

As well as the LED display and buttons, the micro:bit also contains an accelerometer, temperature sensor, magnetometer, and Bluetooth, and can be connected to other components like speakers, motors, screens, lights, and more.

The activity provides an excellent opportunity to discuss examples of embedded devices students may have encountered, and leads into a discussion about the Internet of Things.

Brainstorm examples of embedded devices in the real world, and what sensors and components they contain.

Some examples:

  • Tamagotchis (and other handheld game consoles such as Gameboys) contain a screen, buttons and speakers.
  • Gaming controllers such as the Nintendo Wii remotes sense motion using an accelerometer, and use a motor to create vibration.
  • Fitness trackers use accelerometers to sense movement.
  • Mobile phones are rich embedded devices that contain screens and buttons, magnetometers (like a compass), accelerometers, Bluetooth, light sensors (to adjust screen brightness), biometric fingerprint sensors, cameras, and more.
  • Home appliances such as refrigerators and air conditioners (temperature sensors to automatically control the temperature), microwaves (microwave power and time), washing machines.
  • Modern cars contain many features that are controlled by a embedded systems: radio, door locks, automatic parking, cruise control, airbags and anti-lock braking systems to name a few. They use sensors such as rear-view cameras, accelerometers and pressure sensors.
  • In medicine, devices can monitor a patient's biometrics, and administer help or alert the user as necessary. Examples include pacemakers, neurostimulators, implantable cardio defibrillators, continuous glucose monitoring devices and insulin pumps.
  • Satellites need to weigh as little as possible in order to be launched into space, and have microcontrollers controlling the sensors.
  • Electronic signs for roadworks, showing petrol prices, etc.

Design new applications for embedded devices in the context of an Internet of Things, where devices are connected to the internet and can speak to each other.

Some examples:

  • Smart homes: lights that are connected to motion sensors and switch on and off depending on whether a room is occupied; fridges that keep track of their contents (and their expiry dates!), smart thermostats that control blinds, heaters and air conditioners.
  • Drones that automatically follow you and can capture video and photos, and deliver mail to your home.
  • Items that you can't lose: footballs, frisbees and sunglasses you can track with your phone!

If you have physical micro:bits, design and create skins for the micro:bit to match the virtual pet.

Extend the lesson into a crafts project by using paper, play dough or textiles to create a skin for the micro:bit. Here's an example of a skin for a rabbit pet.

Register as a teacher for free!

Or pick one of our other fun activities. Suitable for Grades 3-12.

Monster Maker! (Blockly)

Use drag-and-drop blocks to write your own programs, learn about sequence and ordering, and create fun monster characters!

Start coding now!

Animal Classifier (Python)

Learn about the differences between animals, and how Biologists use programming to help them do science! You'll use the programming language Python to classify animals based on their characteristics.

Start coding now!

Cyber Security: Defence Against the Dark Hats

This Cyber Security Mini course is a short introduction to staying safe online. You'll learn about secure passwords, phishing, security settings, social media and more!

Start coding now!

Is Eliza Human? (Python)

Use the programming language Python to build a friendly chatbot called "Eliza". Can she fool your friends into thinking she's a human?

Start coding now!

Flags of the World (Python Turtle)

Use the programming language Python and instruct a turtle to draw flags from around the world! How many countries do you know?

Start coding now!

Cyber Live!

A Navy captain is held captive inside his ship. A major landmark has gone dark. And weapons are pointed at Sydney’s busiest sites… It’s all connected, and it’s up to you to free the captain, track down the culprit, and stop them. Students will need to trace clues, solve puzzles, and figure out how to stop a large scale simulated cyber attack before it’s too late.

Start coding now!

Image Magic with Python

Use the programming language Python to make speedy changes to images. Make fun image editing programs and make your own image filter!

Start coding now!

Frozen Fractals (Python Turtle)

Use the programming language Python and instruct a turtle to draw fantastic snowflakes with code! Brrr, is it getting cold in here?

Start coding now!

Frozen Fractals (Blockly Turtle)

Build programs using friendly blocks and instruct a turtle to draw fantastic snowflakes with code! Brrr, is it getting cold in here?

Start coding now!

Virtual Pet (Blockly micro:bit)

Get started with the BBC micro:bit. Use friendly blocks to make a virtual pet that you can feed and play with! No micro:bit required.

Start coding now!

Hydrangea Danger (Blockly Turtle)

This activity is designed to introduce branching. Use the Blockly version of Python and its turtle module to draw and colour hydrangea flowers!

Start coding now!

Emoticon Madness (Python)

Ever wanted to create your own emoticon? Use the programming language Python to explore emoticons and text manipulation.

Start coding now!

Space (Blockly Python)

Use the visual programming language Blockly to investigate space and reach for the stars.

Start coding now!

Disease Epidemic (Python)

Use the programming language Python to model a disease outbreak. Can you solve the curious case of the glowing nose?

Start coding now!

The Dark Tunnel (Python)

Use the programming language Python to create a simple game (or MUD). Can you find your way through the dark tunnel?

Start coding now!