4
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Wouter van Ooijen Jul 28 '12 at 10:17
  • \$\begingroup\$ Wow, I think this solved the problem. Why do the long connections matter? You should put it in the answer section. \$\endgroup\$ – Alexis K Jul 28 '12 at 17:36
  • \$\begingroup\$ done. Which of the two suggestions did you use? \$\endgroup\$ – Wouter van Ooijen Jul 28 '12 at 19:27
  • \$\begingroup\$ shortening the wires fixed it :) I tried rebuilding it a few times previously, but when I tried shorter wires it worked \$\endgroup\$ – Alexis K Jul 28 '12 at 20:22
4
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ What do you gain from using 12V relays instead of 5V? \$\endgroup\$ – Dean Jul 28 '12 at 23:44
  • \$\begingroup\$ The 'same' relais for 12V uses ~ 1/4 of the current, and the spikes will be at the 12V supply, with the 7805 to keep them from the 5V supply. \$\endgroup\$ – Wouter van Ooijen Jul 29 '12 at 7:00
4
\$\begingroup\$

It sounds like you have your ULN2803 wired up incorrectly.

Here is the pinout from the datasheet:

ULN2803

And here is an individual darlington from the IC:

ULN2803 darlington

You can see there is no Vcc pin - this is because the outputs are open collector. This means you connect your load (relay coil) in between the output and Vcc. This is just the same as you would have done with your BJT setup.

You can use a diode to protect against inductive kickback as with the single transistor, but the ULN2803 has integrated diodes for this purpose which you can use instead. The diodes anodes are connected to each output, and the COM pin is the common cathode connection for these diodes (so you can connect this to the Vcc to put the diode across the relay coil)

Effectively each output should look something like this when setup correctly:

ULN2803 connections

The input can be driven from the micro output directly (the micro would be where the DS89C4x0 is in the diagram) or use an open drain with pullup resistor as in the circuit above. Notice how the COM pin is connected to +5V to put the internal diode across the relay coil.

EDIT - I notice you have edited your question to change the +5V from pin 18 to pin 10 - I assume this was a typo and it was like this to start with.
In this case, and judging from the picture it does appear that things are wired correctly as Russell mentions.
It's hard to know what might be causing your issue without more data - what do you mean when you say it runs for 5 seconds? What is it doing during this time? How often are the relays switching? What are they switching? Does whatever is being switched share power lines with the micro? If you have a scope, then posting a capture of the ULN2803 outputs and the +5V line would probably help.

\$\endgroup\$
  • \$\begingroup\$ I did edit the question. I said that pin 18 was tied to VCC but it was actually pin 18. The relays are switching once every second. I programmed the mC to cycle the relays. The problem seems to be caused between when all the relays go on and all the relays go off. Currently, the relays are not switching anything. \$\endgroup\$ – Alexis K Jul 28 '12 at 17:30
  • \$\begingroup\$ You mean pin 10? It sounds like you may still have a kickback problem (or possibly your power supply is not capable of supplying enough current) Try adding some external diodes directly across the relay coils, and have a look at your power supply. Do you have a scope? \$\endgroup\$ – Oli Glaser Jul 28 '12 at 17:42
  • \$\begingroup\$ opps! Yes pin 10... :/ If it is a power supply problem why would it work with the BJTs but not with the ULN2803? I don't have a scope yet but I can look into getting one. \$\endgroup\$ – Alexis K Jul 28 '12 at 18:21
  • \$\begingroup\$ If it's the same power supply and you are switching the relays exactly as before then it should be no different. I didn't know it was exactly the same setup (i.e. number of relays, same supply, same switching) A scope should easily pinpoint the problem. \$\endgroup\$ – Oli Glaser Jul 28 '12 at 18:34
  • \$\begingroup\$ Thanks. When I get the scope, should I look at the power supply? \$\endgroup\$ – Alexis K Jul 28 '12 at 19:07
1
\$\begingroup\$

Your photo looks correct.
Ensure all breadboard connections are making contact OK.

Try reverse diodes directly across the relay coils.

Connect +ve lead going to top bus and then to pin 10 directly to pin 10
(and or check pin 10 with meter to ensure it is high.

A ground lead to 2803 outputs should operate relays
(can do as-is with no harm to IC.)

A + input to 2803 inputs should operate relays - disconnect uC first.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the help. I tried the reverse diode across the relays but the same problem seemed to be happening. Then I tried the shorter wires and it works. \$\endgroup\$ – Alexis K Jul 28 '12 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.