Electrical – 3,8 Volt to 1 Volt via Voltage Divider

esp8266voltage divider

I am trying to get an analog reading from a YL-69 Soil Moisture Sensor onto my ESP8266-12F Module.
The ESP8266 12F is powered via 3 AAA 1,2 (so 3,8 Volt when fully charged) Volt Batteries.
The YL-69 Moisture Sensor and the Controller Board need min. 3,3 Volt.

The ESP8266 12F's analog pin is only capable of reading 0-1 Volt. Reading the analog pin gets me 1024 every time no matter what conditions are present. so I tried a voltage divider with 1x 200 Ohm and 1x 100 Ohm resistor to bring down 3,8 to max. 1,18 Volt.
It looks like this:
enter image description here

Problem: I am not sure I did the right thing when trying to build a voltage divider. The reading now gives me values between 34 and 36 and that does not change when conditions are changed. Is the setup shown in the picture correct or did I something wrong? Did I use the wrong resistors or did I simply violate the principles of electrical engineering.

Update: I tried 2K instead of 200 Ohm and 1 K instead of 100 Ohm and now I get values from 272 to 276…. something's still off… Is my setup correct?

Best Answer

The device you have does not provide an analog output- it is a simple resistance comparator (bridge circuit into an LM393 inputs):

enter image description here

Since the LM393 has an open-collector output, your loading it will cause the LED D2 to turn on and will reduce the voltage substantially.

You can use the output as a logic signal into your micro, but there is no analog signal to work with. The switching threshold is set by R2, and at mid-scale is when the sensor is 10K.

You could try using the sensor alone, but you would have to add a resistor (like R2) and a voltage reference (maybe a 1.25V shunt reference + another resistor) to get a sort-of decent result.

This is a particularly crappy moisture sensor since it has DC across the PCB and will not last long. I suggest throwing it in the garbage (by which I mean properly recycling the electronics which probably has lead) and looking for something better.


The output impedance at the 'AC' pin is from 10K to much less, depending on the sensor state. The input impedance of the ESP seems to be fairly high, so you could try 100K+200K with a cap like 10n to ground. However the reading will vary directly with Vcc as others have noted.

Note that you will not be using the board at all except for R1.

So U1, D1/R3, R2 and maybe D2/R4 will serve only to drain your battery.

If you want to add a reference, a MCP1501 with a single resistor replacing R1 would do a much better job and will not vary with battery voltage. It does not require an output capacitor (and should not have a large capacitor added), but a small cap on the input would not hurt. Put the resistor near the reference not near the sensor if you are running any length of wire. Since you would then have a 0-1V output you could dispense with the divider.