I designed a simple circuit to control a relay with a NodeMCU micro controller. The NodeMCU polls a remote web service via a simple API and pulls high or low the D1 GPIO according to what it's posted online. The relay is triggered accordingly.
I used a 2N7000 MOSFET and a pull-down resistor (78K) to keep the GPIO low if floating. I'm not sure if I also need the other 4.7K resistor to limit the current through the base-source path of the MOSFET, I couldn't risk frying the NodeMCU so I added it.
Here my initial schematic:
The system works as expected. Unfortunately the NodeMCU drives the GPIOs high for a very short period of time during boot (I measured 50-80ms or so). I don't have control of this behavior because it is before my firmware starts running. The short pulse is enough to trigger the relay and I'd want to avoid that.
I tried adding a small capacitor in parallel with the pull-down resistor. This way I solved the issue as the capacitor filters out the short spike and then discharges quickly if power is lost.
Here's the fixed schematic:
It works very well but I don't know if that's the correct way of doing things. Is it ok to do so? Does it stress the GPIO in any way? Also, do I risk letting the spike through if I quickly power cycle the NodeCPU? (I mean, does the capacitor discharge quickly enough?)