Image of model lighthouse

Lighthouse

By Trevor Olsson, 12/05/2016

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

KS2 D&T POS:

• 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.


Progression

This project follows on from the Traffic Lights project
lighthouse_labels

Challenge

To control an automatic lighthouse.

For safety reasons every lighthouse has a signal that is distinctive and individual e.g. the lighthouse at Flamborough Head in Yorkshire flashes four times, waits 15 seconds and then flashes again. This signal is called the lighthouse character and you can see them all listed on the Trinity House Website. An activity for children would be to visit the Trinity House site, find the lighthouse nearest to them and discover the signal their lighthouse uses. They could then create a programme that simulates that lighthouse.

Learning objectives

You will be able to:

  • use the gPiO interface for input as well as output.
  • program an input and output control system.
  • understand how an LDR can be used as a light sensor.

 

Design brief

To create a lighthouse control program.

The control program must:

  • turn on the main light beam when it is dark and turn it off when it is daylight
  • make the main beam flash to produce a unique signal
  • turn on the fog horn when it is foggy and turn it off when it is not foggy
  • make the fog horn produce a unique sequence of sound

You will need to consider the range of sensors and select the most suitable input device for the job:

  • LDR (light sensor)
  • for sensor (in fact we do not have one so you can use a simple push switch for now)

You will need a processing device (computer), an interface to connect the components to the computer and a power supply.

  • Raspberry Pi
  • gPiO interface and power supply
You will need to consider the range of output devices to warn ships that they are approaching danger:
  • filament lamp
  • white LED
  • buzzer

You will need to select a programming language that can communicate with the input output devices:

  • Scratch
  • Python
Main light:
  • input, an LDR connected to a gPiO interface.
  • 6 volt output connected to a bright, white, LED.
Fog horn:
  • input, a push switch connected to a gPiO interface.
  • 6 volt output connected to a buzzer.

Making the model

The lighthouse is quite an easy model to make and all of the electrical components can be built into the model as it is made or they can be added afterwards.The gallery below shows a model made from a kitchen roll holder, an alternative is to use a Pringles tube. The LDR can be difficult to find so we’ve added it to our ‘Hard to Find’ Pinterest board.

You can also watch the video

Connecting to the gPiO Box

  • Design the circuits that will be built into your lighthouse model and use connection blocks to connect your model to the gPiO interface.
  • Bring all of the wires into the eight connection blocks
  • Use additional pieces of wire to connect the blocks to the inputs and outputs on the gPiO.

Scripts & Code

These are the Scratch Scripts and Python Code for this project. All of these are available in the Code Library. The scripts follow the flowchart, you can follow these scripts or create your own for a different lighthouse.

When using Scratch, pin connection numbers are dependent on whether you are using ScratchGPIO or GPIOServer. Use this document to determine the correct pins to use.

Flowchart

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. For more information on using Flowol with the gPiO please contact us.

Lighthouse-Flow1

There is also another version of this flowchart in the Code Library, to keep things simple we haven’t shown it here. The alternate version utilises Flowol’s ability to use subroutines to create more elegant code.

ScratchGPIO

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

SG_Lighthouse

GPIOServer

This is the GPIOServer version of this project, you can download this script from the Code Library.
GS_Lighthouse_scriptThe script shown will work, and appears simple to use.However, in practice the need to initially declare ports as Inputs or Outputs can be difficult for children to grasp and ‘gets in the way’ of actually producing the project code. A better solution is to create a template script that is hidden from the children and does the heavy lifting. This technique is fully documented here and the associated scripts are in 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.

</p>
<p>import time<br />
import RPi.GPIO as gpio<br />
gpio.setmode(gpio.BOARD)<br />
gpio.setup(11,gpio.OUT)#red LED<br />
gpio.setup(12,gpio.OUT)#Yellow LED<br />
gpio.setup(13,gpio.OUT)#green LED</p>
<p>while True:</p>
<p> gpio.output(11,gpio.LOW)<br />
gpio.output(12,gpio.LOW)<br />
gpio.output(13,gpio.LOW)<br />
gpio.output(13,gpio.HIGH)<br />
time.sleep(2)<br />
gpio.output(12,gpio.HIGH)<br />
gpio.output(13,gpio.LOW)<br />
time.sleep(2)<br />
gpio.output(12,gpio.LOW)<br />
gpio.output(11,gpio.HIGH)<br />
time.sleep(2)<br />
gpio.output(12,gpio.HIGH)<br />
time.sleep(2)</p>
<p>

 

Info

The suggested next project is Fairground ride