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 Transistor has 3 Pins:
- Collector - This is connected to the 5V rail via the Resistor and LED.
- Base - This is driven via a resistor by the GPIO Pin, as you supply voltage, the transistor turns on.
- Emitter - This we just connect to GND to complete the Circuit.
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).
If you connect your Traffic Light LEDs using this circuit, rather than directly to the GPIO pins you will:
- Get brighter LEDs due to higher voltage and more current.
- Protect the GPIO pins of your device from over-current and so avoid damage
Other than this connection difference, the rest of the project is the same, we can use the same GPIO Pins and the Micro Python code remains unchanged.

