Soil moisture monitor

土壌水分モニター ・ 土壤湿度监测

Read soil conductivity and show moisture on the screen.

土の乾き具合を測って画面に表示。水やりのタイミングが分かる。

读取土壤电导率并在屏幕上显示湿度,掌握浇水时机。

Parts (BOM)

PartRolePortsLinks
M5Stack Core2 Controller grove_i2c, grove_analog, grove_uart, mbus official page
Unit Earth (Soil Moisture Sensor) Soil moisture sensor grove_analog official page

Wiring

How to build

Build a simple soil moisture monitor: an M5Stack Core2 reads the Unit Earth sensor stuck in your plant pot and shows the moisture level on its screen, so you know when to water.

  1. Unpack and check parts — You need the M5Stack Core2, the Unit Earth soil moisture sensor, the white Grove cable that comes with the sensor, and a USB-C cable. No tools or soldering required.
  2. Connect the sensor cable — Plug one end of the Grove cable into the Unit Earth sensor. Plug the other end into the BLACK Port.B on the side of the Core2 (Port.B is the analog port the sensor uses). The connector only fits one way.
  3. Place the sensor in soil — Push the bottom (the patterned blade) of the Unit Earth into the soil up to the line. Keep the top electronic part above the soil and dry.
  4. Flash the program — Connect the Core2 to your computer with the USB-C cable. Install UIFlow / Thonny with MicroPython for Core2, paste the code below, and click Run to upload it.
  5. Test and read values — The screen shows a moisture number. Note the value in dry soil, then water the plant: the number should change. Use that to learn your plant's 'time to water' point.

Sample code (micropython)

# Soil moisture monitor for M5Stack Core2 + Unit Earth
# Sensor plugged into Port.B (black, analog).
from m5stack import lcd
from machine import ADC, Pin
import time

# Port.B analog pin on Core2 is GPIO36.
# If you see no change, try Pin(26) instead.
sensor = ADC(Pin(36))
sensor.atten(ADC.ATTN_11DB)   # read the full 0-3.3V range

lcd.clear()
lcd.setCursor(10, 10)
lcd.print("Soil Moisture")

while True:
    raw = sensor.read()       # 0 (wet) ... ~4095 (dry), varies by sensor
    # Turn raw into an easy 0-100% (higher = wetter).
    moisture = int((4095 - raw) * 100 / 4095)
    if moisture < 0:
        moisture = 0
    lcd.fillRect(10, 60, 300, 40, 0x000000)  # erase old number
    lcd.setCursor(10, 60)
    lcd.print("Moisture: %d %%" % moisture)
    time.sleep(2)

Tips & safety

Open the interactive diagram →

UnitKit — describe what you want to build, get a parts list and wiring diagram.