I'd like to build a circuit that provides power to a microcontroller (ESP8266 in this instance) when a reed switch is changed from closed to open AND when changed from open to closed.

This is to be used in a circuit that will monitor the state of a deadbolt lock. I'm planning on attaching a magnet to the end of the bolt and putting a reed switch inside the strike box with enamelled wire running out to the ESP8266 that will be discreetly mounted on the wall nearby. The circuit will run on batteries as running power to the lock location is not practical (nor will it have a high enough WAF to get approval).

When the lock is closed it will open the reed switch and when it is open it will close the reed switch (or the other way around, I'm not fussed whether the reed switch is NO or NC).

When someone locks the lock I'd like the circuit to provide power to the ESP8266 so it can connect to wifi and send a message to the automation server recording that the lock was closed and then power itself down (ideally to a zero current draw state).

Then when someone unlocks the lock I'd like the same thing to happen, albeit that the message will be different, but I'll handle that in code, obviously.

I've researched soft latching power circuits but they only seem to work when momentary switches are pressed. Here's an example from EEVBlog:


Here are another two examples of similar one-sided circuits:



This is a similar question but seems to rely on there being constant power available at the lock location so not good for my application:

How to create a locked door detector?

This also seems to be asking a similar question but I can't fathom the answer (and there isn't a final diagram showing how the XOR gate is hooked up to the switch and the microcontroller):

I need a switch that not only detects open/close, but also sends a pulse to wake up an ESP8266 whenever the (debounced) state changes

I've also though about maybe having the ESP8266 in a deepsleep-wake cycle every 5 mins or so and just reporting the state of the reed switch but this would mean the batteries only last a few months and I'd like it to last much longer (>1 yr). The other problem with that approach is that I may have to wait up to 5 mins to know whether the lock is open or closed - often I drive away from the house and within 1 or 2 minutes want to check if I locked the lock on the way out so being able to check instantly would be very helpful.

I also wonder if it could be done using two reed switches, one NO and one NC to somehow trigger the system...?

Any help would be greatly appreciated, even if it's to say that I'm asking the impossible!


There's no way to test the state of a reed switch without attempting to pass current through it. If you don't want to pass current through a closed switch continuously, then you need to have some process that periodically checks the state of the switch by applying power to it.

I've also though about maybe having the ESP8266 in a deepsleep-wake cycle every 5 mins or so and just reporting the state of the reed switch ...

You're on the right track. If the ESP8266 itself consumes too much energy doing this, then consider using a much lower-power "auxiliary" MCU to do this testing, which can then apply power to the ESP8266 only when it's necessary to send a message.

  • \$\begingroup\$ Thanks for your reply Dave. It got me thinking that maybe I don't need to check the reed switch and can just store the previous state in EEPROM and toggle that each time it turns on. I've edited the original post to reflect this - ultimately I'd like to know if it's possible to have a latching power circuit as described. Also, what would be a suitable 'auxiliary' MCU to achieve this? \$\endgroup\$ – Thinqer77 Jul 16 at 12:28
  • \$\begingroup\$ @Thinqer77: there are lots of suitable MCUs for this task. Basically you need to do a scratch-pad design, see if the ESP8266 will do, and if not, go shopping around for a processor that will. Start with offerings that are advertised as "low power", and in addition to paying attention to quiescent power with some sort of clock running, pay attention to how much energy it'll take for the thing to wake up, check the switch, and go to sleep again. I usually measure my success on things like this by comparing my average current to the self-discharge current of the batteries. \$\endgroup\$ – TimWescott Jul 16 at 14:47

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.