Chat freely about anything...

User avatar
By Marko Mocilac
#92169 Hi,

I am doing latching circuit using ESP01.
In short, once motion is detected, EPS01 will be turned on with 3.3V.
Now it should do stuff and select GPIO2 OUTPUT to HIGH, this opens MOSFET which cut off power supply for ESP01.

I noticed problem with ESP01 GPIO.
In case pin have some load (10k pull down resistor prior mosfets gate) measured voltage on pin is 1.3V, when I leave GPIO2 open (no load) everything seems to be fine and I am measuring expected 3.3V.

Could you please help me clarify this?
Any proposal for a solution.

In case you would need code, it is very simple:

Code: Select allvoid setup() {
  Serial.begin(115200);
  pinMode(PIN, OUTPUT);
  setup_wifi();
  mqtt_client.setServer(MQTT_SERVER, MQTT_PORT);
  mqtt_client.setCallback(mqtt_receive);

  Serial.println("setup(): State on pin " + String(PIN) + " is: " + String(digitalRead(PIN)));
}

/***************/
/* Main loop() */
/***************/
void loop()
{
  mqtt_connect();
  mqtt_client.loop();
  digitalWrite(PIN, HIGH);
  Serial.println("loop(): Current state on pin " + String(PIN) + " is: " + String(digitalRead(PIN)));
  delay(100); 
}
User avatar
By eriksl
#92199 I don't think it's smart to use ESP01's GPIO2 for driving a MOSFET. A MOSFET is required to have a strong signal at it's gate, which transitions as fast as possible and charges the gate, or drains any remaining charge from the gate as fast as possible. With the obligatory pull up resistor connected that is hard(er) to achieve. Also keep in mind GPIO2 will go completely wild during booting, the default routing of the GPIO's is all sorts of clock signals so imagine what the load on your MOSFET would do.

To solve the first problem I'd really recommend using a MOSFET gate driver IC (like IR4427). It also inclused a schmitt trigger, so the gate will always be at one of two defined levels - completely off or completely on.

To solve the second problem use a GPIO that's more or less defined during boot. I don't think there are any available on the ESP01, may the UART input (GPIO3). Otherwise better use an I2C I/O expander, their output is always defined (doesn't change without explicit command to do so).
User avatar
By Marko Mocilac
#92336 Thank you very match for your feedback and detail explanation!

Regarding driving the mosfet I am aware that for properly usage I should use mosfet driver.
However, for my purpose I guess it should be fine without it.
This suppose to be kind of door alarm functionality.
I really do not use mosfet and esp01 for high speed switching. I thought that having pull down resistor on mosfets gate and maybe adding current limiting serial resistor could balanced things.
I already used this approach in simple circuits for dimming LEDs which actually uses PWM signal up to 1kHz I think. So far I didn't experienced problems for a year.

I test this latching circuit with ESP8266 NodeMcuV3 board, it works fine.
My main problem here is than obviously related with ESP01 and GPIO2 I choose to use.
I am a bit noob, I wasn't aware that ESP01 will go wild during boot on GPIO2.

After I try to use GPIO3 it works fine.