From few days I was learning Raspberry Pi. So in this article i have made small traffic light control project using Raspberry Pi B+ Model. This is the four way signal so A,B,C,D are the name of respective ways. And i have also made Circuit schematic for real time Operation of Same. So has divided in two parts.
1)Prototype Circuit Model
2)Real time circuit Schematic
1) Prototype Circuit Model
- Hardware requirement :-
1)Raspberry Pi B+ Model.
2)Bread board.
3)RED, GREEN, YELLOW LED's.
4)Jumper Wires.
5)100 Ohm resistors.
- Schematic:-
In the above image as there are total 12 LED's, 3 for each way Red, Yellow, Green.
100 Ohm Resistor is use to limit the current in the LED to safe value and All the cathode terminal of LED is connected to common ground.
RED light of A is connected to pin no 7
YELLOW light of A is connected to pin no 11
GREEN light of A is connected to pin no 13
RED light of B is connected to pin no 15
YELLOW light of B is connected to pin no 29
GREEN light of B is connected to pin no 31
RED light of C is connected to pin no 33
YELLOW light of C is connected to pin no 35
GREEN light of C is connected to pin no 37
RED light of D is connected to pin no 40
YELLOW light of D is connected to pin no 38
GREEN light of D is connected to pin no 36
- Program from operation is
import RPi.GPIO as GPIO #include GPIO library
import time #include Time library
GPIO.setmode(GPIO.BOARD) #Raspi mode set as board mode
GPIO.setup(7,GPIO.OUT) #making pin number 7 as output pin for RED of 'A' way
GPIO.setup(11,GPIO.OUT) #making pin number 11 as output pin for YELLOW of 'A'
GPIO.setup(13,GPIO.OUT) #making pin number 13 as output pin for GREEN of 'A'
GPIO.setup(15,GPIO.OUT) #making pin number 15 as output pin for RED of 'B'
GPIO.setup(29,GPIO.OUT) #making pin number 29 as output pin for YELLOW of 'B'
GPIO.setup(31,GPIO.OUT) #making pin number 31 as output pin for GREEN of 'B'
GPIO.setup(33,GPIO.OUT) #making pin number 33 as output pin for RED of 'C' way
GPIO.setup(35,GPIO.OUT) #making pin number 35 as output pin for YELLOW of 'C'
GPIO.setup(37,GPIO.OUT) #making pin number 37 as output pin for GREEN of 'C'
GPIO.setup(40,GPIO.OUT) #making pin number 40 as output pin for RED of 'D'
GPIO.setup(38,GPIO.OUT) #making pin number 38 as output pin for YELLOW of 'D'
GPIO.setup(36,GPIO.OUT) #making pin number 36 as output pin for GREEN of 'D'
while 1: #to make while loop infinite
GPIO.output(13,1) #making pin number 13 high
GPIO.output(15,1) #making pin number 15 high
GPIO.output(33,1) #making pin number 33 high
GPIO.output(40,1) #making pin number 40 high
time.sleep(20) #delay of 20 seconds
GPIO.output(11,1) #making pin number 11 high
GPIO.output(29,1) #making pin number 29 high
time.sleep(5) #delay of 5 seconds
GPIO.output(31,1) #making pin number 31 high
GPIO.output(7,1) #making pin number 7 high
GPIO.output(13,0) #making pin number 13 low
GPIO.output(15,0) #making pin number 15 low
GPIO.output(11,0) #making pin number 11 low
GPIO.output(29,0) #making pin number 29 low
time.sleep(20) #delay of 20 seconds
GPIO.output(29,1) #making pin number 29 high
GPIO.output(35,1) #making pin number 35 high
time.sleep(5) #delay of 5 seconds
GPIO.output(15,1) #making pin number 15 high
GPIO.output(37,1) #making pin number 37 high
GPIO.output(33,0) #making pin number 33 low
GPIO.output(35,0) #making pin number 35 low
GPIO.output(29,0) #making pin number 29 low
GPIO.output(31,0) #making pin number 31 low
time.sleep(20) #delay of 20 seconds
GPIO.output(35,1) #making pin number 35 high
GPIO.output(38,1) #making pin number 38 high
time.sleep(5) #delay of 5 seconds
GPIO.output(33,1) #making pin number 33 high
GPIO.output(36,1) #making pin number 36 high
GPIO.output(40,0) #making pin number 40 low
GPIO.output(35,0) #making pin number 35 low
GPIO.output(38,0) #making pin number 38 low
GPIO.output(37,0) #making pin number 37 low
time.sleep(20) #delay of 20 seconds
GPIO.output(38,1) #making pin number 38 high
GPIO.output(11,1) #making pin number 11 high
time.sleep(5) #delay of 5 seconds
GPIO.output(40,1) #making pin number 40 high
GPIO.output(38,0) #making pin number 38 low
GPIO.output(11,0) #making pin number 11 low
GPIO.output(7,0) #making pin number 7 low
GPIO.output(36,0) #making pin number 36 low
2)Real time circuit schematic.
- Hardware requirement :-
1) Raspberry Pi B+ Model.
2)MOC3021 Optocoupler.
3)BT139 Triac.
4)Resistors.
5)Bulbs.
In the above schematic there is optocoupler MOC3021 used for the isolation of Raspberry Pi from Main AC supply and Triac BT139 is the used as switch to turn ON and OFF different colour bulbs.