single 5V power source for ESP8266 and relay rack

Hi all

I am using an ESP8266 NodeMCU to drive a set of 7 relays.

The NodeMCU is a 3.3V device but can take 5V power via a USB plug.

The relay board can take the 3.3V pin logic as input but uses a 5V supply to power the relay coils. LOW = on.

Each relay can draw 70mA and I will usually only ever have 4 on at a time, but when the ESP8266 boots it lowers the signal on 6 of the pins so I could reach 420mA draw for the relays.

I have a 5V power supply that is rated for 550mA so this sounds perfect. What I want to do is power both the ESP8266 and the relay board with the same power supply.

Is there any risk to simply running the +5V and GND into the USB socket and to the relay board terminals?

ah, I think I found a better way... I can connect 5V directly to the VIN pin duh!

It works!

Which relay board?

JB Tek 8 channel relay board

OK, so this is the opto-coupled board with active LOW inputs.

You remove the link on the relay board. and connect GND and JD-VCC directly to your 5 V power supply with a twin cable. This is to avoid the relay currents interfering with the operation of the ESP.

You connect your ESP pins to the IN terminals on the board and the adjacent VCC to the Vin (not 3.3 V) on the NodeMCU where your 5 V supply connects to it (by another twin cable separate from the relay power supply). You do not connect GND to the NodeMCU.

Any questions about this?

Thanks, I will try that, but I do now have questions...

I did in fact already connect the VCC next to the in pins to the 3V3 of the NodeMCU and I also bound all grounds together and it seemed to work. Since only one power supply is in play, I thought that all the grounds should be at the same level anyway, no?

If I connect +5V to the VCC next to the IN pins as you suggest, then surely I am driving 5V onto the NodeMCU pins in one of the two states (HIGH/LOW)?

I am a bit confused by this "(by another twin cable separate from the relay power supply)"
We are talking a single connection (VCC to +5V), so why twin?
If that VCC is connected to VIN of the NodeMCU and VIN is also connected to VCC supplying the coil power, how is that any different to connecting the two VCC pins directly?

What is the reason to NOT connect ground of NodeMCU to GND of the relay board?

I see at https://www.mpja.com/download/33329MPSch.pdf

that the VCC pins and the GND pins on the relay board are both connected to each other internally. They certainly show connection with a tester.

Connecting 5V to the VCC next to the inputs and to the JD-VCC would be the same as leaving the jumper in place between VCC and JD-VCC since the two VCC are connected, so that bit is still perplexing me.

An additional connection from GND to NodeMCU is probably superfluous as it is already connected.

I attached a picture of what I have and my configuration that seemed to work... (I understand it may not be optimal)

I think you are suggesting I connect +5V to the the pin that I have connected to 3V3.
Does that VCC pin power the logic side of the switching, with the pin output return coming back via GND?

Yellow lines represent internal connections on the relay board, I can see the traces too.

You should not need the 2 yellow wires.
D0upWXs_d.jpg

Connections.png

DaleSchultz:
I did in fact already connect the VCC next to the in pins to the 3V3 of the NodeMCU and I also bound all grounds together and it seemed to work. Since only one power supply is in play, I thought that all the grounds should be at the same level anyway, no?

Ah Here's the trick. :grinning:

You presently have the mind-set of doing your house wiring. You connect one thing to another with a wire, the current flows, the light goes on. What's the problem?

Well, we are not doing your house wiring here! :astonished: We are working with parts which operate at 16 MHz, that is Radio Frequency and a piece of wire is an antenna capable of receiving and transmitting signals. It is an inductor, albeit small.

Again and again here, we see the problems when someone innocently connects one of these relay boards to an Arduino of sorts (because of course, this is the Arduino forum), writes their code, the relays click in step and the indicator LEDs light, but then they connect the relays to their power devices and suddenly and unexpectedly the code starts crashing. :astonished: What happened?

Well, the relays switching generate rapid transients - current impulses in the wiring which are transmitted inductively from one part of the wiring to another where there are small voltage drops across the wires.

To avoid this, the relay board provides some optical isolation, but to actually make use of this, it is necessary to actually keep the input circuit to the Arduino/ NodeMCU separate from that carrying the relay current, and to prevent inductive pick-up from one to the other.

DaleSchultz:
If I connect +5V to the VCC next to the IN pins as you suggest, then surely I am driving 5V onto the NodeMCU pins in one of the two states (HIGH/LOW)?

Ah! That is a different matter, I was waiting for you to ask. :grinning:

You will note that on the relay board, there is an indicator LED in series with each opto-coupler. Each of these has a voltage drop and will not conduct at all below a certain voltage. If we figure that of the opto-coupler as 1.2 V and the indicator as 2 V, the total voltage threshold is about 3.2 V or so - there is very little leeway left to control this with a 3.3 V signal. So connecting the "Vcc" to 3.3 V is likely to be quite unreliable - it may work now, but mysteriously fail later.

By connecting it instead to 5 V at the NodeMCU itself, it will be actuated properly at 5 V when a LOW is sent, but due to the 3.2 V threshold, the pin will never be pulled higher than 2 V, so there is no risk to the NodeMCU.

DaleSchultz:
I am a bit confused by this "(by another twin cable separate from the relay power supply)"
We are talking a single connection (VCC to +5V), so why twin?
If that VCC is connected to VIN of the NodeMCU and VIN is also connected to VCC supplying the coil power, how is that any different to connecting the two VCC pins directly?

"Twin" means that the Power and ground wires must run together as either a "figure eight" cable or simply twisted, so that they do not form a loop which can either pick up or radiate impulses by induction. And to avoid impulses appearing along the resistance and inductance of the wiring, there needs to be a twin cable from relay board to power supply (where the reservoir capacitor is) and another separately from NodeMCU to power supply.

DaleSchultz:
What is the reason to NOT connect ground of NodeMCU to GND of the relay board?

To maintain isolation as described. :roll_eyes:

1 Like

Thanks Paul and Outsider, this is good stuff and exactly why I am asking such questions...

OK, now I get that the wires should be twisted to prevent crosstalk and other interference, great info and description. I assume these transients you speak of happen with single switching of the relays, i.e. even without any pulse width outputs from pins etc.?

I will redo the diagram to show those wires twisted. (Note there is only one power supply)

I also like the explanation about the 5V not coming back at my precious processor.

I am still a bit in the dark about not grounding the relay board to the ESP8266.

As far as I can tell the GND pin is already connected to GND within the board (yellow line). And I am guessing your answer will be to do with interference again... if I were to connect that pin to ground again, does that create a ground loop? I thought ground loops only happened in much larger circuits...

I have been working with digital model train layouts for years and there the rule of thumb has been to tie all the grounds together and this reduces electrical noise, in a very noisy environment. I am not sure of the frequency of the digital signal involved but I think it is only 10kHz. This background is what makes we tie grounds together by default.

Will now test with 5V to the relay VCC and no ground, then update my diagram.

BTW the relays will drive one AC 120V LED lightbulb (3W) each.

(When I tried to insert my image it asked me for a URL, and since I have not hosted it, I attached it, how did you get it to display inline?)

in updating my diagram, I run into this (probably dumb) question...

for the wire that feeds the +5V to VCC on the relay board - what do I twist it with, a ground to the ground pin?

DaleSchultz:
for the wire that feeds the +5V to VCC on the relay board - what do I twist it with, a ground to the ground pin?

Don't worry so much about the twisting, but it should be grouped with all the "IN" wires since it is the return to them. Generally you would use a ribbon cable with a multi-way "Dupont" housing to connect the relay board to the NodeMCU.

The point is that the input side of the optocouplers has no association whatsoever with the ground - since the inputs are pulled LOW to actuate the optocouplers and the current returns on the Vcc line back to the NodeMCU - nowhere else! The ground on the relay board does not connect to the NodeMCU, the only connection is that you happen to be using the same power supply to power the relay coils, by an entirely separate path.

Thanks. I have connected it as you suggest and of course it also works!

I would like to verify my understanding for the NodeMCU side.

My understanding was that the pins put out +3.3V relative to its ground when HIGH, and zero when LOW.
(Certainly this is how I wire my test LED polarities.)

Now for the relay board, I understand LOW sets the relay to be closed. When a pin is LOW it is essentially about the same as the ground of the power supply, and so current can flow from the +5V on VCC and return to the NodeMCU through the pin, (by which time it won't be 5V anymore as you explained).

Now when the pin goes HIGH at 3.3V there is only about 1.7V potential difference between it and the VCC and this falls below the threshold to turn the relay switching circuit, so it opens.

A HIGH of 3.3 is still lower than 5, and LOW is lower still.

Is that correct?

I have a very nice 10 pin ribbon cable that I am going to use on the input pins. Certainly one pin can carry the 5V as you suggest and 8 input signals. I will leave the ground pin unconnected so that the ground can be connected with the twisted pair to the main power input of the relay board.

Many thanks again!

Sounds about right.

Do not connect the ribbon cable at the relay board at all.

well this afternoon I soldered everything together, and now that all the pins are connected to the relay board, all the time, a new problem has presented itself. The ESP8266 will no longer boot if the output pins are connected. If I disconnect the ribbon cable from the relay board, it will boot up. If I then connect the ribbon cable, it drives all the relays perfectly.

Pin D8 (which is one of the output pins I am using), may not be high during boot. I am wondering if the +5V on the VCC of the relay board is causing it to be HIGH, and if so, what I could do about that. (Such as adding a resistor to pull it down perhaps?)

The device must be able to boot unattended and I may be out of usable pins......

well this afternoon I soldered everything together, and now that all the pins are connected to the relay board, all the time, a new problem has presented itself. The ESP8266 will no longer boot if the output pins are connected. If I disconnect the ribbon cable from the relay board, it will boot up. If I then connect the ribbon cable, it drives all the relays perfectly.

Pin D8 (which is one of the output pins I am using), may not be high during boot. I am wondering if the +5V on the VCC of the relay board is causing it to be HIGH, and if so, what I could do about that. (Such as adding a resistor to pull it down perhaps?)

The device must be able to boot unattended and I may be out of usable pins...... I was avoiding D3 because it goes HIGH during booting, but that would seem much better....

yup it was D8, shifted that to D3 and now it boots fine again.

Hi,
I am using a Wemos D1 mini board. Where would the VCC from relay be connected to the board?
To the 5V pin already connected to the power DC?

Please see image attached herewith.

Yes, I would think so...