-->
Page 1 of 1

GPIO Default for Relay

PostPosted: Wed May 04, 2016 7:55 am
by stevemac00
I'm using Huzzah and SainSmart relay with NodeMCU. If I turn on the relay with gpio.write(2,1), it will stay on - even across a reset. This could be disastrous for me if there was a malfunction such that the software could never start.

I know this has internal pullups but I tried a 10k resistor between GPIO and 3.3V but that did not make any difference and a reset still left the relay ON.

If I remove power then supply power, the relay defaults to off as it should but can anyone tell me how to make the relay default off for a software/firmware problem? (Hope that's clear.)

Re: GPIO Default for Relay

PostPosted: Wed May 04, 2016 4:04 pm
by Barnabybear
Hi, you'll be better off using GPIO 4 or 5, GPIO 2 has a 10K pull up resistor that will keep the relay latched during a reset. With that relay there isn't an easy way round.
https://learn.adafruit.com/assets/24745

Re: GPIO Default for Relay

PostPosted: Wed May 04, 2016 5:13 pm
by stevemac00
It's my understanding when I gpio.write(2,1) on the HUZZAH that I'm really writing to GPIO-4 since the NodeMCU pin table shows D2 as GPIO4. This is confirmed by testing the relay as well.

So, I tried #4, #5, #12, #13 to turn on the relay then I did a software reset. Each time the relay stayed on.

Re: GPIO Default for Relay

PostPosted: Wed May 04, 2016 6:05 pm
by martinayotte
How did you wired you relay and it's driver ?
There are many ways to workaround such situation.
You could use double MOSFETs with pullups in such way that only an LOW output will drive the relay ON and adjust your software accordingly.