I am using the YL-69 with a MCP3008 and a Raspberry Pi 3:

enter image description here

I am using the sensor for soil moisture measurement (plant monitoring). This is the code which gets analogue sensor values:

os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')

spi = spidev.SpiDev()

def getAdc (channel):
    if ((channel>7)or(channel<0)):
        return -1

    r = spi.xfer([1, (8+channel) << 4,0])

    adcOut = ((r[1]&3) << 8) + r[2]
    percent = int(round(adcOut/10.24))
    return percent

moist_value = getAdc(0)

The code is not mine I took it from here. The script is run every 30 minutes via a Cronjob.

I have been watering the plant for about three weeks. Then I suddenly got values like this although I have not been watering for days:

enter image description here

After further inspection I saw that one of the LEDs on the YL-69 PCB was off. Also one of the pins on the sensor itsef fell off. It looks a lot like corrosion.

I did some research and fond that:

Continuously powering the sensor module will corrode the moisture sensor overtime. Therefore control the power to the moisture sensor using a GPIO pin of ESP8266

So I wonder can I turn the power on and off without using a ESP8266. I dont see any code for setting GPIO pins to high or low, so I suppose that they are set to high on default and I can change them back to low. Would that power off the YL-69?

1 Answer 1


As the chips may draw up to 40mA, we won't be able to power them directly with GPIO.

In this case you may use a transistor as a switch. Using this method will allow you to power the circuit with classic 5V/GND pins, controlled via a GPIO, adding only few common components to your circuit.

If the provided tutorial isn't enough, you will be able to find more help about the circuit on Electrical Engineering SE

Note that corrosion will happen because of current, but also because of moist. Don't forget to protect your connections and pins, at least with glue, or with specific electronic gel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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