Skip to content
This repository has been archived by the owner on Feb 4, 2019. It is now read-only.


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

This is an archived resource. The repo will remain available but the resource will no longer be maintained or updated. Some or all parts of the resource may no longer work. To see our latest resources, please visit

Raspberry Pi Sorting Hat

Sorting children into houses can be time-consuming, but with magic Hogwarts were able to sort their yearly intake into houses really easily. Let's replace the magic with some code to achieve the same result!

In this lesson, students will create a Raspberry Pi-powered Harry Potter-style Sorting Hat, using the button on a Pibrella add-on board.

It is assumed that students have prior knowledge of the programming concepts of loops, conditionals and functions in Python. Alternatively, the lesson can also be completed using Scratch.

Students will learn

  • How to create a random group generator based on the Harry Potter Sorting Hat.
  • How to use functions, variables, randomisation, conditionals, and loops.

Computing program of study met


  • Design, write and debug programs that accomplish specific goals; solve problems by breaking them into smaller parts.
  • Select, use and combine a variety of software on a range of digital devices to design and create a range of programs.
  • Use sequence, selection and repetition in programs; work with variables and various forms of input and output.
  • Use logical reasoning to explain how some simple algorithms work; detect and correct errors in algorithms and programs.


  • Use two or more programming languages, at least one of which is textual, to solve a variety of computational problems.


For the majority of the lesson, it is suggested that work is carried out by students on a Raspberry Pi in pairs or a small group. Each pair or group should have access to the standard equipment described below:

  • A Raspberry Pi
  • The latest NOOBS SD card with Raspbian installed
  • A keyboard and mouse connected to the Raspberry Pi
  • A monitor connected to the Raspberry Pi
  • A Pibrella
  • 1 x speakers or headphones
  • Hat

Lesson Plan


Unless otherwise specified, everything in this repository is covered by the following licence:

Creative Commons Licence

Sorting Hat Lesson by Raspberry Pi Certified Educator Simon Johnson and the Raspberry Pi Foundation is licenced under a Creative Commons Attribution 4.0 International License.

Based on a work at &


In this lesson, students will create a Raspberry Pi-powered Harry Potter style sorting hat. Students will also learn how to connect a Pibrella and program it to control the sorting hat







No releases published


No packages published