Puffin Crossing Project

Introduction

PuffinCrossingThis project combines a number of IT, programming and electronic activities to create a working model of an automated PUFFIN pedestrian crossing.

The project replicates the operation of a Puffin crossing. There are RED-AMBER-GREEN lights for the road traffic and RED-GREEN lights for the pedestrians on the kerbside.

It uses the raspberrry Pi computer, the Piface add on board and some electronic components.

Project Notes

The Puffin crossing dispenses with the flashing phase of the Pelican crossing and adds a sensor that detects pedestrians crossing the road and waits for them to finish crossing before changing the lights. The drawing below shows the traffic light sequence and the process as a flowchart.

 Sequence Flowchart


 Programming

The diagram below shows the code that needs to be entered in Scratch or in Python to make the sequence work correctly. The two sets of code can be downloaded by using the link given in the Resources appendix at the end of this document.

Scratch Code

The scratch code for this project is available here http://scratch.mit.edu/projects/10242490/

For more information on programming in scratch visit scratch.mit.edu

The Scratch version of the code uses the PiFace board connected to a breadboard.

Python Code

The Python version of the code does not use the PiFace board but connects directly to the Raspberry Pi using a ‘Cobbler’ cable connected to a breadboard

 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!?usr/bin/env python
# We need to import some libraries
# We need the time library so that we can make the programme pause for a fixed amount of time
import time
# We need the RPi GPIO libraries to allow us to connect the RPi to other physical devices via the GPIO pins
import RPi.GPIO as GPIO
# Now we need to set up the GPIO pins
# and clear the current set-up so that we can start from scratch
GPIO.cleanup()
# Set the GPIO library to use Raspberry Pi board pin numbers
GPIO.setmode (GPIO.BOARD)

# Setup Pins on the GPIO header to act as outputs & inputs
GPIO.setwarnings(False) # Stops "This channel in use..." error messages
GPIO.setup (11,GPIO.OUT) # ROAD red
GPIO.setup (12,GPIO.OUT) # ROAD amber
GPIO.setup (13,GPIO.OUT) # ROAD green
GPIO.setup (16,GPIO.OUT) # KERB red
GPIO.setup (18,GPIO.OUT) # KERB green
GPIO.setup (22,GPIO.OUT) # BUZZER

GPIO.setup (15,GPIO.IN) # BUTTON
GPIO.setup (7,GPIO.IN) # SENSOR

# Setup Variables
delay=3 # PHASE DURATION: HINT use  1 for testing logic, higher for real Sequence
verbose_mode = False # HINT: set to True for testing

while True:

# Phase 1 - ROAD green - KERB red
    phase =1
    if verbose_mode:
            print 'The phase  is:', phase

    GPIO.output(13,GPIO.HIGH) # Turn on ROAD green
    GPIO.output(16,GPIO.HIGH) # Turn on KERB red

    Button = GPIO.input(15)
    while Button == True:
        Button = GPIO.input(15) # Wait for Button Pressed

# Phase 2 - ROAD amber - KERB red
    phase =2
    if verbose_mode:
            print 'The phase  is:', phase
    GPIO.output (13,GPIO.LOW)
    GPIO.output(12,GPIO.HIGH) # Turn on ROAD amber
    time.sleep(delay) # Wait for a few seconds

# Phase 3 - ROAD red - KERB green
    phase =3
    if verbose_mode:
        print 'The phase  is:', phase
    GPIO.output (12,GPIO.LOW)
    GPIO.output(11,GPIO.HIGH)
    time.sleep(2)
    GPIO.output(16,GPIO.LOW)
    GPIO.output(18,GPIO.HIGH)
    # GPIO.output(22,GPIO.HIGH)
    time.sleep(delay)

    Sensor = GPIO.input(7)
    while Sensor == True:
        Sensor = GPIO.input(7) # Wait for Sensor Low

    GPIO.output (11,GPIO.LOW)
    GPIO.output (18,GPIO.LOW)
    GPIO.output(22,GPIO.LOW)

# Phase 4 - ROAD fl amber - KERB fl green
    phase =4
    if verbose_mode:
        print 'The phase  is:', phase
    count = 0
    while (count < 6):
        GPIO.output(12,GPIO.HIGH)
        GPIO.output(18,GPIO.HIGH)
        time.sleep(.5)
        GPIO.output(12,GPIO.LOW)
        GPIO.output(18,GPIO.LOW)
        time.sleep(.5)
        count = count + 1

Electronics

Electronics

Schematic Diagram

The diagram below shows the schematic diagram of the LED wiring.

There are five each of:

• Transistors – Circles with three connections each

• Light Emitting Diodes (LEDs) – A triangle with a line crossing the apex

• Resistors – Rectangular hollow shapes

The transistors are actually inside the PiFace board so these do not need to be wired in. Notice that the LEDS all connect on one end so only one wire is needed for that part of the wiring. When building a circuit like this it is usual to use a Breadboard.

A breadboard consists of a number of electrical contacts that are connected to each other in groups and set inside a plastic shell. Components are pushed into the breadboard to make experimental and prototype circuits. Using a breadboard means that there is no need to use soldering irons and also it is easy to change the circuit layout.

The drawing on the next page show a breadboard in use for this project
Breadboard

Basic Breadboard Showing some INTERNAL connections

PiFace version Connection Diagram Photograph of Wired System with PiFace

Appendices
Parts List

The parts list below includes items that are available from a variety of suppliers. To make it easier we have included the Maplin part numbers as there is probably a Maplin store near to you.

Raspberry Pi A complete Kit that contains many of the required peripherals to be able to use the Raspberry Pi
Resistors 220 Ohm resistors. You may need different values if you change the LEDs
LEDs Mixed bag of LEDS, contains Red, Yellow and Green LEDs
Breadboard Breadboards come in various sizes. This one can easily support the Pedestrian Crossing Project
Hookup Wire Pack of short lengths of wire in different colours

Note. The PiFace Board is available from Farnell in the UK: uk.farnell.com/raspberry-pi

Resources

The PiFace board uses a modified version of the standard Raspberry Pi image. You can download it from here: pi.cs.man.ac.uk/download

More information on the PiFace board is here: tinyurl.com/pifacedocs

The Scratch & Python code used in the project is available here:

A video showing the sequence working is here:

Raspberry Pi GPIO

 

 

Leave a Reply