0
\$\begingroup\$

I am using an ESP8266-01 to control a 3.3 V relay via a 2N7000 NPN transistor. The ESP8266 GPIOs use a 3.3 V logic level.

I have it connected to TXD (GPIO 3) and I am trying to stop the relay from activating a couple times on boot as the pins are floating for a moment. Then they settle and the relay works fine after boot.

I tried adding a pull-up to 3.3 V thinking that would solve the issue, but it does not. There is mention of this exact problem here: Pull up on NPN transistor (during microcontroller power up) as well as here: ESP01 enable GPIO2 before boot

In the second link the person talks about using an inverter, however, I don't know what the part # may be, and I do not have enough reputation to comment on it, so I was forced to make a new question.

My idea is that the relay should be off until the ESP has booted fully, and then stays off unless I turn it on.

Here is my schematic:

enter image description here

Details of boot time data for each GPIO on the ESP8266:

enter image description here

\$\endgroup\$
6
  • 3
    \$\begingroup\$ A pull-up will provide base current and "switch the transistor on". You need a pull-down to GND. \$\endgroup\$ Aug 5 at 19:23
  • 2
    \$\begingroup\$ Maybe you didn't include it for brevity, but that regulator requires an output capacitor at least. \$\endgroup\$
    – vir
    Aug 5 at 19:40
  • \$\begingroup\$ @vir Yeah didn't put that in there. I will add it. \$\endgroup\$ Aug 5 at 19:56
  • \$\begingroup\$ @Unimportant so should that R1k change to connect to GND instead of 3.3v? \$\endgroup\$ Aug 5 at 19:56
  • 2
    \$\begingroup\$ @CircuitNoob Minor nit pick, your schematic shows a BJT but a 2N7000 is a mosfet. In either case, remove the 1K resistor you have drawn, and put one connecting the base/gate to ground. Pick this new resistor value such that the voltage divider created between it and the 10K series resistor still push the device into saturation. \$\endgroup\$ Aug 5 at 20:42

3 Answers 3

1
\$\begingroup\$

You could add one part- an ADM809 to the circuit you have.

schematic

simulate this circuit – Schematic created using CircuitLab

The open-drain output of the ADM809 will inhibit the relay operation for a minimum of 140ms after power is applied (typically 240ms). Pick one with a suitable threshold for 3.3V monitoring such as ADM809R (the higher voltage ones intended for monitoring 5V power will never release the /RESET).

\$\endgroup\$
0
\$\begingroup\$

Adding an answer based on the comments. The schematic below is essentially what you need. You need to select R2 to be a value such that when the MCU output is high, the gate voltage, \$V_g\$, is enough to fully turn on or saturate the transistor M1.

R1 and R2 form what is called a voltage divider. Assuming MCU Output is 0 or 3.3V, then when it is high (3.3V);

\$V_g \approx 3.3V * \frac{R2}{(R1+R2)} \$

That is, VG will be a fraction of 3.3V, based on the ratio of R2 vs the sum of R1 and R2.

In order to saturate M1, such that it turns on fully, you need the gate voltage to be above the threshold voltage, often denoted as VGS_Th in datasheets.

schematic

simulate this circuit – Schematic created using CircuitLab

The reason we add R2 is so that when MCU output is floating or high-impedance, \$V_g\$ is well defined (0V).

\$\endgroup\$
6
  • 1
    \$\begingroup\$ Unfortunately Brendan your circuit doesn’t address the core problem - the esp8266 requires the gpio to be high in order to boot. This has an annoying side effect of turning the relay on. Also R1 at 10k is waaay too high. It also forms a voltage divider with R2. The solution to the issue is a little more complex. The obvious one is not to use gpio2. Other solutions might require delaying the power to the relay until the esp boots. \$\endgroup\$
    – Kartman
    Aug 6 at 0:23
  • 2
    \$\begingroup\$ @Kartman I answered the question at face value, and the OP said the pins are floating at boot up. That said, the answer is fine for general MCU level-shifter requirements, and the OP also doesn't seem to know about voltage dividers. Perhaps there are more issues at play here than just the ESP and its idiosyncrasies. Perhaps you could provide a more complete answer using your expertise on ESPs? I agree that 10K is a bad choice for a series resistor, my hope was that by explaining the concepts at play the OP might arrive at that conclusion themselves. \$\endgroup\$ Aug 6 at 1:54
  • 1
    \$\begingroup\$ Brendan, my solution would be to avoid the problem! Unfortunately the OP has only asked specifically about the issue. For a workable solution would require knowing the whole circuit and then investigating various compromises. \$\endgroup\$
    – Kartman
    Aug 6 at 4:26
  • \$\begingroup\$ Thank you @BrendanSimpson for the detailed design, that is what I was hoping to understand was the math behind it all. I'm attaching a screenshot from a page that details each of the pins behavior on startup.. in my case, I am using GPIO 3 (RX) which does flutter at boot. \$\endgroup\$ Aug 8 at 21:14
  • \$\begingroup\$ According to instructables.com/How-to-use-the-ESP8266-01-pins, GPIO0 and GPIO2 need pull-ups to determine boot-up state. GPIO3 (RxD) does not appear to have any activity on start-up, so perhaps you can first set it low, before configuring it as an output. I'm not sure if your chart applies to the -01 device, which has just 8 pins. \$\endgroup\$
    – PStechPaul
    Aug 8 at 22:08
0
\$\begingroup\$

I think the problem is that during boot that pin goes high so until the ESP is running and you can turn off the pin, a pull down resistor will not stop the relay from coming on during booting even though it's a good idea to have it.

You could add a capacitor to form an RC circuit so that the 2n7000 takes a while to trigger, stopping the relay from triggering during booting but this would of course affect the response time of the relay when switched on in code.

\$\endgroup\$
1
  • \$\begingroup\$ This makes sense.. and you're right about the pin going high, I have added a new picture detailing what happens to clear up the behavior. \$\endgroup\$ Aug 8 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.