I want the same button to wake up (reset) and put it to sleep but this is hard if the button is tied directly to the rst pin. My thought was to read and store a value in EEPROM so tell the chip what mode we were in so it can perform the counter action. For example, on RST if the value is 0 the chip should wake up and do things. It would then set the value to 1. If the button is pressed again, the chip resets, reads there is a 1 and now just puts the chip into deep sleep after setting the value back to 0. Rinse, repeat.

Does this make sense? Will this work? Is there a better/easier way?

  • 1
    Makes perfect sense to me.
    – CrossRoads
    Feb 6, 2019 at 16:54
  • 1
    the answers to the three questions .... yes, yes, impossible to answer without a definition of "better" and "easier"
    – jsotola
    Feb 7, 2019 at 2:54

2 Answers 2


While it looks interesting as idea, IHMO you have keep in mind:

  1. Include some code for button denouncing logic. Actually you will receive couple of “resets” during ~20ms during button press. Without denouncing you may end up with reset signal right at the moment you write to the EPROM. While EPROMs are pretty “solid” nowadays, it many not be good practice. One of potential solutions IMHO is to delay update EPROM with state switch for 20ms after boot, so it be done in stable state.

  2. You may also consider to include electronic circuit to hold reset long enough to reboot the controller (it may also reduce bouncing).

  3. EPROM has finite lifespan in terms of rewrite cycles, if your device turned on and off ~100 timers per day, it may die in a ~year.

  4. Writing the EPROM usually consumes significant amount of energy, so it may reduce battery lifespan (if you use battery).

Probably more classic approach with sleep / wake up by button looks more reasonable, unless you have shortage of pins ;)


Totally agree with Serge.
To cover issues #3 and #4 of Serge's answer I recommend you to have a look at FRAM.
It has more durability with 10 trillions of write cycles.

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.