Register state changes of Reed switch

Hi there,

I would need some help to desing a small piece of schematic to obtain the desired result.
Context is the following:
I'm trying to build my own door sensor based on an ESP8266. The sensor would use a reed switch to detect open & closing of the door.
In order save power to the maximum, I desire the ESP only turns on on state changes of the reed switch and sends some information based on the state of the reed switch.

In order to wake the ESP, I need to generate a single rising edge on it's reset pin.
Hence I need to convert the state change of the reed switch into a rising edge.

Attached is a drawing demonstrates the input and desired output.

I've attempted to extrapolate using an NPN transistor as a switch to also detect an open reed switch using a PNP transistor.
Putting those in parallel I expected to be able to read the open and close state changes, but I seem to encounter a few issues.
Attached is also a drawing of my current schematic.

Info on schematic:
V5: VCC (3.3V)
V6 : pulse that simulates the reed switch open and close (so the reed switch connected to VCC will replace this voltage component)
ESP-RSP-PIN: connection going to the ESP RESET pin to trigger the wake

Can anyone provide some feedback or alternatives ?
many thanks for the help.

Did you actually test this circuit?
What happened?

By the way, with the values drawn this circuit uses 13.2 mA continuously while the switch is closed.

I did simulate it...
Simulation shows only 1 rising edge for the first state change...
Afterwards my Capacitors don't seem to discharge properly and circuit gets stuck...

see attachement the simulation.

You may try to use a logic gate for this.

A single 74H86 will do - use one of the XOR gates for the pulse output; the other three for the delay (tie one of the inputs high and an XOR becomes a NOT gate; tie one input low and it becomes a non-inverting buffer).

Do check on the minimum reset pulse length.

If I understand what you're after, there are simpler ways that consume basically zero current (or at least tens of micro amps).

I would use a CMOS one-shot circuit to generate the pulse, should be pretty straightforward. PM me if you'd like to discuss further.

Good luck beating the 2µA of the 74HC86 :slight_smile:

I currently work with the basic passive components as I don't have knowledge of CMOS and MOSFET...
Even with the basic components, I was not in the field for 10 years, so I can say I'm back a newbie in this...

As I was using a NPN as switch supplying a positive voltage at the base, I thought a PNP would be able to switch when the base was "pulled low". Capacitors would generate the single rising edge I need on my reset...

I had a similar NPN/PNP setup that worked fine in the simulation, but I had to change my schematic and one of the connections disapeared... I haven't been able to figure out whhich one it was and ended up here with my broken circuit...

Update:

I manage to create a circuit that works exactly as I would expect.
Open and close of the reed switch triggers the momentarily rising edge (see left graphic).
the right graphic is to read the state of the reed switch (which is inverted, but easy to take into consideration in the code)

Perhaps an important clarification that is not clear on the screenshot... the upper OUT is **NOT **connected to the 67k resistor...

Nicely done, assuming it works (I don't get the circuit yet). Though 12 discrete components feels a bit excessive for this application.

There are two labels "out" which are apparently not connected (or the diode would be redundant). What are these "out" points going to? What is the purpose of that diode? If that's going to the Arduino pin you still need a pull-down resistor to make it work.

The leakage current through the NPN transistor is unrealistically low. That should be in the order of 10 nA for a common NPN like the BC547. The leakage through the resistors when the reed switch is closed would be about 41 uA.

When posting a schematic please do annotate the parts so we can refer to those numbers. Makes it a lot easier to talk about it.

It's indeed a simple printscreen.

I've attached below the full text file you can import yourself on http://www.falstad.com/circuit/circuitjs.html
(direct link to cirquit: here )

2 outputs for 2 pins on the ESP8266. Top one goes to RST pin, which is pulled high and I need to generate a single rising edge to trigger the pin to reboot...
The lower output goes to another IO pin to read the actual state of the switch.

Originally the diode was meant to create a small voltage drop to respect the logic voltage levels (HIGH/LOW) and read those values on the IO pin.
I removed it, as it didn't serve any purpose after adapting the values of the resistors. (improved voltage divider).

Perhaps an important clarification that is not clear on the screenshot... the upper OUT is NOT connected to the 67k resistor...

Feel free to import the text file on the website and simulate yourself. Works like a charm in simulatin mode. Now I will test it on a breadboard with real components :wink:

circuit-20210308-1404.circuitjs.txt (1.25 KB)

Posting the updates to clarify what was discussed in previous comments.

Link to schema/simulation: https://tinyurl.com/y8t2rbkj

circuit-20210308-1420.circuitjs.txt (1.26 KB)

I've redrawn your schematic and rearranged it a little bit, now with annotation at least we know what we're talking about. The first thing I noticed was that you have two 20k resistors in parallel connected to the 10n cap. That's equivalent to a single 10k resistor - this is R6. Likewise the two 100k resistors to 3.3V; those can be replaced by a single 50k (standard values are 47k and 51k) - this is R1.

So let's see if I can figure out how this works. The simulator doesn't show well how it works; it's too fast or too slow or whatever, just not really useful. I can't see what really happens there. I've also given the outputs a sensible name, and of course annotation was added automatically.
schematic.png
So let's say SW1 starts in open state. C1 is charged fully, C2 is discharged. Both Q1 and Q2 are off.

SW1 closes. C1 and C2 are connected forming a voltage divider bringing the connection to about 330 mV. The base of Q1 is pulled to about -3V keeping it firmly off.

At the same time C2 is of course also at 330 mV, base of Q2 at 330 mV and it conducts pulling low the RESET.Very soon C2 runs out of charge, Q2 switches off again, RESET goes high. Both C2 and C1 get charged to 420 mV through the R2/R6 voltage divider. Current flowing in the circuit is the leakage though R2+R6 (40 µA) plus leakage through the transistors.

SW1 opens, now C2 is pulled to GND and the base of Q2 goes negative, holding it firmly off. At the same time C1 is pulled up, the base of Q1 is brought to about 2.9V, it conducts pulling low the RESET until C1 is discharged and Q1 switches off again.

OK, so that's how it should work. Quite neat.

Concerns: in the SW1 making cycle the 330 mV of C2 may not give enough current to really pull low RESET: it is discharged through R6 so about 3.3 µA base current, which (at a gain of 100) is only just enough to pull down the RESET line through Q2.

That current dwindles really quickly, bringing me to the second concern: pulse duration, which will be very short, possibly too short to give a proper reset of your ESP.

In the SW1 breaking cycle Q1 gets even less current as C1 charges through R2. It probably can not properly pull low the RESET line.

The state output does not go to ground, when SW1 is closed it hovers at about 430 mV. Assuming the ESP wants <0.3*Vcc for a low signal (i.e. about 1V) this will be low enough.

Possible improvements: make C1 and C2 equal value, so C1 can do a much better job helping C2 to switch on Q2. Larger values for those two capacitors may be needed to give a long enough pulse.

When testing this circuit, do connect a scope to see the actual pulses you generate, and measure whether the pulse goes low enough for long enough.

schematic.png

Lacking the small value capacitors I used a 1µ and 0.1µ for a breadboard test...
Result is not very satisfying.... I don't get a proper reset on my ESP...

I can't scope because I don't have a scope... I can only test directly on an ESP where the builtin led blinks when an actual reset happens...

I don't know how you can debug this circuit without a scope. A solderless breadboard is notorious for bad connections, with pulses as short as these a simple multimeter doesn't do. At least you should check the voltage levels at various parts of the circuit... that can also show poor connections if there are any.

So, I printed the circuit on PCB...
registering the closing of the reed switch works like a charm... C1 helps charging C2 and I get a beautiful rising edge.

However for the opening of the reed switch I have more issues.
Although it is smaller it seems to take more time to charge up, which results in a slower decrease of the gate voltage of Q1... hence I get a more slower rising edge (a bit streched).

I've attempted to play with the values of resistors and capacitors, but I'm still unable to make it work properly.
(Simulation with updated values: https://tinyurl.com/yz8ofmrq )

I went back to the simulators and one of the simulators (multisim.com) shows a different behaviour for the C1 generated rising edge.

As you can see the second rising edge does not go as low.
This may be the culprit of not getting the expected RST signal, as I need to get a low signal for at least 100µs.

Other simulators do show me proper low values. So I don't know it the new simulator is more accurate than others...
Can someone help me out to figure out if I do get proper low signal or does it get stuck at 2.2V hwen opening the reed switch ?

Updated schematic in simulator:
https://tinyurl.com/yz8ofmrq

Anyone able to test this? or to confirm which simulation is the most accurate?

Instead of this rather complex circuit have you considered simply relying on the contact bounce of the terminals to register the door opening or closing? I mean, I understand you said you don't know anything about CMOS IC's but the few minutes of learning how to use a HC86 would have probably completed this project by now.

I briefly looked at the HC86 IC, but these seem to be XOR ports... I don't see how these can help me generate the necessary rising edge with sufficient LOW signal for my ESP8266 to reset...
The chip is in deep sleep mode most of the time. Hence I cannot simply read the state of the contacts...
I'm actually using the state of the contacts to wake up the chip and read its state at that precise moment. Once the information has been provided to home assistant, it goes back to sleep...

I'm no expert, but I don't see how XOR ports can achieve this...

wvmarle provided a link to a short pulse one-shot circuit using the HC86 that triggers on either edge. A possible problem (which was alluded to) would be if the pulse it creates is not long enough to trigger the ESP8266. If pulse length is OK, then you have an inexpensive 3-component solution. If you need a longer pulse length, then you may want to look at dedicated one-shot chips (e.g., HCT123) to do the job.

I attempted the circuit, but there is an issue...
I get I edge... but can't repeat it, because the capacitor cannot discharge...

If I put an additional resistor to groundto allow for discharge, I get a huge current usage... that is not good for my battery that will lose power too quickly...

Any recommendation on correct values to get ~1ms pulse without too much power consumption ?

Simulation: https://tinyurl.com/yy5pdhvx