Robots and algorithms at Stockton on the Forest

Great day at Stockton on the Forest primary. Started the day with an algorithm assembly.

How would you sort 10 children by height? We did a bubble sort algorithm – followed by using an algorithm to find a number a child had thought of.

Then a fun day coding robots. The children wrote text codes using Arduino to make their robots perform sequences. Then we demonstrated them at the end of the day in assembly.

A search algorithm you can act out in primary school

Imagine you’ve got100 children all lined up. You want to know if someone is called Sarah and what position they are.

There’s a few ways you can do this – what you can’t do is ask anyone.

1)Get them in a line. Ask each child their name.

IF Name = Sarah, then check position and say that Sarah is at that position. Keep going until you reach the end.


2) Sort the children into alphabetical order (IMPORTANT)

Find the middle child. IF their name is before Sarah, then get rid of the first half. Or the second half if after Sarah.

Then find the middle child again. Repeat the process as above.

By halving, you will find the Sarah.

This can be adapted into a guessing game.

Imagine a number between 0 – 100. Computer guess 50. If Higher, guesses 75 etc.

Worked example.

Number is 57

Guess 50 (HIGHER) Range left 51 – 100

Guess 75 (LOWER) Range left 51 – 74

Guess 63 (LOWER) Range left 51 – 62

Guess 56 (HIGHER) Range left 57 – 62

Guess 59 (LOWER) Range left  57 – 59

Guess 58 (LOWER) Range left 57 – 57

Guess 57. CORRECT

This is called a DIVIDE and CONQUER algorithm. It’s designed to cut down the work. An alternative could be to go through from 0 – 100 and get the answer HIGHER or LOWER. It would work but it would be slow.

You could do RANDOM guesses.

Front door bell using Tiny 85 Atmel chip

The ATMEL Tiny85 chip is a very versatile little microcontroller chip that can be programmed via the Arduino programming environment and is relatively easy to use.

For the door bell, it’s a simple switch. The program reads the INPUT on Pin 0 and if it changes, then it triggers a little music program.

There’s a red LED always on to show that there’s power and the system is working. The Tiny85 has an internal pull up resistor that can be enabled.


Tiny85 layout

Continue reading

Teaching variables using Sonic Pi in primary classroom coding

Variables are very powerful. They are used in Scratch and can easily be taught through drama.


VARIABLE Points = 0

VARIABLE Game Over = false

IF you get touched, you lose a life

IF you score, you get 1 point





This demonstrates how variables can be used in music using Sonic Pi.

The power of variables – making music easy in KS2 coding

Variables are really useful – as the name suggests, they can vary. When you make a simple change in the variable, the result can feed through a program rather than you having to type it in everywhere.

So for music, we have developed a function. In functions, you can “send” details to a function and it will carry it out for you. It saves you having to keep typing the function again and again.

Continue reading

Sorting algorithms in Key Stage 2

Difficult to program using Scratch (but not impossible). But fun to act out and to reinforce the idea of how an algorithm helps solve problems.

Imagine you’ve got items that need sorting. They are in a random order. How can you sort them out and know that every item is in the right place? As a human, it’s intuitive. You can see that people are in the right height order or age order. You just sort them without thinking. Well, you are thinking but you “just know” how to do it.

How would a computer do it?

One way is the BUBBLE sorting algorithm.

Continue reading