Nodemcu not starting with relay connected

When I turn on my nodemcu with the relay connected to pin d4 (the only one set up on my app) the wifi does not connects and the relay keeps buzzing. If I turn it on without the relay connected or connected to other pin and then connect it to d4 it works normally.

Your issue is not Blynk related… D4 (Gpio2 on the Esp8266) is a special pin, try to use other pin rather than this one for your purpose.

1 Like

Is it a relgular relay, or an opto-isolated relay board?
When NodeMCU pins are high, they deliver 3.3v. If you’re using a relay board then you should be powering it with 5v and connecting the digital trigger pin to D4 on your NodeMCU. Some relay boards have a jumper that allows you to select active High or Low, other are one or the other. Depending on the type of board you use you may need to adjust your code to make the relay operate when you want it to.

Some NodeMCU pins will go high at boot up, so you may need to pull it low immediately, or choose a different pin.

Pete.

thanks man! didn’t know about that. Now any ideia of how can I use an input pin as a capacitive sensor to turn the relay on?

https://www.google.com/search?q=esp8266+capacitive+sensor

There is no any problem using D4 for triggering a relay, you have to avoid using D3 and D8 as they are related to boot process. I suspect you don’t have sufficient power supply, especially if you can hear relay oscillating - it’s not having enough power to switch. 3.3V TTL is running without issues on market available 5V relay boards,

The OP issue was not using D4 for the relay, it was booting with the relay connected… a little Googling about “special” pins will find a few sites that will help clarify the issue with GPIO2 on an ESP8266 based chip:


https://www.forward.com.au/pfod/ESP8266/GPIOpins/index.html

Using GPIO0, GPIO2 and GPIO15 as Outputs

As noted above, these pins will already have a resistor connected to either VCC (GPIO0 and GPIO2) or GND for GPIO15. This determines how any external device, like a relay or led+resistor, must be connected. For GPIO0 and GPIO2, an external relay must be connected between VCC and the pin so that it does not interfere with the action of the pull up resistor


http://www.esp8266.com/viewtopic.php?f=13&t=1730

For a regular boot both GPIO0 and GPIO2 need to be floating, or pulled up with a resistor to Vcc. If at a regular boot either GPIO0 or GPIO2 is LOW, it will not boot.


Etc…

This issue does not exist on NodeMCU for sure. I’m using it for running 4-relay and 8-relay boards, D4 (GPIO 2) is used in both cases, everything working fine.

Oh, I see… so they use something different than an ESP8266 chip? :stuck_out_tongue_winking_eye:

If you were reading the whole post, you will see that it WILL work, but not when connected during boot (in a certain configuration). While the OP didn’t mention the wiring, one can figure that the relay was wired as “normal” between a GPIO pin and GND (as one would assume the GPIO wold need to be set HIGH to trigger), then that could affect the bootup.

Ahh, the good old days, when Arduinos just worked regardless of what pin you used… well except for that one time… :smile:

Of course it uses regular ESP12, I think it’s related to development board design, NodeMCU V1.0 is very sofisticated and powerful thingy . My 8-relay power strip is working for almost two months now without single issue, having one of the sockets regulated with GPIO2. There are no any troubles during boot process or logging to Blynk server whatsoever, connecting time is always below 100ms.

But I’m absolutely sure that @oliveiraigorm is facing power related issues. Either he’s trying to power up relay board from 3.3V from NodeMCU instead of using VIN, or something is wrong with the wiring. It can be both.

Sounds great… Then you either have that pin wired through the relay to VCC or your particular relay uses opto isolation or something that prevents interference with GPIO2 (i.e. not pulling it LOW but leaving it floating on boot).

However that clearly was NOT the case here… so instead of telling someone “go ahead all will be good”, or “don’t use it at all costs”, I find sharing a little education and experience will go a bit further :wink:

Yes, I’m using two separate power supplies for NodeMCU and relay board and I rely heavily on optoisolation :slight_smile:

1 Like

Try with other pins for start, D2, D5, D6 and D7 are way to go. If you’re experiencing same problems, have another look on your power supply/wiring.