This project automates irrigation for borewells by monitoring soil moisture and controlling a water pump based on moisture levels. Built around an Arduino Uno, a capacitive soil moisture sensor, and a relay module, the system can operate in manual or automatic modes, with calibration thresholds for dry and wet soil conditions.
The guide provides a complete wiring diagram, parts list, and step-by-step assembly instructions. Firmware is included with serial commands for arming the relay, calibrating moisture thresholds, and toggling between manual pump control and automatic irrigation. Testing procedures ensure safe operation before connecting to an actual pump.
Wiring diagram

Gather all the parts
Assemble it in 2 steps
1. Check the sensor before connecting
The diagram is a reference for the SEN0308. Connect its VCC to 3.3 V, GND to GND, and AOUT to A0. Do not assume another sensor has the same pin order or voltage.
2. Test with the pump disconnected
The relay wiring is only for a verified 5 V module with a driver, 5 V-compatible input, known trigger polarity, and a default-off input during reset. Verify its supply current against the available USB power before using Uno 5 V. The relay and Uno share ground. Test both states and reset with the pump disconnected.
- Disconnect GSM and battery for this USB test. Do not use a breadboard for pump current or connect mains.
Review all connections
1. Connections between "soil" and "Arduino"
2. Connections between "relay" and "Arduino"
Deploy the firmware
#include <Arduino.h>
#include <string.h>
constexpr byte relay=7;
char line[24]; byte n=0; bool discard=false, armed=false, running=false, automatic=false;
byte offLevel=LOW;
int dry=0,wet=0; bool haveDry=false,haveWet=false;
unsigned long last=0, started=0;
void pump(bool on){
if(on&&!running) started=millis();
running=on&&armed;
if(armed) digitalWrite(relay,running?!offLevel:offLevel);
}
void command(){
if(!strcmp(line,"STOP")){automatic=false;pump(false);}
else if(!strcmp(line,"ARM LOW")||!strcmp(line,"ARM HIGH")){
if(!armed){offLevel=!strcmp(line,"ARM LOW")?HIGH:LOW; digitalWrite(relay,offLevel);pinMode(relay,OUTPUT);armed=true;}
automatic=false;pump(false);
} else if(!strcmp(line,"ON")&&armed&&!running){automatic=false;pump(true);}
else if(!strcmp(line,"AUTO")&&armed){automatic=haveDry&&haveWet&&abs(wet-dry)>=20;pump(false);}
else if(!strcmp(line,"DRY")){automatic=false;pump(false);dry=analogRead(A0);haveDry=true;}
else if(!strcmp(line,"WET")){automatic=false;pump(false);wet=analogRead(A0);haveWet=true;}
else if(strcmp(line,"PING")) return;
last=millis();
}
void setup(){Serial.begin(9600);}
void loop(){
while(Serial.available()){
char c=Serial.read();
if(c=='\n'){if(!discard){line[n]=0;command();}n=0;discard=false;}
else if(c!='\r'&&!discard){if(n<sizeof(line)-1)line[n++]=c;else discard=true;}
}
auto now=millis();
if(now-last>3000||(running&&now-started>=15000)){automatic=false;pump(false);}
static unsigned long report=0;
if(now-report<500)return;
report=now;
int raw=analogRead(A0); int pct=-1;
if(haveDry&&haveWet&&abs(wet-dry)>=20)pct=constrain((raw-dry)*100L/(wet-dry),0,100);
if(automatic){if(raw<=1||raw>=1022){automatic=false;pump(false);}else if(pct<30)pump(true);else if(pct>=45)pump(false);}
Serial.print(F("BOREWELL1 "));Serial.print(raw);Serial.print(' ');Serial.print(pct);Serial.print(' ');
Serial.print(armed? (running?F("ON"):F("OFF")):F("DISARMED"));Serial.print(' ');Serial.println(automatic?F("AUTO"):F("MANUAL"));
}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.




