MOSFET as relay to keep ESP on until GPIO is low



  • Hi,

    Aim:
    When a door contact reed switch is triggered it should turn ON the Wemos D1, send some data to IFTTT and turn itself OFF after that.

    Function:
    So the Wemos D1 is OFF all the time (to save battery) till the reed switch (SW) turns on the Wemos D1. When the Wemos is ON it triggers the MOSFET by setting GPIO5 to HIGH and keeps itself alive (even without the reed switch) until GIOP5 is set to LOW which turns off the Wemos.

    Problems:
    But i get strange behavior. In general it works. But after the GPIO is set to LOW the hole thing still draws 0,03Amps. And sometimes it draws 0.1Amps and i have no idea why.

    Did i use the right parts? Should i add a resistor somewhere?

    Here is my code (which only explains the function) and some schematics.

    int SWITCH = 5;
    
    void setup() {
    
      pinMode(SWITCH, OUTPUT);
      digitalWrite(SWITCH, HIGH);   // Trigger the MOSFET to stay ON
    
      // Do stuff.... for example send data to IFTT with the ESP8266_To_IFTTT 
    
      digitalWrite(SWITCH, LOW);    // Turn off the Wemos D1
    }
    
    // the loop function runs over and over again forever
    void loop() {
    yield();                      // do nothing
    }
    

    alt text



  • WEMOS ( and other IC ) is not LED.
    So switch it ON through GND is not very good solution.
    P-channel MOSFETs are used for this.


  • Contest Winner

    Add 10k resistor between the gpio5 and main gnd.



  • Thanks. I understand that my MOSFET is not the best choice. But that's the only one i have here right now.

    The 10K resistor solved my problem. Works great. Thanks for the tip.



  • Hmm... it worked for a while with the 10K resistor but now not any more.
    I guess i have to change the Mosfet to a P-Channel version.



  • @kimot
    Do you have a common P-Channel Mosfet in mind which works for this project? I am struggling finding the right one.





  • Thx for the link.
    For more info about the solution in this video perfectly explained:
    #101 Long lasting DIY "Amazon Dash Button" using an ESP8266 – 06:36
    — Andreas Spiess

    He uses a NDP6020 for Mosfet. The datasheet says:
    Vgs(th) (Max) @ id: 1V @250uA
    Gate Charge (Qg) @ Vgs:35nC @ 5V

    Is 1V the max i can connect to the Gate? That can't be true!?



  • @edsteve as per datasheet VGS Gate-Source Voltage - Continuous = ±8 V and Gate Threshold Voltage is Max 1,0V and Min 0,4V, this is working(conducting) voltage.
    So, according to above datasheet maximum voltage to gate can be ±8 V.
    About the resistor, you could also try 30K or 100K.


Log in to reply
 

Suggested Topics

  • 87
  • 3
  • 10
  • 8
  • 7
  • 5

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts