1
\$\begingroup\$

I have connected the five buttons to the analog pin of esp8266 as follows:

schematic

simulate this circuit – Schematic created using CircuitLab

I want to power on/off esp8266 when SW1 is pressed. Also before powering off, some states should be written to the EEPROM. So obviously we need at least one GPIO to do this. More precisely, when esp8266 is off and SW1 is pressed, it should turned on and stay on until SW1 is pressed again. After pressing again SW1, first states should saved to the EEPROM and then turn off, waiting for another button press. What's the appropriate circuit for this situation? I thought about comparing GPIO voltage(which we can set to 3.3V when we want to power off) and ADC voltage but it doesn't work. Also I think the desired circuit should not load the ADC input.

asked Sep 2, 2021 at 3:57
\$\endgroup\$
6
  • \$\begingroup\$ so your actual question is how to turn off esp8266 programmatically, and how to turn on with a button? \$\endgroup\$ Commented Sep 2, 2021 at 4:03
  • \$\begingroup\$ @jsotola Yes but both of them should be done with same single switch SW1. I can use one digital pin if it helps. \$\endgroup\$ Commented Sep 2, 2021 at 4:08
  • \$\begingroup\$ same switch does not necessarily mean that only one pin is used to interface the circuit ... the simplest course of development I see, is to start with two buttons ... when that works reliably, find a way to merge into one button \$\endgroup\$ Commented Sep 2, 2021 at 4:18
  • \$\begingroup\$ @jsotola The main challenge is merging them. :)) And also writing to the EEPROM before power off. \$\endgroup\$ Commented Sep 2, 2021 at 4:40
  • \$\begingroup\$ writing to the EEPROM before power off ... why would that be a challenge? \$\endgroup\$ Commented Sep 2, 2021 at 5:05

1 Answer 1

1
\$\begingroup\$

We pretty soon discover that it's a bad idea to mix this unrelated analog resistor ladder stuff with your power on/off functionality. So either you need a dedicated button for power on/off, or you need a DPST switch.

This switch can then drive a MOSFET placed in series with your supply. You need some manner of latching function since the switch is momentary. I would add a hardware RC filter to filter out signal bouncing.

At the same time connect the switch to a GPI pin of your MCU. If done right, then the MCU shouldn't detect the key press at power-up, but only when it's up and running.

Once you have detected a switch press, save everything to EEPROM and then from software trigger the shut-down through GPIO tied to the mentioned MOSFET.

answered Sep 2, 2021 at 11:57
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.