4 x 5V relays + ULN2803 + 74HC259 - Can't engage all four coils

I'm trying to engage the coils of more than 2 or 3 relays at the same time. This is the schematic I'm using when breadboarding:

EDIT: I'm using OMRON G5V-2 relays, which have a coil current of 100mA.

When I engage them individually, you hear each coil click. However, if I engage them one by one (additively), you don't hear any coil clicks for the 3rd or 4th.

My EE knowledge is lacking, but I assume this is a power/current issue. I did try using an LM7805 (TO-220 package), but that didn't seem to help.

AddressableLatch.cpp (taken/modified from AddressableLatch/AddressableLatch.cpp at master · brunnels/AddressableLatch · GitHub):

#include "AddressableLatch.h"

const uint8_t AddressableLatch::_digitLatchMap[8] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7 };

AddressableLatch::AddressableLatch() {
	pinMode(HC259_LE, OUTPUT);
	pinMode(HC259_A, OUTPUT);
	pinMode(HC259_B, OUTPUT);
	pinMode(HC259_C, OUTPUT);
	pinMode(HC259_D, OUTPUT);

	setOutputs(LOW);
}

/**
  Output value should be 1 through 8
*/
void AddressableLatch::setOutput(uint8_t output, bool value) {
	digitalWrite(HC259_LE, HIGH);
	digitalWrite(HC259_D, value);
	_setLatch(output - 1);
	digitalWrite(HC259_LE, LOW);
	digitalWrite(HC259_LE, HIGH);
	digitalWrite(HC259_D, HIGH);
}

void AddressableLatch::setOutputs(uint8_t values) {
	digitalWrite(HC259_LE, HIGH);
	for (uint8_t i = 0; i <= 7; i++) {
		digitalWrite(HC259_D, bitRead(values, i));
		_setLatch(i);
		digitalWrite(HC259_LE, LOW);
		digitalWrite(HC259_LE, HIGH);
		digitalWrite(HC259_D, HIGH);
	}
}

void AddressableLatch::_setLatch(uint8_t latch) {
	digitalWrite(HC259_A, bitRead(_digitLatchMap[latch], 0));
	digitalWrite(HC259_B, bitRead(_digitLatchMap[latch], 1));
	digitalWrite(HC259_C, bitRead(_digitLatchMap[latch], 2));
}

Please note that I had to change the pin mappings for some reason. I also had to invert the value of digitalWrite(HC259_D, !value); I also am not sure why I had to do that.

Snippet from my .ino:

        AddressableLatch relayLatch;
        byte idx;
	for (idx = 1; idx <= 4; idx++) {
		relayLatch.setOutput(idx, HIGH);
		delay(1000);
	}

	relayLatch.setOutputs(LOW);
	delay(2000);

	for (idx = 1; idx <= 4; idx++) {
		relayLatch.setOutputs(LOW);
		relayLatch.setOutput(idx, HIGH);
		delay(1000);
	}

	relayLatch.setOutputs(0xff);
	delay(2000);

	relayLatch.setOutputs(LOW);
	delay(2000);

I'm sure it's something so simple, but I'm totally overlooking it.

Thank you in advance for your consideration and help.
Kyle

Snippet from my .ino:

The problem is more or less in th (snippet of the answer)

.

LarryD:
The problem is more or less in th (snippet of the answer).

Does this help?

#include "AddressableLatch.h"

AddressableLatch relayLatch;

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:
  byte idx;
  for (idx = 1; idx <= 4; idx++) {
    relayLatch.setOutput(idx, HIGH);
    delay(1000);
  }

  relayLatch.setOutputs(LOW);
  delay(2000);

  for (idx = 1; idx <= 4; idx++) {
    relayLatch.setOutputs(LOW);
    relayLatch.setOutput(idx, HIGH);
    delay(1000);
  }

  relayLatch.setOutputs(0xff);
  delay(2000);

  relayLatch.setOutputs(LOW);
  delay(2000);
}

Also show us a good photo of your actual wiring.

Also, place a LED and a series (220 ohm) resistor across each relay so they light when the relay is picked.

Edit:
I hope you aren't using the Arduino +5v pin to power the relays.

.

LarryD:
Also show us a good photo of your actual wiring.

I'll get that when I get home.

LarryD:
Also, place a LED and a series (220 ohm) resistor across each relay so they light when the relay is picked.

Edit:
I hope you aren't using the Arduino +5v pin to power the relays.

I've done this, and the LEDs do light, though dimly when all are on. I just don't hear the clicks of the 3rd and 4th relay. When I get home tonight, I'll do this again and get a picture of it all.

I am not using the Arduino 5V pin to power anything. While I'm not sure if it's ample, I'm using one of those MB102 power supply modules for the breadboard.

If all relays can be operated individually, things point to the voltage regulator shutting down.

Try a more robust 5 volt power supply.

Edit
What feeds power to the MB102?
.

Larry, thanks for the help so far. Here's the update I got last night.

I'm using a 1SPOT 9V PSU with an adapter to change it to center positive.

Updated schem, including my LM7805 VREG:

The LM7805 is powering the Arduino, also (VIN / GND pins).

In the following pics, please note that the regulators of the MB102 are being bypassed. I set the jumper for both sides to OFF, and I have a wire (orange) going directly from the center positive to the + rail of the breadboard. This provides me 9V to the first breadboard's rails.

Yellow LEDs are on the coils. Green LEDs are on the switch.

Here are the requested pics of the breadboard setup:










It was quite sporadic last night. Sometimes all four of the relays successfully engaged, sometimes they didn't. At one point, it felt as though it worked better after some time, making me believe it took a while for the caps to charge.

Also, the relays buzzed for a moment upon initial power or Arduino reset. I don't know enough to know why. Is there an easy way to fix this? (I thought I saw something about optocouplers.)

Here's a video showing the fourth coil not engaging when 1 - 3 are on:

Finally, I seemed to get much better results when I replaced the 220u cap on the ULN2803 with a 470u cap. I don't know why; most schems I see online are either 100n or 220u. I'm also a bit concerned, because I eventually need this to power 8 relays.

My FINAL product won't use the OMRONs. They'll use NEC/Kemet, but those don't fit on my breadboard.

From what can be seen, your wiring is neat and accurate, however, it appears you are feeding +5v from the 7805 to the Vin pin of the controller.
If so, feed 5v from the regulator to the 5v pin of the controller.

You could alternatively try 9v into the Vin pin.

Note: Disconnect external power from the controller when USB is in use!

Also to try:

  • measure the 5 volt line with 3 relays picked, then with 4 (you may have to hard wire the relays to get them to all energize)
  • does the 9 volt power supply sag with all relays picked?
  • The 7805 should also have a .1uf capacitor from its input to GND (as close as possible)

What happens when the controller is powered by the USB connector (while powered this way, do not power it from the external supply.)

.

You are correct; I am supplying 5V to the VIN pin. I'll correct that. (To keep some load off the VREG, I'll use 9V to VIN.)

Thank you for the warning about external power when using USB. I have definitely been doing that.

I'll check the points you've mentioned and report back tonight.

You're saying to add an additional 100n cap on the 7805's VIN --> GND? So, a 470u cap + 100n cap? I can do that, for sure!

I'll find more about the USB connector only. Last night, I seem to recall that some of the yellow lights were turning on.

So, a 470u cap + 100n cap?
Yes
The .1uf ceramic helps to keep the regulator from oscillating if there is high inductance on the input.

You can run Vin and USB at the same time.
However, 5v going to the 5v pin and the USB at the same time can be a problem.

.

LarryD:
Also to try:

  • measure the 5 volt line with 3 relays picked, then with 4 (you may have to hard wire the relays to get them to all energize)
  • does the 9 volt power supply sag with all relays picked?
  • The 7805 should also have a .1uf capacitor from its input to GND (as close as possible)

What happens when the controller is powered by the USB connector (while powered this way, do not power it from the external supply.)

I added the 100n to the VREG IN.

Measuring the 9V line to start right next to the MB102. Arduino is disconnected right now.

  • 0 relays: 9.36V
  • 1 relay: 9.32V
  • 2 relays: 9.29V
  • 3 relays: 9.26V
  • 4 relays: 9.23V

BTW: If I am NOT using the ULN2803, all relays turn on just fine, simply by supplying +5V and GND to the coils.

The regulator is getting kinda hot! :slight_smile:

Measuring the 5V line right off the VREG.

  • 0 relays: 4.99V
  • 1 relay: 4.98 - 4.99V
  • 2 relays: 4.98V
  • 3 relays: 4.97 - 4.98V
  • 4 relays: 4.97V

Removed the ULN2803 and 74HC259 from the breadboard.

Measuring the 5V line on the + rail, after the 4th relay (approx. #20 on my breadboard).

  • 0 relays: 4.99V
  • 1 relay: 4.66V
  • 2 relays: 4.47V
  • 3 relays: 4.37V
  • 4 relays: 4.32V

OK. The regulator is definitely pretty hot at this point. I try to let it cool between tests. (I'll follow up with a question later about a buck converter or another power solution to take 9V to 5V with a decent sized load.)

Added the ULN2803 and the 74HC259 back to the breadboard.

So, finally, you ask what happens when I run everything with just the 5V pin from Arduino, with power coming from the USB (I'm using a USB powered hub, BTW). It works brilliantly, even with the 220u.

I went one step further and used 9V to the VIN, NO USB power, and it still works great, even with the 220u.

HOWEVER, if I add any more load to it, things get cattywampus, which I expected.

I'll be honest, I don't know what this tells me. Why would a LM7805 not work as well as the AMS1117?

cattywampus

I learn something new ever day :o

If you are using the 7805 the output being 5 volts leaving 4 volts across the package.
W = I * E = .4amps(~100ma per relay?) * 4volts = 1.6 watts. The TO-220 package will get hot.

Your problem was the 5V was going to Vin which needs to be at ~7V

Yes, use a DC-DC Buck Converter Step-down Voltage Regulator.

What is the coil voltage of the final relay that you will be using?

Cattywampus is something my wife and kid and I love to say; maybe it's a southern USA thing?

Your math is exactly what I thought; I just wanted you to know about the heat so we could be sure. And yes, those relays are supposed to be approximately 100mA.

I switched to supplying 9V to the VIN pin and things on the relay breadboard seemed to start working properly.

However, as soon as I added my second breadboard, which contains 2 x TLC59116, 12 LEDs, 2 7seg digits, and an SSD1306 128x64 OLED (pics to be added later), things are odd again. [This breadboard has it's own LM7805 on it.]

Sometimes the relays work fine. When they start working, they continue working. If I unplug my 9V then plug back in, sometimes they continue to work, sometimes they don't. Then sometimes they will start working properly (if they weren't), and in my final test, I couldn't get them all to engage again.

If you want to see the code, I can do that. However, at this point, I'm pretty sure it's still a power thing.

Today, I created and ordered a PCB that will hopefully let me put four of the NEC/Kemet EC2-5NU relays, in lieu of the OMRONs, on the breadboard. To answer your question, my final relays (EC2-5NU) are 5V, 28mA coil current. There will be eight (8).

I also plan on replacing my 74HC259 with a PCF8574.

Buck Converter
Since I'll eventually design my own PCB, I wish I could put the buck converter on my own PCB. However, for the price of a ready-to-go board from China, how can I even consider it? Those LM2596's aren't cheap by themselves.

At that price, just mount the DC to DC converter as a daughter card onto your new PCB.

Using the shift register TPIC6A595 (Rds on 1 ohm, 350 ma per pin) removes the need for the 2803, you can use SPI.

.

Yes. I definitely am going to do the daughterboard approach! I just ordered a few from China/HK to see the dimensions.

As for the TPIC6A595, looking at the datasheet, it appears that I would not need to worry about transistors or diodes that are typically used with engaging coils. While not a perfect drop-in replacement, it would combine the ULN2803 and 74HC259/PCF8574. Is that correct? It's SPI, not I2C. I don't know how well it'd work with my SPI SD Card.

My final question for this thread, then I'll open a new thread (if needed) when I try to use the 8xNEC relays:
How can I stop the relays from buzzing on power up/MCU reset?

Code can be written for power up conditions.
The TPIC6A595 has an enable pin G'
If you create a power up reset circuit for this pin you can disable its outputs for that period of time.

I would still use kick back diodes on the coils.

I use SPI from the Arduino to send serial data to these chips.

You can use several SPI enable pins for devices.

.

FWIW, I used the PCF8574 last night (since I had it), and most of my problems are gone.

I haven't had a single relay buzz since using it (in lieu of the 74HC259). And my relays work most of the time. When they don't, simply moving the breadboard seems to cause strange scenarios.

This goes back to me not being convinced this is a solid breadboard. I have 3 on order from China, and a friend picked one up at a local electronics store. I'll have that on Monday.

On initial power up, (plugging in my 9V DC barrel), all relays turn on (well, most of the time). I like this.

Thanks, Larry, for your patience and education.

Final feedback: I got a new breadboard and all my problems are gone. I haven't had ONE relay that didn't engage.

Who would've thunk!?

You are becoming a detective/troubleshooter.

  • Never plug anything larger than 22AWG wire into a hole.
  • Only plug I.C.s into the holes on either side of the center trough.
  • Flat pins like those on a TO-220 package should be bent parallel to the pin rows so the spring pins are not bent out of shape.

.