Electronic – BJT, resistor, and diode work but ULN2803 does not

bjtdrivermicrocontrollerrelay

I am trying to control some 5V relays with a mC. At first I went with using a BJT, a 470 ohm resistor, and a 1N4004 diode to control each one of the relays. Each mC output pin is 5V, 40ma. This setup worked well.

I wanted to see if I could do better so I am trying out the ULN2803an driver chip. However, this sort of works. It runs for 5 seconds then the mC freeze or starts controlling the output pins incorrectly.

pin 9 goes to ground, pin 18 goes to 5V

The yellow wires connect directly to the output pins of the mC. Pin 9 of ULN2803an goes to ground, pin 10 of ULN2803an goes to +5V.

Do I need resistor between the mC and the ULN2803an chip? Is the ULN2803 hooked up correctly? Is there something else I am missing? Everything works with the BJT, resistor, and diode combo. I thought the ULN2803an would be exactly the same. Any help in figuring it out would be appreciated.

Best Answer

From the photo it seems that you connected the 2803 correctly, but the path from the relay coils back through the 2803's flyback diodes is a bit long. To check whether this is your problem you could try either wit a separate 5V supply for the relays, or with flyback diodes directly across the relay coils.

A long line is effectively a (small) resistor in series with a (small) inductor. (Actually, there is also a capacitor, and if you need to be precise there is a large string of resistors, inductors and capacitors). A lot of times you can ignore these, but in this case, there can be large current spikes that result in voltage spikes, which can affect your microcontroller.

If you have the chance, use 12V relays, powered from a 12V wall-wart, and use a 7805 or the like to power your microcontroller.