Home Introduction Contact Search Sitemap Raspberry Pi

Pi Traffic Lights
 
Home
Up
Pi Traffic Lights
Pi I2C Traffic Lights
Pi Simple Radio
Raspberry Pi bootcamp
Pi Motor Relay

 


Comments ?
Email:


 

 

 

bulletRaspberry PI Traffic Lights

  Below are the instructions to make this traffic light Traffic Light sequencer using the Raspberry PI. I have used a Ciseco "Slice of PI" prototyping board but any prototyping board can be used.
 
Raspberry PI Traffic Lights project manual
Click the Adobe reader logo on the left to download the project manual.

 

 
 

Features

bulletRaspberry PI based
bulletControlled by a Python application

 

 
.

horizontal rule


 
bulletParts  List
Part Description Supplier
Raspberry PI Raspberry PI credit card computer Farnell or RS
4 Gigabyte SD card For the operating system Any computer or photographic store
Three 5mm LEDs One red, one green and one orange/yellow led Tandy or Farnell Element 14
Ciseco prototype board "Ciseco "Slice of PI" Ciseco
Three  220 Ohm resistors In line resistors for LED Tandy or Farnell Element 14
One 1K resistor For GPIO input switch Tandy or Farnell Element 14
Push to make switch Either PCB mount or wired Tandy or Farnell Element 14
Single strand wire Various colours Any electronics shop

 

bulletWiring
Physical pin GPIO etc. Component wiring
1 3v3 +3.3v  supply
6 Gnd Ground 0 Volts
11 GP17 Red Led --> 220 Ohm --> Gnd (Pin 6)
16 GP23 Orange Led --> 220 Ohm  -->Gnd (Pin 6)
7 GP4 Green Led --> 220 Ohm --> Gnd (Pin 6)
22 GP25 Switch -->  1K --> 3v3 (Pin 1 GPIO)

 

bulletDownload all Traffic Light Source Code
 
Download Dowlnoad complete source. Copy to the raspberry pi /home/pi directory and use the following command to extract it:

$ sudo tar -xvf  traffic_led.tar.gz
$ cd traffic_led

or use the following command to get the source direct to the Raspberry PI.

$ wget http://www.bobrathbone.com/raspberrypi/source/traffic_led.tar.gz
 

bulletPedestrian Traffic Light Python Code
# First we need to import the libraries that
# we need
# Import the time library so that we can make
# the program pause for a fixed amount of time
import time
# Import the Raspberry Pi GPIO libraries that
# allow us to connect the Raspberry Pi to
# other physical devices via the General
# Purpose Input-Output (GPIO) pins
import RPi.GPIO as GPIO
# Now we need to set-up the General Purpose
# Input-Ouput (GPIO) pins

# Set up the GPIO library to use Raspberry Pi
# board pin numbers
GPIO.setmode(GPIO.BOARD)
# Set up the pin numbers we are using for each LED
RED=11
AMBER=16
GREEN=7

# Define the pin for the switch
SWITCH=22

# Set Pin 11, 16 and 7 on the GPIO header to act as an output
GPIO.setup(RED,GPIO.OUT)
GPIO.setup(AMBER,GPIO.OUT)
GPIO.setup(GREEN,GPIO.OUT)

# Set up pin 22 (SWITCH) to act as an input
GPIO.setup(SWITCH,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)

# This loop runs forever and flashes the LED
while True:
    # Turn on the green LED
    GPIO.output(GREEN,GPIO.HIGH)
    print "Green"
    ButtonPressed = False

    # Wait until a pedestrian presses the switch
    print "Press button"
    while not ButtonPressed:
        # Wait for 2 seconds
        time.sleep(1)
        ButtonPressed = GPIO.input(SWITCH)

    print "Button pressed"
    # Turn off the green LED
    GPIO.output(GREEN,GPIO.LOW)
    # Turn on the amber LED
    GPIO.output(AMBER,GPIO.HIGH)
    print "Amber"
    # Wait for 2 seconds
    time.sleep(2)
    GPIO.output(AMBER,GPIO.LOW)
    # Turn on the red LED
    GPIO.output(RED,GPIO.HIGH)
    print "Red"
    # Wait for 4 seconds
    time.sleep(4)
    # Turn off the red LED
    GPIO.output(RED,GPIO.LOW)

    # Now flash the amber light
    count = 5
    while count > 0:
        # Turn on the amber LED
        print "Flash amber"
        GPIO.output(AMBER,GPIO.HIGH)
        time.sleep(1)
        # Turn off the amber LED
        GPIO.output(AMBER,GPIO.LOW)
        time.sleep(1)
        count = count - 1

							
bulletRunning the Pedestrian Traffic Lights program
  $ sudo python PedestrianCrossing.py
  To stop press Control-C

 

 

 

Next
Copyright 2004 Bob Rathbone. All rights reserved