Electronic – ESP8266-12 F/Moisture Sensor Analog Reading Problem

analogesp8266voltage divider

I am using an ESP8266 12 F Module with 3 x 1,2 V Batteries (3,6 Volt)
I connected a chinese soil moisture sensor like this (LINK) to the anaolog pin of the ESP8266 Module. The Module works from 3,3 Volt on to 5 V.

Problem: The Sensor gives back 1024 every time no matter what the actual moisture conditions are. Dry Conditions = 1024, Fully under Water = 1024

I tried the same with an NodeMCU Module which uses the same ESP8266 Chip and there where no problems with the analog reading.

Question 1: I found out that the ESP8266 12 F has an analoge pin capable of reading only values from 0-1 Volt so this could explain the high reading on every measurement when supplied with 3,6 Volt and under wet conditions.I still don't understand why the sensor returns 1024 even if there are absolutely dry conditions. Shouldn't there be a 0 reading?

Question 2: I know that I need some kind of voltage divider e.g. two resistors and would appreciate some hint which ones I should use. The NodeMCU Module seems to have a voltage divider on board and that's why everything worked with this module.

Best Answer

I recently ran into the analog read problem on an ESP12 and found that the problem is referenced here:

https://github.com/esp8266/Arduino/commit/09bb75874deb95c22b4c09e63b842fc1f89eebc3

To resolve the problem I modified core_esp8266_wiring_analog.c as shown here:

extern int __analogRead(uint8_t pin)
{
    // accept both A0 constant and ADC channel number
    if(pin == 17 || pin == 0) {
        return readvdd33() >> 2; // readvdd33 is 12 bit
    }
    return digitalRead(pin) * 1023;
}