Electronic – arduino – Multipurpose momentary button – microcontroller/arduino/esp8266

arduinoesp8266microcontrollerswitches

as more of a hobbyist than a pro I apologise if I'm asking the wrong questions, however I have been researching for a while and hoped Stack exchange might help.

I've read a few articles on low power cut off circuits and soft latching power circuits but im hoping to achieve something a little smarter.

Essentially I'd like a single button interface whereby pressing the button would power the circuit when in the off state, act as an input when the circuit is active then power down the circuit if held for say 3 seconds or more.

On a software level it's important the power down the chip using the micro controller (potentially by dropping a pin to ground connected to a transistor/mosfet) as I'd like to send a "power down" message before shutting down the circuit.

Is this possible?

Thanks in advance,

Chris

Best Answer

Yes, this is possible.

  • Use the long-hold to put the processor into sleep state.
  • Configure the same pin to wake from sleep.
  • While the processor is running you can use the pin as a standard input.