The Maker Cupboard

- Digital Making - Raspberry Pi Projects - 3D printing - Educational Resources -

Second Pi GPIO project - traffic lights

Philip’s second GPIO project using the Raspberry Pi

After the success of our first project we wanted to try building the traffic lights detailed on the OCR resource sheet
here

After helping Philip solder the components onto a prototype circuit board we connected it up to the GPIO breakout board.

I showed Philip how to write the code to make one of the lights flash on and off. He was then challenged to find a way of making the three LEDs show the correct traffic light sequence.




GPIO-project21

GPIO-project22

GPIO-project23

GPIO-project24

In a similar way to the first project I was really pleased with the determination Philip showed in writing this simple piece of code.

import time
import RPi.GPIO as GPIO

GPIO.cleanup()

GPIO.setmode(GPIO.BOARD)
GPIO.setup(3,GPIO.OUT)
GPIO.setup(5,GPIO.OUT)
GPIO.setup(7,GPIO.OUT)

GPIO.setwarnings(False)

GPIO.output(7,GPIO.HIGH)
time.sleep(5)
GPIO.output(5,GPIO.HIGH)
time.sleep(2)
GPIO.output(7,GPIO.LOW)
GPIO.output(5,GPIO.LOW)
GPIO.output(3,GPIO.HIGH)
time.sleep(10)
GPIO.output(3,GPIO.LOW)
GPIO.output(5,GPIO.HIGH)
time.sleep(2)
GPIO.output(5,GPIO.LOW)
GPIO.output(7,GPIO.HIGH)
time.sleep(5)

GPIO.output(3,GPIO.LOW)
GPIO.output(5,GPIO.LOW)
GPIO.output(7,GPIO.LOW)






blog comments powered by Disqus