I am using an ESP8266 12 F Module with 3 x 1,2 V Batteries. I tried to connect an infamous chinese soil moisture sensor YL 69 like this (LINK) to the anaolog pin of the ESP8266 Module. The Module works from 3,3 Volt on to 5 V and comes with an electronic board that includes a potentiometer

I figured that since I am not going to use the digital output I don't need that extra board between ESP8266 12F and the sensor. The Sensor without the extra board offers two pins.

First Try: First Pin: A0 Pin of ESP Module and Second Pin: Ground of Batteries This got me some readings between 0.00 and 340 but it seemed quite unreliable and reacting slowly to changes.

Second Try: A0 Pin of the ESP module to one pin and Pin4 of the ESP8266 12 F module to the other pin (the idea was that with this method I would be able to completely turn off the sensor while it's not needed and therefore increase durability of the sensor) This got me some readings between 0.00 and 1024. However while using digitalWrite(PIN 4,LOW); I still got readings out of the sensor... how if theres no current flowing?

I tried the same sensor with an NodeMCU Board that contains an ESP8266 chip. I used the extra board and the analog output and got very good and reliable readings.


  1. What could I do to adjust the setup so that the readings with the "naked" ESP8266 module match those of the NodeMCU model.
  2. Why was I able to get some reading at the second try setup when digital pin 4 was turned off?
    1. Is there a way to use the First try method but to shutdown the sensor completely when not needed so that it doesn't draw any current?

UPDATE Thanks again for the help: Here's my solution: I connected VCC to one Pin of the Sensor and Ground via a 10 K resistor to the other Pin. Than I connected the Analog Read Pin from the ESP Module to a point between the 10 K Resistor and the Ground wire and I end up with usable reading between 0 and 1024 although I noticed that the readings reach 1024 quite soon but it is good enough for my uses.

  • 1
    \$\begingroup\$ Some microcontrollers have a sleep feature where the chip enables some type of interrupt pin (I've never used the ESP MCU so I don't know exactly which pin it could be). But I would search on Google on how to enable this "sleep mode" and there could be some code for you. While sleep mode reduces current drawn from the MCU, it will not make it disappear completely. It still needs a very small amount of current in order to wake itself back up. (This is to answer your third question) \$\endgroup\$ – KingDuken Jul 17 '17 at 20:32
  • \$\begingroup\$ Thanks I am quite familiar with the ESP8266 Sleep modes. I am using DeepSleep in order to improve battery performance for other sensors and it worked well. I guess I need to buy a multimeter to test if there's any current drawn by the sensor. \$\endgroup\$ – Peter S Jul 19 '17 at 13:40

This sensor is not a "voltage generator", it is actually a resistance that varies with moisture. To measure it you should make a voltage divider. Connect a 10k resistor from AO to Vcc.

Inspect the original board and you will find this resistor standing between the sensor connector and the OpAmp.

Update: Turning off to increase sensor durability... I assume you are using the sensor as its main purpose - soil moisture measuring. If your ESP is totaly disconnected from any voltage potential like in a battery only operation and no wired communication, it will be fine to reduce the diferential voltage on both pins to 0. I am not sure can you switch the ESP's analog input to digital output - if you can, than you could write a 0 there. If not, you could use a small signal external n-channel MOSFET driven by some of the other pins to short this pin.

This of course will draw some current trough 10k resistor from batteries, which may not be such a good idea for a battery operated device. You could use another small signal p-channel MOSFET to disconnect the pull up resistor. Both p- and n- channel MOSFETS could be driven by a single digital output pin.


simulate this circuit – Schematic created using CircuitLab

If your ESP is also connected to other devices, incl. battery chargers, then a leakage current may flow trough sensor's GND to the soil and cause sensor plates' corrosion. Your option here is to isolate the sensor when it is not used - you can do it with a DPST (or DPDT) relay to disconnect both sensor leads.

  • \$\begingroup\$ Thanks for your elaborate answer. I used the ESP8266 Module with other sensors like an Ultra Sound Module and a 433 MHz transmitter. I powered those modules via pins from the ESP8266 module and by setting these pins Low I made sure there's no current drawn while the module's not needed. I'll try your advice with the 10k resistor. The whole Setup is battery powered so I'll try to set the Powering Pin and the Analog Pin to low/0. \$\endgroup\$ – Peter S Jul 19 '17 at 13:45

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.