0

i'd like to have a esp-01 powered on and controlled with a push button only. so imagine the device is off, the user press the momentary push button. in the setup the esp8266 turn on a mosfet or something similar to give himself power using another line. the user release the button and the device is on. i want to be able to understand long button press and double press and similar stuff too. even when device is already powered on. so i need to have a pin attached to the button somehow this is what i have till now, thanks to a very skillfull friend of mine

the vcc is 5 v and pin tollerance is only 3v

it must be completely off when not pressed for long battery duration

enter image description here

2
  • 1
    Q2 looks upside down to me...
    – Majenko
    Commented Jul 9, 2018 at 10:25
  • yeah probably yes Commented Jul 9, 2018 at 10:38

1 Answer 1

1

You need to isolate your button from the logic output using a diode. For example:

schematic

simulate this circuit – Schematic created using CircuitLab

In this method M1's gate is normally pulled up by R2. It can either be pulled down by M2 (switched by the "HOLD" signal) or by the switch via D1.

The BTN input is pulled up by R1, and can be pulled down by the switch. M2 can't pull it down because the diode is reverse biased and blocks current trying to flow from BTN via M2 to ground.

R3 is just a pull-down on the gate of M2 to keep it off when HOLD is floating (the power is off).

If you need to interface the 5V "BTN" signal with a lower voltage-tolerant input pin just use a couple of resistors as a voltage divider to reduce the voltage to within the proper levels for the pin.

2
  • this is a good solution. the problem is that I'll use 3v as in, and the btn should work the opposite: high when button pressed and low all the rest of the time Commented Jul 11, 2018 at 9:12
  • 3v for control (HOLD) is fine as long as M2's threshold is suitable. 3V for sensing (BTN) can just go through a simple voltage divider. Why do you need the button reversing? It needlessly complicates things.
    – Majenko
    Commented Jul 11, 2018 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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