4
\$\begingroup\$

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), then turn itself off.
  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.
\$\endgroup\$
4
  • \$\begingroup\$ Tried to remove D2 and R2. But D2 is needed for when gpio12 is high, or it will cause some disruption. R2 was also needed to help the signal to be held low when checking the switch state. So in this case both D2 and R2 are needed. \$\endgroup\$
    – John-Arvid
    Sep 9, 2020 at 18:10
  • \$\begingroup\$ I’am planning to build 20 of your shared project for my house heating system with a goal to shutdown the heaters when you open a window more than 2 minutes for ex… or another usage, should be notifying when i left the house and forgot to close a window… Do you have some feedback with the batery life time ? since a year did you make some improvements ? How do home assistant discover this new devices ? with API ? Where can i find the differents Libraries ? arduino IDE ? Thank you for sharing this project i was looking for this for a While ! \$\endgroup\$
    – NeOdYmS
    Sep 16, 2021 at 15:29
  • \$\begingroup\$ Answered in pm, thanks for your interest! \$\endgroup\$
    – John-Arvid
    Sep 17, 2021 at 16:35
  • \$\begingroup\$ Great project! I've emailed you. Will try to replicate with modification. Your input is greatly appreciated. \$\endgroup\$
    – Martin
    Oct 10, 2021 at 7:34

3 Answers 3

1
\$\begingroup\$

Have you considered just keeping the ESP8266 in deepsleep and having the reed switch cause it to wake up?

Here's a door alarm project using an ESP8266 which does that:

https://github.com/chaeplin/esp8266_and_arduino/tree/master/_48-door-alarm-deepsleep

More discussion here: https://github.com/esp8266/Arduino/issues/1488#issuecomment-205113504

\$\endgroup\$
7
  • \$\begingroup\$ That is a good idea if you discard my first requirement, and that I use a ESP8266. The ESP8266 itself uses ~20uA in deep sleep. Source: espressif.com/sites/default/files/… Then you have to factor in what the board uses. That is why I have used a mosfet to turn the whole thing off. \$\endgroup\$
    – John-Arvid
    Jun 18, 2021 at 6:28
  • \$\begingroup\$ I think the esp8266 and esp12 have similar (if not the same) deepsleep operation -- e.g. see: kevinstadler.github.io/notes/… \$\endgroup\$
    – ErikR
    Jun 18, 2021 at 6:32
  • \$\begingroup\$ Yes in theory, but my issue with deep sleep is the "high" current draw. \$\endgroup\$
    – John-Arvid
    Jun 18, 2021 at 6:34
  • \$\begingroup\$ I think it's worth trying out for yourself. Have you seen this video? youtube.com/watch?v=IYuYTfO6iOs An ESP-12 transmitting once an hour might last several months on 2AA cells. \$\endgroup\$
    – ErikR
    Jun 18, 2021 at 8:16
  • \$\begingroup\$ Absolutely, but my goal is to use less power than Andreas uses. youtube.com/watch?v=IYuYTfO6iOs&t=680s Here he talks about power draw, ~70uA at 4.1Vdc and ~40uA at 3.5Vdc. My circuit uses ~3uA during power off(my version of deep sleep) \$\endgroup\$
    – John-Arvid
    Jun 18, 2021 at 9:07
1
\$\begingroup\$

It seems to me that the network of R10, R12, R14 and Q2 is a bit overkill here, since you wish to trigger power-on from the output of an XOR gate, rather than directly from a switch. There's a bit of complexity and redundancy there, that you can probably dispense with.

I think that since power state is decided by two push-pull IC outputs, you can get away with a diode-OR arrangement and a single BJT, everything in the blue box:

schematic

simulate this circuit – Schematic created using CircuitLab

I also got rid of R2, since the XOR gate input will be held low by D2, R4 and R5. Lastly, I added C2 for a bit of immunity to spurious transitions at M1's gate; it's just a suggestion, I'm not sure how necessary or useful it would be without testing.

I feel that D1 and D2 should be schottkey devices, since you want to keep digital inputs as far as possible from logic thresholds.

R4 is necessary, to prevent diode protection at the MCU input from drawing a large current when the MCU is powered down, and the switch is suddenly closed, but I'm not sure why you need D2.

\$\endgroup\$
2
  • \$\begingroup\$ Thank you for your suggestion. This looks very good, do you have any suggestions on partnumbers for G1 and M1? And is it possible to simulate (in CircuitLab) this circuit how it behaves on rising and falling edges? (The time it uses and power draw on each state) Would be interesting to test this in the real world to see how it behaves! Had some experience where I needed to change some parts because of some thresholds that were difficult to spot in a simulation. \$\endgroup\$
    – John-Arvid
    Feb 28 at 6:59
  • \$\begingroup\$ XOR 74HC1G86, PMOS perhaps BSL307SP. CircuitLab is OK for basic function verification, but it doesn't have the right component models. Digital models are poorly implemented. I would use LTSpice for a better library, and more comprehensive tests, but it's not nearly as easy to use. \$\endgroup\$ Feb 28 at 13:24
0
\$\begingroup\$

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?

\$\endgroup\$
1
  • \$\begingroup\$ I have looked at the 74HC74 before, but found that it wouldn't help on the falling edge of the signal. Am i correct? \$\endgroup\$
    – John-Arvid
    Sep 4, 2020 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.