Fairground Ride

Click box on right for Curriculum Links

KS2 Computing POS:

• design and write programs that accomplish specific goals, including controlling or simulating physical systems; solve problems by decomposing them into smaller parts

• use sequence, selection, and repetition in programs; work with variables and various forms of input and output; generate appropriate inputs and predicted outputs to test programs


• pupils should work in a range of relevant contexts [for example, the home, school, leisure, culture, enterprise, industry and the wider environment].

• understand and use electrical systems in their products [for example, series circuits incorporating switches, bulbs, buzzers and motors]

• apply their understanding of computing to program, monitor and control their products.


This project follows on from the Lighthouse project


To program an automated fairground ride.

A popular DT (design technology) project in schools is for children to build a fairground ride that includes some electrical components such as lights, buzzers, and a motor (with a 200:1 gear box attached).

For this task you are going to program a fairground roundabout to bring it to life.

Learning outcome

  • You will be able to use the gPiO interface for input as well as output.
  • You will be able to program an input and output control system.
  • You will understand how to control a motor in a forward and reverse direction.
  • You will understand the need for a fail safe control.

This model needs some thought on the physical construction, but is still relatively easy to build. A basic template for the working mechanism has been provided.

You could just turn the motor on and off – but to make it more realistic (and more fun), add forward and reverse motion, lights and buzzers There should also be a fail safe switch that will stop the ride if something happens to the operator.

This is the fairground ride algorithm for the code we have used:

  • When the start button is pressed:
    • some lights flash
    • a warning buzzer sounds once just before the ride starts to turn
    • repeat 5 times
      • turn for three seconds in one direction
      • turn three seconds in the other direction
    • the buzzer should sound twice to signal the end of the ride
    • if the operator releases the switch the ride will stop.

Adding some suitable music gives the model more of an impact. Click the music player below for a short snippet of the Waltz from Carousel.

If you like this you can download the whole piece from the Code Library > Media Files

Making the Model

i) Glue the motor (and 200: gearbox) onto a short length of wood about 5cm x 5cm x 2cm (see below).

ii) Glue a pulley wheel onto the motor spindle.

iii) Drill a hole through the centre of the wood block just wide enough to take a piece of dowel so that it will turn easily.

iv) Glue another pulley wheel onto the length of dowel so that it sits just above the wood block and is at the same level as the pulley on the motor.

v) Connect the wires from the motor to one of the motor outputs on the end of the gPiO and switch it on. The mechanism should operate as shown in the video below.

Connecting to the gPiO Box

When you are connecting to the model, the red wires from the LEDs and the buzzer must be connected to the red (positive) sockets on the gPiO. The motor must be connected to the motor outputs. If you use the code shown below make these connections.

  • INPUT A – Push Button
  • MOTOR A (On side of gPiO box) – Model motor
  • OUTPUTS 3,4 & 5 – Lights
  • OUTPUT 6 – Buzzer

Scripts & Code

These are the Scratch Scripts and Python Code for this project. All of these are available in the Code Library.


If you use Flowol(TM) in your school you can download this flowchart from the Code Library. Version 4 and above of Flowol can be used with the gPiO Box, so that you can use this flowchart to control physical devices directly.



This is the ScratchGPIO version of this project, you can download this script from the Code Library.



This is the GPIOServer version of this project, you can download this script from the Code Library.



Python Code

For more advanced users we have included a Python version of this activity here and put a copy in the Code Library.

[sourcecode language=”python”]

import time
import RPi.GPIO as gpio
gpio.setup(11,gpio.OUT)#red LED
gpio.setup(12,gpio.OUT)#Yellow LED
gpio.setup(13,gpio.OUT)#green LED

while True:




This project is the last of the beginners videos, you should now have a real feel for what you can do with a gPiO box. There will be other projects on the site that you can experiment with, bear in mind that they are often just design ideas that you can use as a basis for your own projects. Have Fun!