Powering relay with NodeMcu

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
Ophirg123
Posts: 3
Joined: Fri May 10, 2019 4:20 pm

Powering relay with NodeMcu

Post by Ophirg123 » Fri May 10, 2019 4:43 pm

Hello,

I am a newbie in using electronics and i have some issues.

I bought Nodemcu and 5v relay. I connected him with the Vin port to receive 5 volt for the relay.
I configured another GPIO for controlling the relay by the "relay = machine.Pin(5, machine.Pin.OUT)" and then the relay switched to on.
I tried to switch the relay to off by "relay.off()" but nothing happened.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Powering relay with NodeMcu

Post by Roberthh » Fri May 10, 2019 6:26 pm

What kind of relay or relay module arr you using. You may post a link to that relay.

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: Powering relay with NodeMcu

Post by OutoftheBOTS_ » Sat May 11, 2019 2:11 am

You will also need isolation from the relay as it will produce back EMF from the coil in the relay.

To make the whole system work you need 3.3v to power the Node MCU and 5v to power the relay and isolation.

You can buy these super cheap https://www.aliexpress.com/item/ESP8266 ... st=ae803_5

They have all the components on board. There is a buck converter to convert supply down to 5v to power relay and then a linear converter to convert down further to 3.3v for the ESP8266 as well as the isolation to the relay.

Ophirg123
Posts: 3
Joined: Fri May 10, 2019 4:20 pm

Re: Powering relay with NodeMcu

Post by Ophirg123 » Sat May 11, 2019 7:23 am

I bought this relay:
https://www.gearbest.com/power/pp_35514 ... id=1433363

So from what I understood, there is no possible way to connect and control a relay from a single esp8266 board with usb 5v only?

By the way I found another issue. This time with connecting water pump:
https://www.gearbest.com/diy-parts-comp ... id=1433363
I tried to control it with GPIO5 but it was too low (The power of the pump).

I think that there something that I don't understand with the voltage at GPIO's.

ThomasChr
Posts: 121
Joined: Sat Nov 25, 2017 7:50 am

Re: Powering relay with NodeMcu

Post by ThomasChr » Sat May 11, 2019 7:41 am

The relay module should be controllable by an ESP8266 board. You power it via 5V from the esp board and use a 3.3V gpio pin to trigger it. It‘s not actually really specified to get switched by 3.3V instead of 5V but it should work.

The think you struggle with right now is not voltage, it‘s current. Motors are known for needing "much" current, especially on startup (because they are essentially electro magnets which are something like a short circuit wire...), they even have some nasty spikes of voltage when you stop them, which can easily kill your ESP8266. Fortunately most of them have an inbuilt diode to dicipate these spikes.

So coming to your little ESP8266 which only can deliver a few mA of current per GPIO - these are not enough for a motor, even if the Voltage (3.3V) matches.

There are essentialy three ways to go from here:
1. Use a transistor, it‘s a device allowing you to switch a rail which can provide more current (aka a wire from your battery, which can provide thousands of milliamps) with a wire from you esp8266.
2. Use a motor driver like a L293D. Truly nothing more than a few transistors arranged in a nice package.
3. Use a relay, but beware that it is switched on by a magnetic force, and generating magnetic force needs a few mA. But those relay modules have a transistor for that on them, because they know that nearly every powerful microcontroller these days isn‘t able to switch more than a few mA of current.

Did that help you or are you even more confused now? :-)

Thomas

ThomasChr
Posts: 121
Joined: Sat Nov 25, 2017 7:50 am

Re: Powering relay with NodeMcu

Post by ThomasChr » Sat May 11, 2019 7:47 am

By the way: You can think of voltage as the force with which a water stream flows (water high up from a mountain has more force). The current is the amount of water flowing.

So you stream from the ESP8266 has enough force but simply it is not wide enough and so it‘s not enough water.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Powering relay with NodeMcu

Post by Roberthh » Sat May 11, 2019 8:03 am

I bought this relay:
https://www.gearbest.com/power/pp_35514 ... id=1433363
As far As I understand from the sparse information for that product, it requires a low level with respect to 5V to switch ON. Since a single transistor seems to be used on the board, even 3.3V is considered a low level. Therefore, it is always ON. I do not know why they always seem to use this design, which is impractical for driving.
You need another transistor to shift the levels. This is simplest done with a 2N7000, with Drain->Relay module input, gate->NodeMCU, Source at GND.

Nevertheless, the modules posted by @OutoftheBOTS_ seem much more appropriate for that purpose.

Ophirg123
Posts: 3
Joined: Fri May 10, 2019 4:20 pm

Re: Powering relay with NodeMcu

Post by Ophirg123 » Sat May 11, 2019 8:19 am

Thank you all very much!

I am a electrical engineering student so I will learn more about circuits and current next semester.

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: Powering relay with NodeMcu

Post by OutoftheBOTS_ » Sun May 12, 2019 10:02 pm

Most of the relay modules that I have brought have been really badly designed. The Chinese just copy each other and if the orginal desing had flaws then they seem to just keep coping each other.

Common problems.

No1. Back EMF from the coil of the relay. There needs to be an octocupler or after some use your MCU will die.

No2. Most relay need either 12v or 5v (and enough amps) to energize the coil of the relay. The board needs a design where there is a power supply of the needed voltage of the relay then a transistor that switches that voltage from the MCU pin.

Post Reply