Automatic plant watering
自動水やり機 ・ 自动浇水器
Capacitive soil moisture sensing with a built-in pump waters plants automatically.
土の水分を測って、乾いたら自動でポンプが水をやる。家庭菜園の鉄板。
电容式土壤湿度检测,内置水泵在干燥时自动浇水。家庭园艺首选。
Parts (BOM)
| Part | Role | Ports | Links |
| M5Stack Core2 |
Controller |
grove_i2c, grove_analog, grove_uart, mbus |
official page |
| Unit Watering |
Moisture sensor + pump |
grove_analog |
official page |
Wiring
- M5Stack Core2 → Unit Watering (grove_analog)
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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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
- Safety: the pump moves water near electronics. Keep the Core2, cable, and connectors dry and above the water line. Never let water drip onto the device, and unplug power before adjusting tubing.
- Keep WATER_SECONDS short (a few seconds) and the check interval reasonable, so the pump doesn't overwater or flood the pot. Start small and increase only if needed.
- If the pump never runs or always runs, your DRY_THRESHOLD is off. Read the on-screen number for dry vs wet soil and set the threshold between those two values.
- Don't let the pump run dry: keep enough water in the container, or running the pump with no water can damage it.
Open the interactive diagram →
UnitKit — describe what you want to build, get a parts list and wiring diagram.