ESP12e: analog reading not working with voltage divider

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
djipey
Posts: 14
Joined: Sun Dec 01, 2019 3:04 pm

ESP12e: analog reading not working with voltage divider

Post by djipey » Sun Jan 05, 2020 3:53 pm

Hi,

I'm trying to read from an analog sensor (a capacitive soil moisture sensor). I'm using a ESP12E, not a development board, so the ADC pin can only take 1V max. Since my sensor can output up to 3V, I need a voltage divider to not fry my board.

Here is my wiring:
https://imgur.com/4NYRfzt

Could you please confirm the wiring is ok?

I then use this code to read from the sensor:

Code: Select all

from machine import Pin, ADC
from time import sleep

pot = ADC(0)

while True:
    pot_value = pot.read()

    print(pot_value)

    sleep(1)

However, the analog reading is always 0. When I disconnect the ADC pin, I get other, fluctuating values. So I think the problem comes from my voltage divider.

The sensor works with a ESP32 devkit board, so the problem doesn't come fro m the sensor (the devkit board has a voltage divider, so I didn't need to make one myself).

User avatar
pythoncoder
Posts: 3925
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ESP12e: analog reading not working with voltage divider

Post by pythoncoder » Sun Jan 05, 2020 4:56 pm

Can the sensor drive an impedance as low as 320Ω? It would help if you could measure the voltages coming from the sensor and going into the ADC.
Peter Hinch

djipey
Posts: 14
Joined: Sun Dec 01, 2019 3:04 pm

Re: ESP12e: analog reading not working with voltage divider

Post by djipey » Sun Jan 05, 2020 5:32 pm

I'm a beginner in electronics so I'm not sure about what "Can the sensor drive an impedance as low as 320Ω?" really means.

But I can measure the voltages coming from the sensor, I have a multimeter. Directly from the sensor (no voltage divider), I have 2.5V when the sensor is in the air, and 1.2V when it's in water. When I measure the output of the voltage divider, I get 7 mV. That's really low. So I guess it answers your question.

What can I do to fix the problem?

djipey
Posts: 14
Joined: Sun Dec 01, 2019 3:04 pm

Re: ESP12e: analog reading not working with voltage divider

Post by djipey » Sun Jan 05, 2020 6:50 pm

I got the divider to work, by using 2x 220k ohm resistors as R1 and a 470k ohm as R2. I span the range 420/975 mv (in water, in air) vs 1.2/2.5V (water, air) directly from the sensor. Thanks for spotting impedance was the problem.

Online
User avatar
MostlyHarmless
Posts: 145
Joined: Thu Nov 21, 2019 6:25 pm
Location: Pennsylvania, USA

Re: ESP12e: analog reading not working with voltage divider

Post by MostlyHarmless » Sun Jan 05, 2020 6:54 pm

djipey wrote:
Sun Jan 05, 2020 5:32 pm
I'm a beginner in electronics so I'm not sure about what "Can the sensor drive an impedance as low as 320Ω?" really means.
impedance == (effective) resistance (of a circuit)

In this case @pythoncoder meant the resistance of the entire voltage divider, which is 320Ω. The problem here might be that that is way too low of an impedance and for all practical purposes pulls your analog signal to ground, rather than dividing anything (technically it is still dividing something but not enough to measure it with the ADC).
djipey wrote:
Sun Jan 05, 2020 5:32 pm
But I can measure the voltages coming from the sensor, I have a multimeter. Directly from the sensor (no voltage divider), I have 2.5V when the sensor is in the air, and 1.2V when it's in water. When I measure the output of the voltage divider, I get 7 mV. That's really low. So I guess it answers your question.
What do you get from the sensor with the voltage divider attached? IOW the input, rather than the output of the voltage divider. My guesstimate is something around 21mV.
djipey wrote:
Sun Jan 05, 2020 5:32 pm
What can I do to fix the problem?
You can try using resistors with a higher resistance. Like 10KΩ and 22KΩ (or even 100KΩ and 220KΩ). The higher you go, the less the voltage divider will pull down your sensor signal, but at the same time the input impedance of the ADC pin itself will affect the voltage divider. This is because the ADC is actually a resistor wired in parallel to where you currently have the 100Ω. ADCs usually are around 1MΩ. That in parallel to 100Ω is insignificant. But it is significant with a 100KΩ because it changes that part of the voltage divider to effectively 90.9KΩ.


Regards, Jan

Post Reply