Electronic – Circuit to turn microcontroller on when reed switch state changes (to monitor door lock state)


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!

Best Answer

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.