This smart plant care system automates watering and lighting for potted plants using a Raspberry Pi Pico connected to a soil moisture sensor, submersible pump, and full-spectrum LED grow strip. The system monitors soil conditions in real time and can operate in automatic mode to maintain optimal moisture levels, with a 30-minute rest period between waterings to prevent overwatering.
The guide provides a complete wiring diagram showing how to connect the capacitive soil sensor, pump, and LED strip through MOSFET drivers powered by a 12V adapter, along with a parts list, calibration procedure, and web interface firmware. Builders will learn how to set dry and wet soil reference points, control the system remotely through a web browser, and adjust automatic watering behavior to match their plant's needs.
Wiring diagram

Gather all the parts
Assemble it in 4 steps
1. 接上土壤感測器
斷電後,VCC 接 3V3,GND 接地,AOUT 接 GP26。只把探頭插入土裡,接頭留在乾燥處。
2. 接上兩個開關模組
水泵模組 In 接 GP14,燈條模組 In 接 GP15。各用一顆 10 kΩ 電阻把 In 接到 GND,避免開機時誤啟動。水泵和燈條的正線接各自模組輸出端子的正極,負線接 Out。
3. 用一個 12 V 變壓器供電
端子 POS 接燈條模組 V+ 和降壓模組 VIN。端子 NEG 接降壓模組 GND,並與 Pico W 和兩個開關模組共地。先不接水泵和 Pico W,通電用萬用表把 VOUT 調到 5.0 V,再斷電。VOUT 接水泵模組 V+ 和 Micro USB 插頭的 VBUS,插頭 GND 接降壓模組 GND。將插頭插入 Pico W 的 USB 插座,不另外接板上 VBUS 腳。
- 水泵須為 5 V、啟動電流不超過 1 A;降壓模組在 12 V 轉 5 V 時須能持續供應至少 2 A。燈條須為 12 V、最多 6 W。
- 不可把 12 V 接到水泵或 Pico W。部署時拔下供電插頭,再插電腦的 USB 線。
4. 固定水管與燈條
把水泵浸入水箱,固定出水口高於水箱最高水位,防止停泵後繼續虹吸。先對量杯試抽,再把出水管固定在盆土上。燈條及所有電路遠離水花。
- 不要讓水泵空轉;先有人看管試運轉。
Review all connections
1. Connections between "soil" and "Raspberry Pi Pico"
2. Connections between "supply" and "Raspberry Pi Pico"
3. Connections between "jack" and "Raspberry Pi Pico"
4. Connections between "pumpsw" and "Raspberry Pi Pico"
5. Connections between "lampsw" and "Raspberry Pi Pico"
6. Connections between "pumppd" and "Raspberry Pi Pico"
7. Connections between "lamppd" and "Raspberry Pi Pico"
8. Connections between "pump" and "Raspberry Pi Pico"
9. Connections between "lamp" and "Raspberry Pi Pico"
10. Connections between "buck" and "Raspberry Pi Pico"
11. Connections between "usbplug" and "Raspberry Pi Pico"
Deploy the firmware
#include <Arduino.h>
#include <WiFi.h>
#include <WebServer.h>
constexpr int PUMP_PIN=14, LAMP_PIN=15, SOIL_PIN=26;
constexpr uint32_t DOSE=2000, REST=30UL*60*1000;
WebServer web(80);
int dry=-1, wet=-1, raw=0, percent=-1;
bool valid=false, automatic=false, pumping=false, lamp=false, watered=false;
uint32_t started=0, stopped=0, lampStarted=0, sampled=0;
void stopPump(){
digitalWrite(PUMP_PIN,LOW);
if(pumping){stopped=millis(); watered=true;}
pumping=false;
}
void sample(){
int sum=0;
for(int i=0;i<16;i++) sum+=analogRead(SOIL_PIN);
raw=sum/16;
valid=raw>30 && raw<3650;
percent=(valid && dry>=0 && wet>=0 && abs(wet-dry)>=80)
? constrain((raw-dry)*100/(wet-dry),0,100) : -1;
}
bool ready(){return valid && !pumping && (!watered || millis()-stopped>=REST);}
void dose(){if(ready()){started=millis(); pumping=true; digitalWrite(PUMP_PIN,HIGH);}}
void page(){
String s="<!doctype html><html lang='zh-Hant'><meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1'><title>盆栽控制</title><h1>盆栽控制</h1><p>濕度:";
s+=percent<0 ? String("未校正或讀值異常") : String(percent)+"%(相對值)";
s+=";感測原始值:"+String(raw)+"</p><p>自動補水:"+(automatic?String("開"):String("關"))+";植物燈:"+(lamp?String("開"):String("關"))+"</p><p>水泵:";
s+=pumping ? "運轉中" : ready() ? "就緒" : "冷卻中或感測器異常";
s+="</p><form method='post' action='/control'>"
"<button name='cmd' value='dry'>記錄偏乾土壤</button> <button name='cmd' value='wet'>記錄澆透瀝乾的土壤</button><br>"
"<button name='cmd' value='auto'>啟用自動補水</button> <button name='cmd' value='stop'>停泵並關閉自動</button><br>"
"<button name='cmd' value='dose'>試抽 2 秒</button><br>"
"<button name='cmd' value='on'>開燈</button> <button name='cmd' value='off'>關燈</button></form>"
"<p>低於 30% 時補水 2 秒,每次間隔至少 30 分鐘。燈最長連開 12 小時。重啟後需重新校正。</p><a href='/'>更新狀態</a></html>";
web.send(200,"text/html; charset=utf-8",s);
}
void control(){
String cmd=web.arg("cmd");
if(cmd=="dry" || cmd=="wet"){
automatic=false; stopPump(); sample();
if(valid){if(cmd=="dry") dry=raw; else wet=raw;}
sample();
}else if(cmd=="auto"){automatic=percent>=0;}
else if(cmd=="stop"){automatic=false; stopPump();}
else if(cmd=="dose"){dose();}
else if(cmd=="on"){lamp=true; lampStarted=millis(); digitalWrite(LAMP_PIN,HIGH);}
else if(cmd=="off"){lamp=false; digitalWrite(LAMP_PIN,LOW);}
web.sendHeader("Location","/"); web.send(303,"text/plain","");
}
void setup(){
pinMode(PUMP_PIN,OUTPUT); digitalWrite(PUMP_PIN,LOW);
pinMode(LAMP_PIN,OUTPUT); digitalWrite(LAMP_PIN,LOW);
analogReadResolution(12); sample();
Serial.begin(115200);
WiFi.mode(WIFI_AP); WiFi.softAP("Plant-Pico","SoilGarden4827");
Serial.println(WiFi.softAPIP());
web.on("/",HTTP_GET,page); web.on("/control",HTTP_POST,control); web.begin();
}
void loop(){
uint32_t now=millis();
if(pumping && now-started>=DOSE) stopPump();
// Do not process potentially slow network requests while the pump is running.
if(!pumping) web.handleClient();
now=millis();
if(lamp && now-lampStarted>=12UL*60*60*1000){lamp=false; digitalWrite(LAMP_PIN,LOW);}
if(now-sampled>=1000){sampled=now; sample(); if(!valid){automatic=false; stopPump();}}
if(automatic && percent>=0 && percent<30) dose();
delay(1);
}
// Power-only wiring update: pump GP14, light GP15, soil GP26 unchanged.Remix this project
Make it yours in one click
Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.




