Using a raspberry pi and almost pure bash script, not python
The products listed here are mostly ref links from Amazon. If you find the info on this page useful, do me a favour and use these links for purchase.
The idea is to build 'half' of a normal traffic light that you might find right in front of your house. The traffic lights will have 3 colors (red, yellow and green) while the pedestrian lights will only have red and green. There will be a button for pedestrians to request a red light phase for traffic, enabling them to cross. Because it could be doubled to resemble a real setup by just 'mirroring LEDs and resistors through appropriate wiring' anyways, we'll only build one set of traffic lights plus one button.
The end product will look a bit like this:
You can see 5 LEDs (2 red, 1 yellow, 2 green), 5×330 Ohm resistors, one button and a lot of jumper wires, which will be explained later on. Note that setting up the raspberry pi is beyond the scope of this tutorial, only the packages needed for this very thing are mentioned.
Get the necessary parts ready. These are:
# apt-get install wiringpi