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.
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?
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.
- 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).
- Have a small size (this cirucit is ca 20mm x 31mm).
- 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), then turn itself off.
- 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).
- Easy to program for a normal DIY'er. So no other microcontroller that needs special equipment to be programmed.
- Use the esp-12f or esp-12s since these are very small.
- Be able for the esp8266 to sense if the sensor is open or closed.
- Powered by a lipo battery (have found some 200mah that are almost the same size as the pcb and has protection circuit built in).
- Use a reed switch or some other non-powered sensors (this is just for my use-case, so others can use what they want).
- 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.
- Have most parts on one side since jlcpcb only mounts on one side.
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.
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.
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).
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:
D2 and R2 can be removed since it seems they don't have any purpose.
- 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.
- 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.