-->
Page 1 of 3

Use a pull-down resistor with relay and NodeMCU

PostPosted: Fri May 03, 2019 4:21 pm
by array81
I use a NodeMCU to control a 2 channel relay. I use HIGH pin status when relay is at rest and LOW pin status when relay is active.
On device start for a fraction of a second relay is active then return to rest. I want avoit it, on device start I want relay is rest.
I think I need use a pull-down resistor to avoid LOW pin status on start. I do not understand where insert the resist.
Can you show me the scheme?

Re: Use a pull-down resistor with relay and NodeMCU

PostPosted: Fri May 03, 2019 5:54 pm
by Good Science For You
array81 wrote:I use a NodeMCU to control a 2 channel relay. I use HIGH pin status when relay is at rest and LOW pin status when relay is active.
On device start for a fraction of a second relay is active then return to rest. I want avoit it, on device start I want relay is rest.
I think I need use a pull-down resistor to avoid LOW pin status on start. I do not understand where insert the resist.
Can you show me the scheme?


There existing pins that have a pullup or pulldown resistor on them. Once the esp8266 is running the problem is gone. You can pick one of the pins with a pullup on them so that as the device boots up, the relay should stay off and not go low randomly. This is on the module I am using. You can go look up the module you are using to see.

You want a pull up pin on startup.


D3 IO, 10k Pull-up GPIO0
D4 IO, 10k Pull-up, BUILTIN_LED GPIO2

Also in the setup() set the pin to HIGH to start.

digitalWrite(pin, HIGH);

Then change to LOW as needed in the main loop.

Re: Use a pull-down resistor with relay and NodeMCU

PostPosted: Sat May 04, 2019 3:03 am
by array81
Good Science For You wrote:You want a pull up pin on startup.


D3 IO, 10k Pull-up GPIO0
D4 IO, 10k Pull-up, BUILTIN_LED GPIO2

Also in the setup() set the pin to HIGH to start.

digitalWrite(pin, HIGH);

Then change to LOW as needed in the main loop.


Thanks for your replay.

I just use D3 and D4 to control my relay and I set digitalWrite(pin, HIGH); on setup but this not works. I relay is active for a fraction of a second on device start. After this all work.
I have read on other forum that for this scope is not possible use the internal pull-down resitor but I need add an external (I don't know why, maybe the resistance is too small) but I don't understand the scheme. I just have use pull-down resister for button but not with relay. I need connect PIN with GND by resister before relay?

Re: Use a pull-down resistor with relay and NodeMCU

PostPosted: Sat May 04, 2019 4:41 am
by btidey
A lot of the GPIO pins go high through a weak internal pull up of around 36K until the device has booted and you set the pinMode yourself.

If your relays are set to be active high then you need the GPIO to be low during the boot up period to avoid the relay being set on during this period.

In general try to avoid using GPIO 0 and 2 (D3, D4) as these have to be high during the boot period for normal use.

GPIO15 (D8) would be a good pin to use as it has to be low during the boot period and the board will have an pull down already on the board.

For other pins you need to use a separate external pull down resistor which needs to go from the pin to 0V as well as the pin being connected to the relay input. So for example, use GPIO4 (D2) and a pull down resistor of say 4K7 to 0V.