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.
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:
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
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.
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.
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.
import time import RPi.GPIO as gpio gpio.setmode(gpio.BOARD) gpio.setup(11,gpio.OUT)#red LED gpio.setup(12,gpio.OUT)#Yellow LED gpio.setup(13,gpio.OUT)#green LED while True: gpio.output(11,gpio.LOW) gpio.output(12,gpio.LOW) gpio.output(13,gpio.LOW) gpio.output(13,gpio.HIGH) time.sleep(2) gpio.output(12,gpio.HIGH) gpio.output(13,gpio.LOW) time.sleep(2) gpio.output(12,gpio.LOW) gpio.output(11,gpio.HIGH) time.sleep(2) gpio.output(12,gpio.HIGH) time.sleep(2)
The short video below shows a variety of Fairground Rides that can be controlled with a gPiO box.