-1
\$\begingroup\$

I'm trying to read capacitor voltage over ESP8266 A0 pin. Positive capacitor output is always conected to A0. Negative is connected to ESP8266 via a BC547 transistor to prevent capacitor discharge. Transistor acts as a switch - it connects capacitor negative to ESP GND for voltage reading only when I send a high signal to the base of this NPN transistor. Voltage reading over A0 works fine, but I get a reading even when the transistor is off. What could be the issue ?enter image description here

\$\endgroup\$
8
  • 2
    \$\begingroup\$ As drawn, the capacitor is always connected to GND and it is the ESP's ground pin that's being switched... \$\endgroup\$ Jul 26, 2022 at 12:21
  • \$\begingroup\$ Yes, I'm switching ESP GND to capacitor negative via transistor. I want to prevent A0 discharging capacitor when it is not performing reading. Is this correct way to perform this ? \$\endgroup\$
    – Marc
    Jul 26, 2022 at 12:38
  • \$\begingroup\$ Draw the rest of the circuit. Where does "PIR OUT 3.3V" come from and where is it's ground connected? \$\endgroup\$
    – brhans
    Jul 26, 2022 at 13:56
  • \$\begingroup\$ PIR 3.3v is pir sensor output. I'm using capacitor to store PIR value (if PIR was high). Pir GND is connected to capacitor negative. \$\endgroup\$
    – Marc
    Jul 26, 2022 at 15:21
  • 1
    \$\begingroup\$ If you only need to know if the PIR was triggered during the hour the ESP sleeps (and not how many times it was triggered) you could use a interrupt to wake up on PIR trigger, and then disable the wake-up on PIR trigger before going to sleep again. So it'll only wake up once on the first trigger... \$\endgroup\$ Jul 29, 2022 at 7:15

1 Answer 1

0
\$\begingroup\$

Very low current analog 1 bit memory

schematic

simulate this circuit – Schematic created using CircuitLab

You can isolate the capacitor using a MOSFT as switch. If you want to check the capacitor voltage, you activate the MCU output WANT_READ and immediately take an ADC measurement. This way there is no current consumption via R1 during sleep mode.

The voltage at MCU_ADC can be lower than the capacitor voltage because it will not rise above VCC - Vthr (the threshold voltage of the MOSFET). But since the purpose of this circuit is only a kind of event memory, this should not be important as long as a FET with low threshold is used.

Finally the capacitor fully discharges via R1 and a new cycle can start after WANT_READ is low again.

This circuit is not free from leakage currents but will hold the information for some hours.

Some MCUs have a very high dc input resistance at their ADC inputs (e.g. 100 Mohm ATmega88-328 series) and the circuit would not be needed at all for 1 hour info hold time.

Edit:
Alternative solution with BJT

schematic

simulate this circuit

\$\endgroup\$
8
  • \$\begingroup\$ Thank you for this schematic. Is it possible to use 3.3v logic level mosfet like IRLZ44N since I can obtain BSS138 only in SMD version ? Or perhaps an opto coupler ? \$\endgroup\$
    – Marc
    Aug 8, 2022 at 21:17
  • \$\begingroup\$ @Marc IRLZ44N is not an option, but an opto coupler is a good idea. I just don't know the typical leakage current of them. An NPN with 50 kohm base resistor may also work. \$\endgroup\$
    – Jens
    Aug 8, 2022 at 21:27
  • \$\begingroup\$ could you help me with schematic using PC817 optocoupler ? I tried to connect A0 pin to PIN4 (colector) of opto and pin 4 (emiter) to output of capacitor. But I get consant A0 reading despite of opto state (I'm controling opto using digital output). PIR and ESP8266 are connected to same battery. Could this be the issue ? \$\endgroup\$
    – Marc
    Aug 10, 2022 at 18:51
  • \$\begingroup\$ Its just the other way round: collector to the capacitor, emitter to R1, because the voltage at C1 is more positive (in case of an event) \$\endgroup\$
    – Jens
    Aug 10, 2022 at 20:43
  • \$\begingroup\$ The opto coupler needs 18µs time to conduct, so you have to wait that before reading the ADC (delayMicoseconds) \$\endgroup\$
    – Jens
    Aug 10, 2022 at 20:48

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.