This smart plant watering monitor uses soil moisture and air temperature sensors to track plant conditions on a small OLED display. When soil dries out, the system can automatically trigger a water pump to deliver measured doses, helping keep plants healthy without constant manual checking.
The guide provides a complete wiring diagram, parts list, and step-by-step assembly instructions using an Arduino Uno, DHT22 temperature/humidity sensor, capacitive soil moisture sensor, relay module, and submersible pump. Firmware with calibration routines and safety limits (maximum three 2-second doses per watering cycle) is included, along with serial commands for setup and testing.
Wiring diagram

Gather all the parts
Assemble it in 5 steps
1. Keep both supplies disconnected
Use a 128x64 SSD1306 I2C module, an analog capacitive soil probe, a 3–6 V pump and an active-HIGH DFR0017 relay. Check your parts match before wiring. This build uses USB for the Uno and four alkaline AA cells only for the pump.
- Do not connect the 6 V battery to the Uno 5V pin or USB. Do not switch mains electricity.
2. Connect the air and soil sensors
DHT22 VCC to 3V3, GND to GND, DATA to D2 (air readings). Connect the 10 kΩ resistor between DATA and 3V3. On a bare four-pin DHT22 viewed from its vented front, pins left to right are VCC, DATA, unused, GND. Soil VCC to 3V3, GND to GND and AOUT to A0 (soil reading).
- DHT data uses a 3.3 V pull-up; the firmware only pulls the data line low, not high. Soil output is analog input only. Keep probe electronics above the soil.
3. Connect the screen and relay control
OLED VCC to 5V, GND to GND, SDA to A4 (data), SCL to A5 (clock). Relay VCC to 5V, GND to GND and IN to D7 (pump command). Wire by printed labels, not header position.
- Before adding battery power, confirm the relay is off during reset and disabled mode. This firmware requires active-HIGH control; an active-LOW relay is not interchangeable.
4. Connect the pump circuit
Battery positive goes to relay COM. Relay NO goes to pump positive (red). Pump negative goes to battery negative. Put the diode across the pump: banded cathode to pump positive and unbanded anode to negative. Leave NC unconnected. Do not route pump current through the Uno or breadboard.
- The diode is an additional required part. Reversing it shorts the battery when the relay closes. Keep water away from all electronics. Never run the pump dry.
5. Calibrate and test small doses
Put the pump under water and secure its tube above the reservoir waterline to prevent siphoning. Using the serial monitor at 9600 baud, send d with the soil probe in dry soil; send w in thoroughly watered, drained soil. Send a to enable automatic watering or x to stop. Calibration and enable state reset on every restart.
- Below 30% relative moisture, watering uses 2-second doses at least 60 seconds apart, with at most three doses per enable. Measure the delivered water before trusting this setting. The percentage is a relative calibration, not laboratory water content.
- No reservoir sensor is included. Supervise watering, keep the reservoir filled and do not leave this prototype unattended. A disconnected analog sensor cannot always be detected.
Review all connections
1. Connections between "air" and "Arduino"
2. Connections between "pullup" and "Arduino"
3. Connections between "soil" and "Arduino"
4. Connections between "oled" and "Arduino"
5. Connections between "relay" and "Arduino"
6. Connections between "battery" and "Arduino"
7. Connections between "pump" and "Arduino"
8. Connections between "diode" and "Arduino"
Deploy the firmware
#include <Arduino.h>
#include <Wire.h>
#include <U8x8lib.h>
#include <DHT.h>
#include <math.h>
U8X8_SSD1306_128X64_NONAME_HW_I2C oled(U8X8_PIN_NONE);
DHT air(2, DHT22);
// DFR0017 relay is active HIGH. Change only after testing without pump power.
const uint8_t RELAY=7;
int dryRaw=0, wetRaw=0, raw=0, moisture=-1;
bool haveDry=false, haveWet=false, armed=false, pumping=false;
unsigned long sampled=0, started=0, stopped=0;
uint8_t doses=0;
char previous[8][17] = {};
void line(uint8_t row, const char *text) {
char padded[17]; memset(padded,' ',16); padded[16]=0;
size_t n=strlen(text); if(n>16)n=16; memcpy(padded,text,n);
if(strcmp(previous[row],padded)) { oled.drawString(0,row,padded); strcpy(previous[row],padded); }
}
void stopPump() { digitalWrite(RELAY,LOW); if(pumping) stopped=millis(); pumping=false; }
void setup() {
digitalWrite(RELAY,LOW); pinMode(RELAY,OUTPUT);
Serial.begin(9600); air.begin(); oled.begin(); oled.setPowerSave(0);
oled.setFont(u8x8_font_chroma48medium8_r);
line(0,"Plant monitor");
Serial.println(F("Pump disabled. Send d in dry soil, w in well-watered drained soil; a arms; x stops. Calibration is RAM only. Three 2-second doses max per arm, 60 seconds apart. Never run pump dry."));
stopped=millis();
}
void loop() {
unsigned long now=millis();
if(pumping && now-started>=2000UL) stopPump();
if(Serial.available()) {
char c=Serial.read();
if(c=='x') { armed=false; stopPump(); }
if(c=='d'||c=='w') {
armed=false; stopPump();
long sum=0; for(byte i=0;i<16;i++) sum+=analogRead(A0);
if(c=='d'){ dryRaw=sum/16; haveDry=true; } else { wetRaw=sum/16; haveWet=true; }
Serial.print(F("Dry=")); Serial.print(dryRaw); Serial.print(F(" Wet=")); Serial.println(wetRaw);
}
if(c=='a' && haveDry && haveWet && abs(dryRaw-wetRaw)>50) {
armed=true; doses=0; stopped=now; Serial.println(F("Armed; first dose no sooner than 60 seconds."));
}
}
if(now-sampled<2500UL) return;
sampled=now;
long sum=0; for(byte i=0;i<16;i++) sum+=analogRead(A0); raw=sum/16;
bool valid=raw>5 && raw<1018;
moisture=-1;
if(haveDry&&haveWet&&abs(dryRaw-wetRaw)>50&&valid)
moisture=constrain((long)(raw-dryRaw)*100/(wetRaw-dryRaw),0L,100L);
if(!valid) { armed=false; stopPump(); }
if(armed&&!pumping&&moisture>=0&&moisture<30&&doses<3&&now-stopped>=60000UL) {
digitalWrite(RELAY,HIGH); pumping=true; started=now; doses++;
}
if(doses>=3&&!pumping) armed=false;
float t=air.readTemperature(), h=air.readHumidity();
char b[24], v[10];
if(isnan(t)) line(1,"Temp: error"); else {dtostrf(t,4,1,v); snprintf(b,sizeof b,"Temp: %s C",v); line(1,b);}
if(isnan(h)) line(2,"Humidity: error"); else {dtostrf(h,4,1,v); snprintf(b,sizeof b,"Humidity:%s%%",v); line(2,b);}
snprintf(b,sizeof b,"Soil raw: %d",raw); line(3,b);
if(moisture<0) line(4,"Soil: calibrate"); else {snprintf(b,sizeof b,"Soil: %d%%",moisture); line(4,b);}
line(5,pumping?"Pump: ON":"Pump: OFF");
line(6,armed?"Auto: armed":"Auto: disabled");
line(7,!valid?"Sensor fault": "d dry w wet a go");
Serial.print(F("Raw=")); Serial.print(raw); Serial.print(F(" Soil%=")); Serial.println(moisture);
}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.




