Soil Moisture Sensor
Overview
Can be used to detect soil moisture. When the soil lacks water, the sensor output value decreases; otherwise, it increases.
Technical Specifications
Operating voltage: VCC 3.3V -5V
Mounting: 2 screw holes
Data type: Analog sampling value
Pin Definition
Pin |
Definition |
|---|---|
GND |
Ground |
VCC |
Power |
AO |
A nalog sampling value |
NC |
Not connected |
Example Code
The AO port outputs an analog value. Insert the probe into the soil, then use the main controller’s AD converter to read the AO pin. The greater the soil moisture, the greater the AO output.
The mPython Board OLED display shows the soil moisture measurement value. When the measured value is less than 2000, the mPython Board RGB LED lights up.
from mpython import *
from bluebit import SoilHumiditySensor
soilHumidity_0 = SoilHumiditySensor(0)
import time
while True:
oled.fill(0)
oled.DispChar(str(str('Soil moisture: ') + str(soilHumidity_0.get_raw_val())), 0, 0, 1)
oled.show()
if soilHumidity_0.get_raw_val() < 2000:
rgb.fill((int(255), int(0), int(0)))
rgb.write()
time.sleep_ms(1)
time.sleep(1)
else:
rgb.fill( (0, 0, 0) )
rgb.write()
time.sleep_ms(1)