On an ESP8266 I try to analogRead(A0) my soil moisture sensor using a voltage divider but I get unexpected low values.

The MT3608 increases the esp's output voltage from 3.3V to 5.5V which is the recommended voltage for my capacitive soil moisture sensor v1.2 (different to the picture below I use v1.2, not v1.0). When there is no voltage divider in the game and the sensor is dry, the sensor outputs ~4.5V (yellow wire). The output is around ~2.3V when the sensor is completely wet.

For my voltage divider I use a 150 Ohm (R1) and a 39 Ohm (R2) resistor. Given ~4.5V Vin on the yellow wire this should provide me with ~0.9V Vout on the green wire, because Vout=Vin*(R2/(R1+R2)). A voltage <=1V I could safely attach to the esp8266 A0 analog pin. However, using the voltage devider I measure only 8,3mV instead of the expected 0.9V! It drops to 7.7mV when Vin is 2.3V (wet sensor).

enter image description here

What am I doing wrong? Any advise is highly appreciated!

For testing I currently use a board which has a build-in internal voltage divider that allows for up to 3.3V input, however in the final design I need to run everything using an ESP12-E without such an internal divider.

  • If the "V3" is anything like the "V1" then the A0 pin already has a voltage divider in it aimed at 3.3V operation (the analog input of the ESP8266 only handles 1.1V max). You just need to add another resistor instead of a whole voltage divider to adjust the onboard one. 100kΩ should work.
    – Majenko
    Jul 2 at 21:28
  • It looks like my board has a voltage divider on it, however I use the NodeMCU board just for testing and need to run the final circuit with an ESP12-e that doesn't have a build-in voltage divider and expects <=1V analog input. I still wonder why I get this low value of just 8.3mV while I actually expect 900mV
    – mika
    Jul 2 at 21:45
  • Just use the internal divider as part of your design.
    – Majenko
    Jul 2 at 21:49
  • 2
    those resistors are way too low of a value; they are pulling down the output. Multiply your ohms by 100 and it should work.
    – dandavis
    Jul 3 at 7:35
  • 1
    A low-resistance voltage divider draws more current than a high resistance one, even without a measurement device (your ESP) connected at the mid-point. The power supply must be able to supply enough current and still maintain it's voltage. If it isn't, the supply voltage drops.
    – JRobert
    Jul 5 at 12:54

When designing a voltage divider with 2 resistors, there are 2 things to consider:

  • The ratio between R1 and R2, which gives the output voltage: U(out) = U(in) * [R2 / (R1 + R2)]
  • The magnitude of each resistors: to get a 1/2 ratio, you need to have R1 = R2 no matter their value. But depending the value of your resistors (it can be 10Ω, 1kΩ, 100kΩ or 10MΩ for example), you will have a different current travelling through the bridge. The higher the resistors, the lower the current, and vice-versa.

When mesuring voltage inside the voltage divider, the ADC can be considered as a load to the circuit (as shown below). Some forums state that the input resistor of the ESP8266 ADC is around 20MΩ. If the resistors of the bridge are too low, the current will be high and will only travel through the bridge, leaving not enough current for the ADC to measure (electrons are lazy and always take the path of least resistance). On the other hand, if the resistors are too high, the current will be to low to be accurately detected as well.

Voltage divider with load

In most cases, voltage dividers are build with resistors between 10kΩ and 1MΩ. This allows enough current to travel through the ADC to give an accurate measure of the voltage.

As suggested by dandavis comment, choosing (R1 ; R2) = (15kΩ ; 3,9kΩ) or (150kΩ ; 39kΩ) should work in your circuit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.