In some situations, in your designs with Arduino and microcontrollers, you can use a shift register like 74HC595 to directly trigger LED, LED array and displays, but if you check the datasheet, you will see that you need to be careful with the maximum current in each output and also with the total current do not damage the device.
These are important information that we do not normally care about in our projects at home (including myself) and I would like to explain this problem to you and then you can go ahead applying more reliable and robust solutions!
This overview will help you understand differences and design alternatives using the 74HC595, ULN2803, UDN2981 and transistors.
I hope you enjoy it and that it will be useful.
This is a formal description of 74HC595 that you can find on the datasheet:
"The 74HC595 devices contain an 8-bit, serial-in, parallel-out that feeds an 8-bit D-type storage register."
This device is very popular for applications on LED arrays, for example, but my intention here is to just discuss your power consumption limit and not all of its functionality.
Let's see the specifications shown in the datasheet related to Maximum Ratings:
- Io (Continuous Output Current) = 35 mA
- Io (Continuous Current through Vcc or GND) = 70 mA
- Output Drive at 5V = 6 mA
What this means:
- If you have 2 outputs with 35 mA of charge, forget to use the remaining 6 outputs because you are already using the limit of 70 mA of the device.
- The maximum for each port is 8.75 mA and the recommendation at 5V is 6 mA.
Within these conditions, if you apply an LED to each output port, you'd probably go beyond these limits. In this case, a standard red LED has a consumption of 10 mA, which means 80 mA in total when 8 of them are used simultaneously in your design.
Of course, you can put a resistor to limit in 6 mA, but certainly you will not like the result of the brightness of each LED. Okay, now you're thinking you already have seen a dozen projects that just use the shift register to directly drive some component.
I confess I did this in some situations just to maintain a more compact design, with fewer components and lower costs. Maybe the components have survived due to low duty cycle or high flashing frequency.
But with the equipment, you should continue to work all day for a long time. I'm not sure if it will be robust and reliable enough in terms of its useful life. For these conditions, you need to use some interface device that can work with larger currents, as we will see in the next steps.
The ULN2803 is an array of Darlington transistors that can be charged 500 mA in a single output with voltage up to 50V. There are many applications for it, such as solenoids, relays, LED display drivers, and light bulbs, as well as inductive loads such as small motors.
Note that in the pin configuration you only find the GND but no Vs pin. At first glance, it is strange because we hope to see both pins! In fact, you do not need any specific Vs pin because the ULN2803 is used as a drain for the current.
When you apply a signal to an input port, the corresponding output port will be able to drain the current from a positive source.
You can see an example of this in the schematic shown in the attached image. Note that the LEDs are connected in a common anode configuration and the ULN2803 is used to drain the current at its output ports according to the input signals driven by the 74HC595.
In this case, you can drain up to 500 mA at each output port and keep the 74HC595 in safe working condition.
The UDN2981 is an 8-channel source drivers.
It is similar to the ULN2803 but with an opposite function and you can use it as an interface between 74HC595 and a device that needs a higher current supply for the job. Typical applications include: relays, solenoids, lamps, step motors, servos and LEDs.
UDN2981 can also work with 500 mA (Output Source Current Capacity) up to 80V. Note that in this case you have the Vs and GND pins because you must be connected to the power supply. Now, when you apply a signal to an input port, the corresponding output port will be able to provide a higher current to the next device.
You can see an example in the schematic shown in the attached image. Note that the LEDs are connected in the common cathode configuration and the UDN2981 is used to supply the current at its output ports according to the input signals driven by the 74HC595. Again, in this case, you can drain a larger current at the output ports and keep the 74HC595 in safe working condition.
In the datasheet, you can also find interesting information about the duty cycle versus the output current.
The attached chart shows the number of outputs simultaneously, and if you consider a 50% duty cycle with 8 outputs, the maximum recommended output current is about 220 mA. In the same configuration, if the duty cycle is increased to 100%, the recommended output current will be 120 mA. And, of course, the current can be higher if you decrease the number of outgoing ports that are being used.
This shows us how important it is to consider the number of outputs you run simultaneously, the duty cycle you are using in your application (e.g., the LED refresh rate) and the maximum current supported by the devices.
The amplifier PNP silicon bipolar transistor BC327 can work with collector currents up to 800 mA (maximum ratings) and up to 45V. In some applications this transistor can be used as switch for higher currents, e.g., LED actuation, in place of UDN2981.
Note: BC327 is shown here as an example, but of course there are many other equivalent transistors for this type of application.
But there are some pros and cons:
- Low cost
- Availability (very easy to find anywhere)
- It needs more space to be mounted on the board
- More additional components (resistors must be used)
To work properly as a switch, the BC327 transistor must be in the saturation region and you can calculate the resistor on the base as follows:
- hFE = Ic / Ib = 100 (minimum gain value according to datasheet of BC327)
- Vbe = 1.2 Volts
- Rb = (Vin - Vbe) / Ib = (Vin - Vbe) / (Ic / 100)
For example, if you need to direct a current of 160 mA to the collector and the gain of the transistor is 100, this means that the current required at the base is only 1.6 mA.
Rb = (5 - 1.2) / 0.0016 = 2.4 K (Ohms)
Note: The hFE gain of the transistors produced can vary within a specified range according to the datasheet and due this you can test some resistors with values close to the calculated one.
This presentation shows some ways to improve the robustness and reliability of some devices by preventing them from working beyond their design limits.
Personally, my preferred design is with common anode using ULN2803 because it is very simple, easy to find it in different markets and also has a lower cost comparison with UDN2981.
In the following photos, you see my project of Multiple LED Display Module where I applied all these concepts.