NodeMCU with 5V relay

Hi folks - I have an ESP8266, and I want to use that to control a relay. The relay should use an isolated 5V circuit for what it is switching.

The relay I'm using is this: https://www.amazon.com/gp/product/B01HCFJC0Y/ref=ppx_yo_dt_b_asin_title_o03_s01?ie=UTF8&psc=1

I have the ESP8266 powered from the micro usb. I have power from the 3v3 off the 8266 going to the vcc of the relay board, and the D1 pin going to input 1 on the relay.

Then I have a separate 5V power supply hooked to the JD-VCC of the relay board, and GND from the relay board (next to the JD-VCC) going to the ground for the 5V power supply.

In this configuration, the relay is properly turning on and off based on my arduino code (and it clicks when it does so)....but there is no current coming out of the relay.

What am I doing wrong? Is it possible to control the relay switch with the 3.3V ESP8266?

In this configuration, the relay is properly turning on and off based on my arduino code (and it clicks when it does so)....but there is no current coming out of the relay.

Post a schematic showing all connections to the relay contacts.

There isn't supposed to be coming any "current" out of the relay.

The relay is just three pieces of metal being moved around. It's just a changeover switch. Instead of you moving the switch by a lever, you have an electromagnet do the job for you.

// Per.

There isn't supposed to be coming any "current" out of the relay.

The relay is just three pieces of metal being moved around. It's just a changeover switch. Instead of you moving the switch by a lever, you have an electromagnet do the job for you.

I was hoping we wouldn't have to go there....(then we would have to confirm he knows what current is...)

First of all - thank you for the quick responses. And I apologize I am just learning. I know some theory
It stops at v=ir and the water pipe analogy) and have watched about 30 you tube videos.

I've attached a (crappy) schematic -- sorry, I didn't learn better tools yet to create a good one.

Note: To try to simplify the problem I swapped an Arduino Uno for the NodeMCU right now so at least I wouldn't have the voltage difference (since the Uno outputs 5V).

Even in this circuit setup, the relay is clicking and switching, but the LED is not lighting. Using the multimeter on the two relay screws with wires says the voltage drop is 4.4 mV. Testing at the 5V power source shows the proper 5V ... so I'm using the multi meter right. I think? :S

circuit.png

circuit.png

Testing - I sent a response with a schematic image, but I only see it on the forum when I'm signed in. Not when I'm signed out. Sending this as a test.

I used the img tags to show your other .png images. I don't see any schematic either.

Where is the led connected to 5V ?

Appreciate the quick responses again guys. CrossRoads - by "schematic" I meant one of my two images that had boxes and wires. (blush)

Raschemmel....perhaps this illustrates the depth of my misunderstanding...but my assumption was that the 5V is provided to the LED through the 5V going into the JD-Vcc. I assume the flow in this module is that power flows in through the JD-Vcc, through the relay (through the normally open port when the relay is activated, and through normally closed when it is not).

So I connected the resister and LED to the NO port, then back to the common port on the relay, where I assumed it flowed back through GND to the ground of the 5V source.

The NC-C-NO are only connected to the relay's screw terminals, not to any control pins.

So you don't even have a meter to take measurements ?

Your post says there is NO jumper !

Raschemmel - I have a meter just out of the picture I took above (and as I mentioned in my post, I took many readings of many things). I fully grant you I am a beginning and I'm doing my best. I apologize for not knowing much and if I'm wasting your time. In my readings I found that no voltage was getting through to the LED, as I mentioned; although at the power source the 5V was fine. Also WRT the "no jumper"...there isn't...I took it off of the JD-vcc and vcc pins on the relay module...you can see as such in the picture. Unless I'm misunderstanding what you're saying?

CrossRoads - ...thank you. So I do have a fundamental misunderstanding of how the relay works. That explains it...there was no power at the LED because I hadn't actually hooked up power to that part of the circuit.

I've been re-studying this tutorial: https://howtomechatronics.com/tutorials/arduino/control-high-voltage-devices-arduino-relay-tutorial/

....so if I understand correctly now (and as you guys alluded to above): the relay is really only a switch. nothing about the pins is transferred through. The vcc is the voltage that flows to the LED light of the optocoupler - and the jd-vcc is the voltage that flows to the electromagnet to throw the "switch".

Do I have that right? If so, three questions:

  1. Does the Vcc need a ground? It appears like it might not (vcc flows to In1) - but I'm not sure I understand why not. In the diagram at the link above, I see where the jd-vcc ground flows out the bottom.

  2. Without sacrificing isolation, I think I can use the same 5V source powering the jd-vcc to power my LED light circuit being triggered by the relay. Right? I can't use the arduino 5V source, though, because that would be using the power source for "both sides" of the optocoupler, I think?

  3. If I swap the Arduino Uno out for an ESP8266, the power going to vcc will be 3.3V vs. 5V. The relay is a 5V relay - does that mean both vcc and jd-vcc need to be 5V? If so, any suggestions for a clean way to get the ESP8266 working with a relay like this?

Can't tell you how much I appreciate the help guys - I know I'm learning.

If you remove the jumper , the relay coil has no power.
You can try to turn it on with a signal but nothing will work. The led wouldn't work with or withou the jumper.

Yes - that is the problem. I was trying to figure out why it had no power given I thought the jdvcc would power it.

Is my understanding as I posted above correct?

....so if I understand correctly now (and as you guys alluded to above): the relay is really only a switch. nothing about the pins is transferred through. The vcc is the voltage that flows to the LED light of the optocoupler - and the jd-vcc is the voltage that flows to the electromagnet to throw the "switch".

Do I have that right? If so, three questions:

  1. Does the Vcc need a ground? It appears like it might not (vcc flows to In1) - but I'm not sure I understand why not. In the diagram at the link above, I see where the jd-vcc ground flows out the bottom.

  2. Without sacrificing isolation, I think I can use the same 5V source powering the jd-vcc to power my LED light circuit being triggered by the relay. Right? I can't use the arduino 5V source, though, because that would be using the power source for "both sides" of the optocoupler, I think?

  3. If I swap the Arduino Uno out for an ESP8266, the power going to vcc will be 3.3V vs. 5V. The relay is a 5V relay - does that mean both vcc and jd-vcc need to be 5V? If so, any suggestions for a clean way to get the ESP8266 working with a relay like this?

It's no secret the jumper allows you to power thecrelays from a separate supply. The input has to talk to the Vcc circuit but doesn't care about the relay power but of ociursevifvtgetevis none a good input sigal can't energizevthecrelay.

larrywal32:
What am I doing wrong? Is it possible to control the relay switch with the 3.3V ESP8266?

For an ESP8266 - such as a NodeMCU or WeMOS D1 Mini with that opto-isolated relay board, you must:

  • Remove the link.
  • Connect your 5 V relay supply to Gnd and "JD-VCC" on the three terminal connector.
  • Connect your ESP8266 I/O line(s) to the relevant "IN"(s) on the relay board.
  • Connect your ESP8266 5 V supply and not the 3.3 V to "Vcc" on the ten pin connector.
  • Do not connect Gnd to ground on your ESP8266 board.

Also, write the output pin HIGH before setting pinMode to OUTPUT, otherwise you may get spurious activation of the relay(s) during initialisation.

Regarding the separate 5 V supply. What is important is that power wiring - and control wiring - is laid out so that related wires - power and ground or control and ground or input and ground always travel bound together using twin ("figure 8") or ribbon cable. In the case of the control lines to the relay board, it is the "IN" wires and 5 V rather than ground, which are bound together.

A reasonable isolation of the relay supply is where the relay supply to this relay board runs (that is, 5 V and ground, together) from the board and back to the output capacitor of the 5 V power supply and the supply to the logic board (that is, 5 V and ground, together) also runs from that output capacitor of the 5 V power supply. It is the responsibility of the power supply to prevent transients propagating from one part to another and interfering with the logic devices.

Thank you Paul! Couple of follow ups...

Connect your ESP8266 5 V supply and not the 3.3 V to "Vcc" on the ten pin connector.

Would love to understand more as to why. I tested an ESP8266 with a different relay module and it seemed to work. I ask because my ESP8266 is currently powered by a standard 5V microUSB cable, so I'd have to separate that out in order to tie in to the 5V directly.

Do not connect Gnd to ground on your ESP8266 board.

Again - would simply love to understand more why - if the signal circuits are really isolated from the relay circuit, then wouldn't the signal circuit need a ground?

I thought you might ask these things. :grinning:

Here is the per-relay circuit of the relay board:

Note the input circuit of the opto-coupler. It connects from "IN0" to "VCC". It has nothing whatsoever to do with ground - the ground is only for the relay power so you connect ground only to the relay power - using the terminal in the triple header.

Secondly, you have a green LED with a voltage drop of 2 V or more (the 1.8 on the diagram is rather conservative :roll_eyes: ) in series with a optocoupler (IR) LED of 1.3 V or so drop. That would easily total 3.3 V without the resistor, so you need more than 3.3 V to reliably actuate it. So "VCC" must be connected to 5 V, not 3.3 V.

Note that the two LEDs in series will definitely not conduct below about 2.5 V or so, so with 5 V on "VCC", no more than 2.5 V can ever appear on "IN0" so there is no risk in doing so, of applying any voltage greater than that, to the ESP8266.

larrywal32:
if the signal circuits are really isolated from the relay circuit, then wouldn't the signal circuit need a ground?

A critical concept here regarding electronics and logic. A circuit must be a complete circuit, but logic does not always reference to ground. "Active-LOW" logic references instead, to Vcc. :sunglasses:

This is so helpful. Thank you Paul.

Last question - any additional good pointers you recommend I look at to understand this more? It blows my mind and I'm picturing water spilling out of the end of the proverbial pipe :).

A critical concept here regarding electronics and logic. A circuit must be a complete circuit, but logic does not always reference to ground. "Active-LOW" logic references instead, to Vcc. :sunglasses:

Paul__B:
For an ESP8266 - such as a NodeMCU or WeMOS D1 Mini with that opto-isolated relay board, you must:

  • Remove the link.
  • Connect your 5 V relay supply to Gnd and "JD-VCC" on the three terminal connector.
  • Connect your ESP8266 I/O line(s) to the relevant "IN"(s) on the relay board.
  • Connect your ESP8266 5 V supply and not the 3.3 V to "Vcc" on the ten pin connector.
  • Do not connect Gnd to ground on your ESP8266 board.

Also, write the output pin HIGH before setting pinMode to OUTPUT, otherwise you may get spurious activation of the relay(s) during initialisation.

Regarding the separate 5 V supply. What is important is that power wiring - and control wiring - is laid out so that related wires - power and ground or control and ground or input and ground always travel bound together using twin ("figure 8") or ribbon cable. In the case of the control lines to the relay board, it is the "IN" wires and 5 V rather than ground, which are bound together.

A reasonable isolation of the relay supply is where the relay supply to this relay board runs (that is, 5 V and ground, together) from the board and back to the output capacitor of the 5 V power supply and the supply to the logic board (that is, 5 V and ground, together) also runs from that output capacitor of the 5 V power supply. It is the responsibility of the power supply to prevent transients propagating from one part to another and interfering with the logic devices.

Hello, I have exactly the same problem but I do not understand the points

I have a nodeMCU that have in input a keypad and it activate a Rele. The problem is exactly the same, the nodemcu is 3,3 and the Rele is 5V. Now the circuit is like this, however when I turn on the power of the nodeMCU the relay become HIGH. However if I turn on the nodeMCU and THEN I put the connection VU- UCC it works.

Could you please help me to use the others pins of the relay (JD-VCC and VCC)

Thank you