1
\$\begingroup\$

My application is that I'm trying to create a very small, "button battery" powered device to sense the opening and closing of a switch and send state changes via WiFi to another device on the network. I will be using an ESP8266 (ESP-03) which has a reset (RST) pin and a deep sleep mode.

To my understanding, the deep sleep mode can be initiated by software. Then the RST pin on the ESP needs to be brought low for at least 100us (but preferably less than 0.1 sec) to wake it up. At that time it can check one of the GPIO inputs to see if the switch is open (high) or closed (low) and then put it back to sleep until the next open/close event.

To clarify by example, one application would be to send a notification each time a box is opened or closed, which needs to include the current status. For instance, it sits closed on a shelf. When someone opens it the ESP wakes up, sends an "is open" signal, and then goes back to sleep. When the box is closed it wakes up again, sends an "is closed" signal and goes back to sleep. The box may be open or closed for a long time, so we only want the reset pulse signal sent when the state changes.

I've seen some other articles that talk about similar situations but there don't appear to be any "this worked" comments or the cases are slightly different. The monostable flip flop looks promising (http://www.bowdenshobbycircuits.info/page9.htm), but am I understanding it correctly? Also, will it drain the battery?

I'm trying to keep this device as small and energy efficient as possible.

\$\endgroup\$
  • \$\begingroup\$ Do you need to know whether the button is hi or lo, or just that it has been pressed? If you only care about button presses, then an active low momentary switch hooked up to the RST line might work. This would be the most energy efficient as there is only the leakage current through the ESP8266 pin, which is tiny. \$\endgroup\$ – spearson Feb 13 '17 at 6:05
  • \$\begingroup\$ I need to know if the button is high or low. One example situation would be to send a notification each time a box is opened or closed, which needs to include the current status. For instance, it sits closed on a shelf. When someone opens it the ESP wakes up, sends a "is open" signal, and then goes back to sleep. When the box get's closed it wakes up again, sends an "is closed" signal and gas back to sleep. The box may be open or closed for a long time, so we only want the signal sent when the state changes. \$\endgroup\$ – Mark Stevens Feb 15 '17 at 20:59
  • \$\begingroup\$ Put the added information from your comments into the question. Be SURE that the spec is necessary and sufficient to describe what you want. When it is tell us and well advise an ~~~= optimal solution. \$\endgroup\$ – Russell McMahon Feb 18 '17 at 12:19
  • \$\begingroup\$ Russell, I've updated the question. I didn't know it was proper to do that. Hopefully what I have now is more clear. \$\endgroup\$ – Mark Stevens Feb 19 '17 at 22:45
  • \$\begingroup\$ See my XOR gate addition. You can get very small package single gate XOR ICs that will do what you want. Non operating current drain can be a few microamps. \$\endgroup\$ – Russell McMahon Feb 26 '17 at 23:39
0
\$\begingroup\$

Added:

An XOR (Exclusive OR) gate (or XNOR) can be used to produce an output pulse on the rising or falling edges of an input signal. An XOR 'truth table' is:

IN Out

00 0
01 1
10 1
11 0

ie - the output is high when one only inout is high. Both inputs low or both inputs hyigh produce a low output.

In the diagram below the RC combination acts as a delay that causes any input level change to be delayed in arrival time at the RC connected input relative to the directly connected input. When a continuous high or low is input, both XOR inputs are the same polarity and output is low.
When the input level transitions there is a period of about t = R1 x C1 when the two inputs are not the same and an output pulse is produced.
Ideally Schmitt triggered inputs would be used, but std inputs "work OK" - subject to there being no input transients.

The RC only consume energy when the capacitor charges or discharges and this can be very small so the circuit achieves extremely low power consumption. CMOS gates when not switching draw sub microamp currents.

You can get single XOR gates in a package so small it's almost a breathing hazard. One of many is 74AHCT1G86SE-7

schematic

simulate this circuit – Schematic created using CircuitLab

______________________________

Something as simple as this may work for you depending on overall application (as sometimes unspecific "extras" complicate the requirement).

This shows the general principle and you may have to 'play' somewhat.

/RST is assumed to have an internal pullup to Vdd. If not, one can be added.

Initially, SW1 open = uC sleeping.
SW1 closed = /RST low and Cd is charged low. SW1 open releases /RST and processor come out of sleep.
Cd level can be read via GPIO.
Cd level returns to Vdd = high after a period > t= RdCd.

If the switch is the only thing that brings the processor out of sleep then the GPIO read and no circuitry is needed except apart from the switch and a pullup for /RST (internal or external).

schematic

simulate this circuit

\$\endgroup\$
  • \$\begingroup\$ Thank you for the suggestion, but am I correct in understanding that this only triggers the micro controller to wake up when the switch SW1 goes from the closed to open state? I also need it to trigger when the SW1 goes from the open to closed state. I think this circuit would also not work at all while SW1 is closed because /RST would remain low. \$\endgroup\$ – Mark Stevens Feb 15 '17 at 21:05
  • \$\begingroup\$ Russell, could you please revisit this or mark down your answer so that this question does not appear answered? I attempted to update the question to make it more clear but no one has revisited it. Your response did not address the problem I was attempting to ask. \$\endgroup\$ – Mark Stevens Feb 25 '17 at 14:07
  • \$\begingroup\$ Russell, the suggestion with the XOR gate is great! Since I need Vout inverted I supposed I could use a NOT gate after the XOR, but then I realized that a XNOR gate work. If so, this is a very simple solution. I will also look at creating this as a Schmitt trigger, although I think if I size the pulse T (e.g. R x C) to 150ms then it should "debounce" itself. Again, great suggestion...thanks! \$\endgroup\$ – Mark Stevens Feb 28 '17 at 2:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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