I’m essentially doing a “switch” example to run a 5v relay on an ESP8266MOD. Because of this I don’t use a pin for ground as the ESP can’t take the voltage nor allow enough current to drive the relay. I’m seeing that the relay PIN go HIGH then LOW after the call to iot_gpio_init. I’ve tried several recommended pins, such as GPIO3/9/10/16 without success of eliminating this chatter. Any suggestions?
Just a thought…
I’m thinking if you put a diode on the relay, that might at least help to figure out if the problem is with something shorting over and over. Other than that, it sort of reminds me of when a inductor coil is faulty.
It’s happening to all the GPIOs that I’ve tested. I even replaced the relay with an LED to confirm, so it doesn’t seem to be anything with the relay.
I wish I knew more…
I had something similar going on with a television control board, while powering through an inverter, which apparently was related to interference generated by the inverter.
May not be helpful at all, but if it occurs regardless of the logic, I’m still thinking it might have something do with a coil and interference.
I think a diode can be placed across an inductor to prevent this, if there is anything to my notion. I suppose an LED could work also, I’m just not sure about the voltages/amps etc…
Hopefully someone has more experience with your application.
Edit: look up “flyback diode” looking up your application, I’m guessing it could have to do with the relay coil, rather than the type of inductor, that I was imagining.
Hope it helps
Here is how I wire my 5v relay to an ESP8266. You could also use a completely separate 5v power supply for the relay power, just remove the red/black pair from the NodeMCU board (bottom pair) and connect those to a 5VDC power supply.
Wiring it as shown above ensures the digital output is only power the optoisolator on the relay boards input circuit, and not the relay’s coils.
I switched to GPIO5 and all is well. I was being silly; I was choosing GPIOs that go high at boot. D’oh!