This is an old revision of the document!
Updated Traffic Lights Using Transistors for Improved LED Brightness
Introduction
In our first attempt at doing the Traffic Lights, we are getting our supply for the LEDs from the GPIO pins, there are two issues with doing this:
The GPIO Pins only seem to supply around 12mA. There is a way to force more, but you meed to use C++
the GPIO Voltage is only 3.3v
What we want to do is to drive the LEDs from the same 5V rail that is powering the Pico (or whatever board you are using). To turn on the LEDs (and protect the GPIO pins from over-current) we can use some Transistors. Transistors are generally associated with amplifier circuits, but you can use them as a simple switch.
See below for a diagram of what we want to achieve.
Below is a view in a more circuit diagram format.
This is just the Red LED circuit, the Amber and Green are identical except for the LED Colour and they come from different GPIO Pins.
The amount of current that each LED gets is control by Ohms Law. So the current limiting resistor is calculated using the Voltage (5v) and the required current (20mA).
The Resistance (R) is the Voltage (V) divided by Current (A) so R=V/I
So 5V divided by 20mA (0.2) = 25 (Ohms).

