Powering ESP with a Low-Level trigger

Thread Starter

MMM**MMM

Joined May 30, 2022
91
The normally closed switch will work but not in your simulation as Q22 is not the correct mosfet for this circuit
The simulation demonstrates that the capacitor remains charged without discharging (when the switch is open). The voltage across the capacitor remains a constant 3.06V. As a result, the gate voltage of the N-MOSFET remains low, preventing it from turning on. Consequently, the gate voltage of the P-MOSFET remains high, causing it to remain off. This ultimately leads to the ESP being turned off when the switch is open.

1689875049545.png

Same for a very small capacitor:
1689875162245.png
 

sghioto

Joined Dec 31, 2017
8,634
That circuit is not designed for a normally open switch. For a normally open switch just connect Vcc from the switch to the ESP power pin.
 

Thread Starter

MMM**MMM

Joined May 30, 2022
91
That circuit is not designed for a normally open switch. For a normally open switch just connect Vcc from the switch to the ESP power pin.
This implies that the ESP will remain powered on only when the switch is closed or if the KEEP_ALIVE signal is high. However, we need to power it when the switch is open.
Furthermore, I have resolved the issue by removing the capacitor. The main problem lies in the extremely brief startup duration for the ESP. Unfortunately, I am uncertain about the ideal placement of a capacitor that would extend this duration to approximately 2-5 seconds.

1689876213558.png
 

sghioto

Joined Dec 31, 2017
8,634
You are not choosing the correct part numbers for your simulation. Diodes should be BAT42 schottky diodes or similar and the P channel mosfet a BS250. What's with the 1pf cap?
 

Reloadron

Joined Jan 15, 2015
7,890
YES, this is exactly what I'm looking for. As mentioned in the previous thread, the circuit already fulfills the function you described. However, the issue lies in the usage of a normally closed switch, whereas I would prefer to utilize a normally open switch as it is readily available to me.
I gave a link to a NO & NC switch back several post ago. You should have no problem finding one which has NO & NC contacts.

Ron
 

sghioto

Joined Dec 31, 2017
8,634
New twist using a CPC1002 SSR for either a NO or NC reed switch. Both circuits provide 2 second ON times which should be plenty of time for the ESP to power up and provide the KEEP_ALIVE signal.
1689885033618.png
 

Thread Starter

MMM**MMM

Joined May 30, 2022
91
New twist using a CPC1002 SSR for either a NO or NC reed switch. Both circuits provide 2 second ON times which should be plenty of time for the ESP to power up and provide the KEEP_ALIVE signal.
View attachment 298715
Is it feasible to substitute the CPC1002N chip with a P-MOSFET because I cannot find the CPC1002N in either the simulation or the market?
 

Thread Starter

MMM**MMM

Joined May 30, 2022
91
You can as long as the current required for the ESP is no more then 1.5ma. But it probably won't sim correctly.
The BS250 datasheet indicates a maximum drain current of 250mA. However, I'm wondering why the ESP cannot draw more than 1.5mA. Could there be other components in the circuit that are limiting the current?

1689893714072.png
 

Thread Starter

MMM**MMM

Joined May 30, 2022
91
Actually I got better results using a common 2N3906 for Q2.
View attachment 298727
Hi sghioto,

I have simulated the circuit for the normally closed switch, and it is functioning as intended. However, there are some modifications that should be made (if necessary) to handle the high negative voltage across the capacitor or the high positive voltage at the gate of the N-MOSFET:

1. When the reed switch is closed, the ESP is powered on until capacitor C8 charges. The simulation indicates that it remains powered on for approximately 15 to 20 seconds. We can adjust the capacitance of C8 to reduce this duration to, for example, 5 seconds.

2. A high KEEP_ALIVE signal keeps the ESP continuously powered on.

3. When the KEEP_ALIVE signal is low and the switch is open, the ESP powers off.

4. In the event that the switch remains closed for an extended period until the ESP completes its code execution and pulls the KEEP_ALIVE signal low, two scenarios can occur:

a) If capacitor C8 is charged during this period, the ESP will not be powered again after the KEEP_ALIVE signal goes low.

b) If capacitor C8 has not yet been charged, the ESP will power on again and execute the same code, subsequently pulling the KEEP_ALIVE signal low once more. This process will continue until C8 is charged. Therefore, selecting a precise value for C8 is crucial. It should be a capacitor that charges faster than the ESP handles the code, but not so fast that it outpaces the ESP's startup process.

5. R57 and C7 are added to handle situations when the door is opened and closed very rapidly (in less than 1 second). In such cases, the switch will behave as if it is closed for an additional 3.5 seconds (by simulation), allowing the ESP sufficient time to start up, pull up the KEEP-ALIVE signal, send the message, and subsequently pull the KEEP_ALIVE signal low to power off again. These components ensure smooth operation even during quick transitions.
1689965609842.png



I must point out that you have reversed the terms "normally closed" and "normally open". A normally closed switch is closed by default, without any external effects. Conversely, a normally open switch is open by default, without any external effects.

The circuit I simulated utilizes a normally closed switch, while your schematic indicates a normally open switch, which is inaccurate.

Additionally, I want to ensure safety measures. Just after the pull-up of the KEEP_ALIVE signal, the gate voltage of the N-MOSFET reaches 5V. Also, I noticed that C8, as depicted in the image, has a voltage of -4.22V across it, occasionally reaching -5V. This capacitor is electrolytic and should have a specific polarity. It appears to be charging in reverse polarity. How will the actual hardware handle this? Could this potentially damage the circuit?


Regarding the other circuit that utilizes a normally open switch, I will test it later on. So far, I can say that you have put in a lot of effort, and I want to express my gratitude for that. Thank you.
 

sghioto

Joined Dec 31, 2017
8,634
The circuit I simulated utilizes a normally closed switch, while your schematic indicates a normally open switch, which is inaccurate.
There is some confusion here.
Normally closed to me means the door is closed and the magnet is shorting the contacts on the reed switch, that is the arrangement I show in post #75
So what type of switching arrangement do you want to use?
 

Thread Starter

MMM**MMM

Joined May 30, 2022
91
There is some confusion here.
Normally closed to me means the door is closed and the magnet is shorting the contacts on the reed switch, that is the arrangement I show in post #75
So what type of switching arrangement do you want to use?
Yes, this is essentially identical to a normally open switch. When the door is closed, the magnet causes the contacts on the reed switch to close (so you call this normally closed). You are considering its functionality, while I am examining the inherent characteristics of the switch regardless of its function.
 

sghioto

Joined Dec 31, 2017
8,634
Quoting from post #1:
"The reed switch available to me is a normally open switch, meaning that when the door is closed, the switch will be closed due to the presence of a magnet."
Is this still the type of switch you want to use?
 

Thread Starter

MMM**MMM

Joined May 30, 2022
91
Quoting from post #1:
"The reed switch available to me is a normally open switch, meaning that when the door is closed, the switch will be closed due to the presence of a magnet."
Is this still the type of switch you want to use?
Yes, I have just simulated the first part of your circuit successfully. This part utilizes a normally closed switch (the normal case when the door is open), giving very good results. I will conduct tests on the other part in a few hours.
By the way, I have a question. How can we effectively position a capacitor like C7 in the other part of the circuit? Simply placing a capacitor directly across the switch will keep it closed for a certain period of time, but this is not desirable as it may cause unnecessary delays. I haven't considered a suitable solution for handling fast transitions, such as opening and then quickly closing the door within a second. Precisely, we need to maintain the case where the switch is open for some time even if it is just closed immediately.
 
Top