Electronic – Improving edge detector with latching circuit for esp8266

circuit-designesp8266pcb-design

What can be done with this circuit to improve/simplify it?
For example, have I done something that is bad practice, or something that is known would fail before five years have passed (I say five since that is what I think is a normal life expectancy for household electronics), or should/could I use other parts that would be better suited.

Note:
I created this question to focus primarily on the circuit that I created. My initial thoughts were to ask a broader question, but I see (and experienced) that can be difficult. Ref my other (now edited) question: What is this circuit called?
Note 2:
This is a open source project that I want to share with the community, it is not ment to be industry standard but I also don't want to make something that breaks down in a couple of months. It is meant to be a door/window/mailbox/whatever opening and closing sensor that you can have full control over.

I have created a working prototype that I have had manufactured and tested working with my requirements. More explanation later.
Ref: https://easyeda.com/jakibsgaard/low-powered-rising-and-falling-power-on-circuit

Requirements:

  1. As low as possible power consumption in deep sleep (this circuit uses theoretically less than 3uA, except that the SN74AHC1G86DBVR power consumption states max usage as 10uA).
  2. Have a small size (this cirucit is ca 20mm x 31mm).
  3. On each edge, give a signal that is long enough for the esp8266 to wake up and keep the latching circuit on (found some information that boot time of the esp8266 is around 300ms).
  4. Try to use basic components on lcspcb to keep costs down (I don't want to solder these 0402 myself. This circuit only has one extended part).
  5. Easy to program for a normal DIY'er. So no other microcontroller that needs special equipment to be programmed.
  6. Use the esp-12f or esp-12s since these are very small.
  7. Be able for the esp8266 to sense if the sensor is open or closed.
  8. Powered by a lipo battery (have found some 200mah that are almost the same size as the pcb and has protection circuit built in).
  9. Use a reed switch or some other non-powered sensors (this is just for my use-case, so others can use what they want).
  10. Be able to check the battery voltage when waking up. Currently I set the ADC_MODE(ADC_VCC) on the esp8266, it does not give an exact voltage but it can be adjusted or thought of in software. This might be difficult if using a buck converter.
  11. Have most parts on one side since jlcpcb only mounts on one side.

About my circuit and experiences
First some credit:
For the latching-circuit Rui Santos on randomnerd tutorials.
For the idea on the edge detector circuit Russel McMahon answer.

Schematic:
enter image description here

How it works:
Assuming the reed switch connected on P1 is open and is being closed. VCC will then go directly to A on the XOR and since C1 is being charged up slowly (because of R1), B is still under the threshold, so the output Y on the XOR is now high. This sends a signal to Q2 that in its turn send a signal to Q3, this causes the gate on Q1 to close and power is sent to the esp8266.
The esp8266 is powered solely because of the signal from the XOR for a time (determined by C1, R1 and R3), this time is long enough so that the esp8266 sends a high signal out pin 14 (GPIO5) towards Q3 which then keeps the power flowing as long as needed.
When C1 is charged enough A and B on the XOR is high and Q2 is turned off and the esp8266 is keeping the power up alone.
The esp8266 is also checking if the input is high or low on pin 6 (GPIO12), this is to report if the switch is open or closed.
Then when the esp8266 is done it stops sending the high signal and the latching circuit is turned off.

Then when the reed switch is closed and being opened A on the XOR is low, and B is still being high since C1 is still holding a voltage above the threshold. This causes Y on the XOR to be high and the same process with the latching circuit is starting. D1 is avoiding current to go back in the circuit, but some leaking exists.
When C1 is depleted enough B is also low so the output Y on the XOR is now low.

On the esp8266 pin 3 (EN) needs to be high and pin 10 (GPIO15) needs to be low for the esp8266 to boot correctly. Pin 12 (GPIO0) is used when flashing and needs to be held low when doing so. But can be floating when not being flashed. Pin 11 (GPIO2) can also be floating to be in high state.

The programming header is there for easier first time programming. Later it is better to use OTA (Over The Air update). It also powers the esp8266 directly.

Battery power:
I have tested this circuit succesfully in the range of 2.5 to 4.3VDC. Of course this is not recommended as the voltage range of the esp8266 is from 2.5 to 3.6 VDC. But from my and some others experience this is ok, especially since it is only powered on a few times pr day.
I also don't need any capacitors for the power since the lipo-battery is the direct source.

Power consumption:
After testing I found that the sleep current in closed state is ~3uA and in open state ~0.40uA.
So if it wakes up two times a day, uses 3 seconds to boot and do what it should do at ~80mA, it will last over 2 years on a 200mAh battery (15% capacity derated in calculations).

Latching circuit:
I have changed some components to smaller ones since I wanted to have the SMD mounted by jlcpcb. So only basic components and as small as possible since the power consumption is very low in the "logic" part of the circuit.

Current "issues" that I can change but haven't tested or found a working solution for in real life:

  1. D2 and R2 can be removed since it seems they don't have any purpose.
  2. R5's value should be increased so that the power consumption is lowered when the sensor is closed. But currently it is needed to be this value so that GPIO12 is pulled low and not affected by the noise coming from the reverse current of D1.
  3. There should be a buck converter or LDO, but for now it is powered directly from the battery. And if a buck converter or LDO is used it should still be possible to measure the voltage when it becomes low.

Best Answer

Have you considered a 74HC74 with your signal connected to the clock input (perhaps via an inverter if necessary), the data line pulled high and a GPIO from your MCU connected to the reset line so you can cancel the request once the MCU has powered up?