Automatic plant watering

自動水やり機 ・ 自动浇水器

Capacitive soil moisture sensing with a built-in pump waters plants automatically.

土の水分を測って、乾いたら自動でポンプが水をやる。家庭菜園の鉄板。

电容式土壤湿度检测,内置水泵在干燥时自动浇水。家庭园艺首选。

Parts (BOM)

PartRolePortsLinks
M5Stack Core2 Controller grove_i2c, grove_analog, grove_uart, mbus official page
Unit Watering Moisture sensor + pump grove_analog official page

Wiring

How to build

Build a simple automatic plant waterer with M5Stack Core2 and a Watering Unit. The unit measures soil moisture and has a built-in pump; the Core2 reads the moisture level and turns the pump on whenever the soil gets too dry, so your plant gets watered on its own.

  1. Gather your parts — You need: the M5Stack Core2, the Watering Unit (moisture sensor with pump), one Grove cable (usually included with the unit), a small water container, and a USB-C cable to connect the Core2 to your computer.
  2. Place the sensor and pump tubing — Push the Watering Unit's moisture probe into the soil near the plant's roots. Put the pump's water tube into your water container, and point the output tube at the base of the plant. Keep the water container below or beside the pot so it can't spill into the electronics.
  3. Wire it with the Grove cable — The Watering Unit uses an analog (black) connection. Plug one end of the Grove cable into the unit and the other end into the Core2's black Port.B (the analog/IO port). The connectors only fit one way, so don't force them.
  4. Connect to your computer and flash MicroPython — Connect the Core2 to your computer with the USB-C cable. Using a tool like UIFlow/Thonny, make sure MicroPython firmware is on the Core2, then copy the sketch below onto the device and run it.
  5. Calibrate the dry/wet values — Run the sketch and watch the moisture number on the screen. Note the value when the soil is dry and when it is freshly watered. Adjust the DRY_THRESHOLD in the code so the pump turns on at the dryness level you want.
  6. Test the watering — Let the soil be dry (or briefly pull the probe out) so the reading goes above the threshold. The pump should run for a few seconds and water the plant, then stop. Watch one full cycle to confirm it waters and stops correctly before leaving it alone.

Sample code (micropython)

# M5Stack Core2 + Watering Unit (auto plant waterer)
# Wiring: Watering Unit -> Core2 black Port.B (analog/IO)
import time
from machine import Pin, ADC
from m5stack import lcd  # Core2 screen helper

# Port.B pins on Core2: analog input pin 36, pump control pin 26
moist = ADC(Pin(36))
moist.atten(ADC.ATTN_11DB)   # read full 0-3.3V range
pump = Pin(26, Pin.OUT)

DRY_THRESHOLD = 2200   # adjust after calibrating (higher = drier)
WATER_SECONDS = 3      # how long the pump runs each time

while True:
    value = moist.read()        # raw moisture reading
    lcd.clear()
    lcd.print('Moisture: %d' % value, 10, 20)
    if value > DRY_THRESHOLD:    # soil is too dry
        lcd.print('Watering...', 10, 60)
        pump.on()               # turn pump on
        time.sleep(WATER_SECONDS)
        pump.off()              # turn pump off
    time.sleep(5)               # wait before checking again

Tips & safety

Open the interactive diagram →

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