Tuesday 8 August 2017

WeMos self-turn-off with N-channel MOSFET


I'm trying to build an internet-connected button. When button is pressed, WeMos D1 turns on, makes a network call and then cuts off the power by pulling the irlb8721 gate to LOW.


Video: https://photos.app.goo.gl/QEpIgPa3gxHatTyG3


Here's the program I currently use for test:


void setup() {
pinMode(2, OUTPUT);
digitalWrite(2, LOW); // Turn on built-in LED

pinMode(5, OUTPUT);
digitalWrite(5, HIGH); // Keep ourselves powered after button is released

delay(5000); // Do the work, e.g. make a network call
digitalWrite(5, LOW); // Cut off the power
}

void loop() {}

The problem is that after the power is turned off, there's still ~20mA current leaking, which is a deal-breaker for a battery-powered button. Disconnecting the pin 5 (D1) gets rid of that for some reason.


Resistor between gate and source is 676kOhm, between D1 and gate - 10kOhm. Thanks for your help!


circuit



Answer




I think , because you are using the WeMos to turn itself off, what is happening is as the MOSFET turns off, the voltage on the pin driving it goes up.


Or to put it another way, the pin driver is standing on the ground it is trying to pull up.


This is what you are trying to do..


schematic


simulate this circuit – Schematic created using CircuitLab


Without studying the specs on the device that internal pull-up may or may not be present and controllable.


At some point it will turn into some form of linear regulator or oscillate.


You may have more success using


pinMode(5, INPUT);


instead of


digitalWrite(5, LOW);

That will allow the pull-down to do it's job, assuming that pull-up does not exist or can be turned off.


If it exists and can not be turned off, you need to significantly reduce the pull-down value and gate resistor and add another one to the switch line and eat the current loss through the divider.


schematic


simulate this circuit


However, either way, cutting it's own throat may be problematic since the device may reset itself during the power down or brown out.


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...