DIY traffic light with PIC microcontroller.
- Automatic cycle of lights.
- Super simple boost converter driven from PIC microcontroller for LEDs supply.
- Easy construction.
- Fun thing to play with.
- Lights speed adjustable by potentiometer
- Powered by AAA or AA batteries.
- Push button for power ON/OFF and manual advance of lights.
This project was inspired by my daughters kindergarten. One day they showed up with some electronic parts including 555 timer and one led for each color and wanted a traffic light for the kids game. I was not happy with that design, and wanted some more power and of cource a PIC microcontroller, so I designed a completely new circuit and printed circuit boards. Forutantely I found out at the time that it is possible to get the PCB-s of 3 different colours just suitable for traffic light. So I managed to come up with very nice circuit, that I am happy with.
PIC microcontroller generates PWM signal for boost converter circuit (Q1;L1;D3). It is mainly constant frequency and constant duty cycle. Software only corrects the duty cycle a little for different lights so that all lights seem equal intencity. The boost converter for leds do not need much output capacitance because LED-s are not sensitive to current fluctuations. Also the output current is limited by inductor current, so all suits very well.
Q1, Q2 and Q3 are used for switching between the lights. Microcontroller again takes care of the timing.
RV1 potentiometer is used for adjusting the lights cycle speed. Microcontroller reads the potentiometer position and adjusts the cycle accordingly.
The latest code uses the state machine approach for easily managing the lights sequence. I actually had to measure the real traffic light changing speed from the video made on the cross section. Interesting thing is most people do not know that for a period of time the red and yellow lights are both on before the red appears! Even those who have driven in the city for years!
PWM signal is generated by the PIC built is PWM module so that is really easy too. Only configure the parameters and go!
The one button is coded as follows:
- Short push (when off) -- Power on. Actually wake up from sleep
- Short push (when on) -- Advance to the next color manually.
- Long push (hold button for little longer) -- Power off. The microcontroller is in sleep during off state. All other things turned off.
Firmware assembler source code here:mainfoor.asm
Compiled hex file for directly programming into PIC16F1824 here:valgusfoor.hex(rename the file -- remove .txt from the end)
And yes the firmware is quite state of the art and largely overkill for so simple application but I had a good time coding and recoding it ;) Eventually I am happy with it!
PCB-s and KIT of parts will hopefully be soon available from my shop. Meanwhile feel free to drop me a letter if interested I still have some extra PCB-s laying around.