Page 1 of 1

### art project with a traffic light

Posted: Mon Jun 17, 2019 6:58 am
Hello,

For an art project I want to control a traffic light with a raspberry Pi (it’s on a remote site, so both powered with batteries).

I am not a noob with electronics but I am a noob with Raspberry Pi and Python.

I have three questions, which I hope at least one I can get help with.

Question 1: how to program the Pi, so the light functions like in a standard traffic situation(green-orange-red) in a continous loop.

Question 2: how to program the Pi, so the light reacts on a proximity sensor (PIR) and performs a predetermined sequence of light flashes.

Question 3: the lamps are changed with led matrixes, how to program the Pi, so the light reacts on a proximity sensor (PIR), and the traffic light show a predetermined list of words.

If I could get any guidance, I would be very grateful

### Re: art project with a traffic light

Posted: Mon Jun 17, 2019 9:47 am
As a starting point why not take a look at the physical computing lessons on the raspberry pi site it includes making traffic lights using LED's as one of the lessons.

https://projects.raspberrypi.org/en/pro ... mputing/11

then I suggest you do some searching on the web you will find lots of examples of traffic lights controlled by a pi.

### Re: art project with a traffic light

Posted: Mon Jun 17, 2019 11:27 am
This may get you started.
viewtopic.php?t=223659

Change the buttons to pirs, they may need inverting

try this...

Code: Select all

``````from gpiozero import LED
from gpiozero import Button
from time import sleep

red1     = LED(23) # RED set 1
amber1   = LED(24) # AMBER set 1
green1   = LED(25) # GREEN set 1
red2     = LED(5)  # RED set 2
amber2   = LED(6)  # AMBER set 2
green2   = LED(13) # GREEN set 2
p_red1   = LED(8)  # pedestrian RED (DON'T WALK) light, set 1
p_green1 = LED(27) # pedestrian GREEN (WALK) light, set 1
p_red2   = LED(19) # pedestrian RED (DON'T WALK)light, set 2
p_green2 = LED(26) # pedestrian GREEN (WALK) light, set 1
p_set1   = LED(12) # Pedestrian WAIT LED 1, acknowledges pir detection
p_set2   = LED(22) # Pedestrian WAIT LED 2, acknowledges pir detection
PIR1 = Button( 7,pull_up = False,bounce_time= None)
PIR2 = Button(16,pull_up = False,bounce_time= None)
# initialise
red2.on()
amber2.off()
green2.off()
red1.on()
amber1.off()
green1.off()
p_red1.on()
p_red2.on()
p_green1.off()
p_green2.off()
p_set1.off()
p_set2.off()

def Light_Sequence(red,amber,green):
amber.on()
sleep(2)
red.off()
amber.off()
green.on()
sleep(10)
green.off()
amber.on()
sleep(2)
amber.off()
red.on()
sleep(1)

def PED_PIR(x): # pedestrian PIR detected
global PED
PED = 1
p_set1.on() # WAIT LED 1
p_set2.on() # WAIT LED 2

def PED_Crossing():
p_set1.off()
p_set2.off()
p_green1.on()
p_green2.on()
p_red1.off()
p_red2.off()
sleep(3)
for led in range (0, 10):
p_green1.off()
p_green2.off()
sleep(.1)
p_green1.on()
p_green2.on()
sleep(.1)
p_green1.off()
p_green2.off()
p_red1.on()
p_red2.on()
sleep(1)

x = 0
PED = 0
PIR1.when_pressed = PED_PIR
PIR2.when_pressed = PED_PIR

while True:
# traffic lights set 1 sequence
Light_Sequence(red1,amber1,green1)
# pedestrian crossing,if either button has been pressed
if PED == 1:
PED_Crossing()
PED = 0
# traffic lights set 2 sequence
Light_Sequence(red2,amber2,green2)
# pedestrian crossing,if either button has been pressed
if PED == 1:
PED_Crossing()
PED = 0``````

### Re: art project with a traffic light

Posted: Mon Jun 17, 2019 5:01 pm
“I am not an electronics noob, but I am a PI noob “

First the Pi is not plug & play, A start on
Learning some basic electronics is your
First move. Script / and programming is
Only useful if it as something to do and
Control, Controlling traffic light comes
Under understanding Combinational Logic
Down load a Combination logic truth table,
Then You will have some idea what you
are doing, Copying a circuit is ok if it works
first time, If it don’t then you are in TROUBLE

Regards BoyOh

### Re: art project with a traffic light

Posted: Mon Jun 17, 2019 6:43 pm
thanks pcmanbob and Gordon77 for the help and hints,

I had a look and I think it can take me where I wantto be in this short amount of time.

@BoyOh: I hear what you are saying, and although learning the basics of PI and Python before jumping into this bath is the preferred way, I do not have the time, I am asking this question to fulfill my art project I have no desire in becoming a skilled python programmer. But again, thanks for your advice

greetings

thomas