Community project

Agricultural Resource Monitoring

Photo of Agricultural Resource Monitoring

JAY SANGHVI

Published November 21, 2026

This agricultural monitoring system uses an ESP32 to track soil moisture, temperature, and humidity while controlling irrigation and motorized equipment. The setup combines low-voltage environmental sensors (BMP280, DHT22) with a 12V power system that drives a dosing pump, Mecanum wheel motor, and servo actuator, all coordinated through an RFID reader and I2C expander for flexible field deployment.

The guide provides a complete wiring diagram, parts list, and step-by-step assembly instructions for connecting the sensor array and motor control rails. Firmware examples demonstrate soil moisture monitoring with pump automation, RFID-based command reception via ESP-NOW wireless protocol, and real-time serial logging of system status.

Wiring diagram

Loading diagram…

Gather all the parts

QtyComponent
1

12V Barrel-Jack Adapter

12 V / 2 A wall adapter with a 5.5 mm / 2.1 mm barrel jack. Used to power motor drivers, LED strips, or boards that need a higher rail.

1

MP1584 Buck Converter

Adjustable buck (step-down) DC-DC converter, 4.5-28 V in -> 0.8-20 V out, ~3 A. Configured to 5 V to step a 9 V / 12 V supply or battery pack down to the board's 5 V rail.

1

BMP280

Barometric pressure and temperature sensor

1

DHT22

Digital temperature and humidity sensor

1

Resistor

10 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

RC522 SPI module (MFRC522)

RC522 SPI module (MFRC522)

1

PCF8574 breakout (non-A)

PCF8574 breakout (non-A)

1

DFRobot MDV 2x2A DC Motor Controller (L298N)

Dual H-bridge motor driver board built on the L298N that drives two brushed DC motors at up to 2 A each from a 4.8-46 V motor supply. Each motor is controlled with one PWM enable pin for speed and one direction pin, and motors connect through screw terminals.

1

12 V two-wire brushed geared Mecanum wheel motor

12 V two-wire brushed geared Mecanum wheel motor

1

Resistor

10 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

12 V two-wire brushed geared Mecanum wheel motor

12 V two-wire brushed geared Mecanum wheel motor

1

Resistor

10 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

DFRobot MDV 2x2A DC Motor Controller (L298N)

Dual H-bridge motor driver board built on the L298N that drives two brushed DC motors at up to 2 A each from a 4.8-46 V motor supply. Each motor is controlled with one PWM enable pin for speed and one direction pin, and motors connect through screw terminals.

1

12 V two-wire brushed geared Mecanum wheel motor

12 V two-wire brushed geared Mecanum wheel motor

1

Resistor

10 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

12 V two-wire brushed geared Mecanum wheel motor

12 V two-wire brushed geared Mecanum wheel motor

1

Resistor

10 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

MG90S Micro Servo

Tower Pro MG90S 9g metal-gear micro servo motor. Controlled via a standard 50 Hz PWM signal (1–2 ms pulse width). Operating voltage 4.8 V–6 V. Three-wire interface: VCC (red), GND (brown/black), and Signal (orange/yellow). Stall torque 1.8 kg·cm at 4.8 V / 2.2 kg·cm at 6 V. Rotation range 0°–180°.

1

MG90S Micro Servo

Tower Pro MG90S 9g metal-gear micro servo motor. Controlled via a standard 50 Hz PWM signal (1–2 ms pulse width). Operating voltage 4.8 V–6 V. Three-wire interface: VCC (red), GND (brown/black), and Signal (orange/yellow). Stall torque 1.8 kg·cm at 4.8 V / 2.2 kg·cm at 6 V. Rotation range 0°–180°.

1

5 V DC dosing pump

5 V DC dosing pump

1

AO3400A

30V 5.7A N-channel enhancement-mode logic-level MOSFET in SOT-23-3L. Vgs(th) typically ~0.7V (max 1.45V at Id=250 uA), fully enhanced at Vgs=2.5V-4.5V. RDS(on) ~26 mOhm at Vgs=4.5V, ~38 mOhm at Vgs=2.5V. Driven directly by 3.3V or 5V microcontroller GPIO/PWM as a low-side switch for loads up to its Id and VDS limits. No firmware library required.

1

1N4007 Diode

General-purpose silicon rectifier diode in DO-204AL (DO-41) axial through-hole package. Rated 1A average forward current and 1000V peak reverse voltage (VRRM). Forward voltage drop ~0.7V at typical load (up to 1.1V at full 1A). Used here in series with LM7805 Vout for reverse polarity protection: anode to LM7805 output, cathode to 5V rail, resulting in ~4.3V on the output rail. Not suitable for high-frequency switching (reverse recovery ~2µs–30µs); intended for DC or 50/60Hz rectification only.

1

Resistor

10 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

220 Ω

Through-hole resistor (current-limiting in series with an LED)

1

74AHCT125 Quad Buffer / Level Shifter

Quad non-inverting buffer with 3-state outputs and active-low output enables, in a breadboard-friendly 14-pin DIP. Powered from 5 V, its TTL-level inputs accept 3.3 V logic, so it is a common one-way 3.3 V to 5 V level shifter for NeoPixel/WS2812 data and other fast digital signals; each output drives up to 8 mA.

Assemble it in 2 steps

1. Wire the low-voltage sensors

Use 3.3 V only. RC522 SDA means SPI chip select. Set PCF8574 address straps all low. Use breakouts with I2C pull-ups to 3.3 V.

2. Wire the motor and actuator rails

Use the DFRobot E/M version of the driver, not a generic IN1–IN4 board. Set buck to 5.0 V before connecting loads. Share ground; do not connect actuator positive to USB-powered ESP32. Check total stall and pump/servo current against supply, driver and buck ratings. Raise wheels and disconnect linkages for first tests. Use plain water only and a blunt guarded demonstration plunger.

Review all connections

1. Connections between "supply" and "ESP32"

FunctionsupplyESP32
power+12V12V
groundGNDGND

2. Connections between "buck" and "ESP32"

FunctionbuckESP32
powerVIN12V
powerVOUT5V
groundGNDGND

3. Connections between "bmp" and "ESP32"

FunctionbmpESP32
powerVCC3V3
groundGNDGND
i2cSDAGPIO 21
i2cSCLGPIO 22

4. Connections between "dht" and "ESP32"

FunctiondhtESP32
powerVCC3V3
groundGNDGND
dataDATAGPIO 32

5. Connections between "dhtpull" and "ESP32"

FunctiondhtpullESP32
powerP13V3
digitalP2 → DHT22 DATAEXT

6. Connections between "rfid" and "ESP32"

FunctionrfidESP32
powerVCC3V3
groundGNDGND
spiSDAGPIO 4
spiSCKGPIO 18
spiMISOGPIO 19
spiMOSIGPIO 23
powerRST3V3

7. Connections between "dir" and "ESP32"

FunctiondirESP32
powerVCC3V3
groundGNDGND
i2cSDAGPIO 21
i2cSCLGPIO 22
groundA0GND
groundA1GND
groundA2GND

8. Connections between "drive1" and "ESP32"

Functiondrive1ESP32
powerVD12V
powerVS12V
groundGNDGND
pwmE1GPIO 14
pwmE2GPIO 27
digitalM1 → PCF8574 breakout (non-A) P0EXT
digitalM2 → PCF8574 breakout (non-A) P1EXT

9. Connections between "wheel1" and "ESP32"

Functionwheel1ESP32
dataA → DFRobot MDV 2x2A DC Motor Controller (L298N) M1+EXT
dataB → DFRobot MDV 2x2A DC Motor Controller (L298N) M1-EXT

10. Connections between "wheel1pull" and "ESP32"

Functionwheel1pullESP32
digitalP1 → DFRobot MDV 2x2A DC Motor Controller (L298N) E1EXT
groundP2GND

11. Connections between "wheel2" and "ESP32"

Functionwheel2ESP32
dataA → DFRobot MDV 2x2A DC Motor Controller (L298N) M2+EXT
dataB → DFRobot MDV 2x2A DC Motor Controller (L298N) M2-EXT

12. Connections between "wheel2pull" and "ESP32"

Functionwheel2pullESP32
digitalP1 → DFRobot MDV 2x2A DC Motor Controller (L298N) E2EXT
groundP2GND

13. Connections between "drive2" and "ESP32"

Functiondrive2ESP32
powerVD12V
powerVS12V
groundGNDGND
pwmE1GPIO 26
pwmE2GPIO 16
digitalM1 → PCF8574 breakout (non-A) P2EXT
digitalM2 → PCF8574 breakout (non-A) P3EXT

14. Connections between "wheel3" and "ESP32"

Functionwheel3ESP32
dataA → DFRobot MDV 2x2A DC Motor Controller (L298N) M1+EXT
dataB → DFRobot MDV 2x2A DC Motor Controller (L298N) M1-EXT

15. Connections between "wheel3pull" and "ESP32"

Functionwheel3pullESP32
digitalP1 → DFRobot MDV 2x2A DC Motor Controller (L298N) E1EXT
groundP2GND

16. Connections between "wheel4" and "ESP32"

Functionwheel4ESP32
dataA → DFRobot MDV 2x2A DC Motor Controller (L298N) M2+EXT
dataB → DFRobot MDV 2x2A DC Motor Controller (L298N) M2-EXT

17. Connections between "wheel4pull" and "ESP32"

Functionwheel4pullESP32
digitalP1 → DFRobot MDV 2x2A DC Motor Controller (L298N) E2EXT
groundP2GND

18. Connections between "nozzle" and "ESP32"

FunctionnozzleESP32
powerVCC5V
groundGNDGND

19. Connections between "punch" and "ESP32"

FunctionpunchESP32
powerVCC5V
groundGNDGND

20. Connections between "dose" and "ESP32"

FunctiondoseESP32
powerPLUS5V
dataMINUS → AO3400A Drain (D)EXT

21. Connections between "dosefet" and "ESP32"

FunctiondosefetESP32
digitalGate (G) → Resistor P1EXT
groundSource (S)GND

22. Connections between "dosediode" and "ESP32"

FunctiondosediodeESP32
powerAnode → 5 V DC dosing pump MINUSEXT
powerCathode → 5 V DC dosing pump PLUSEXT

23. Connections between "dosepull" and "ESP32"

FunctiondosepullESP32
digitalP1 → AO3400A Gate (G)EXT
groundP2GND

24. Connections between "dosefetseries" and "ESP32"

FunctiondosefetseriesESP32
digitalP2GPIO 33

25. Connections between "shift" and "ESP32"

FunctionshiftESP32
powerVCC5V
groundGNDGND
ground1OEGND
digital1AGPIO 13
digital1Y → MG90S Micro Servo SIGEXT
ground2OEGND
digital2AGPIO 25
digital2Y → MG90S Micro Servo SIGEXT
power3OE5V
ground3AGND
power4OE5V
ground4AGND

Deploy the firmware

#include <Arduino.h>
#if defined(ARDUINO_ARCH_AVR)
static constexpr int pump=7, on=450, off=370;
static constexpr int marks[]={130,260,390,520};
bool running=false, timeout=false;
uint32_t started=0;
void setup(){Serial.begin(115200);pinMode(pump,OUTPUT);for(int i=2;i<=5;++i)pinMode(i,OUTPUT);}
void loop(){
 int sum=0;for(int i=0;i<8;++i)sum+=analogRead(A0);int wet=sum/8;
 if(wet<=off){running=false;timeout=false;}
 if(wet>=on&&!running&&!timeout){running=true;started=millis();}
 if(running&&millis()-started>=15000){running=false;timeout=true;}
 digitalWrite(pump,running);for(int i=0;i<4;++i)digitalWrite(i+2,wet>=marks[i]);
 Serial.print(wet);Serial.print(" pump=");Serial.println(timeout?"TIMEOUT":running?"ON":"OFF");delay(200);
}
#elif defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#include <esp_now.h>
#include <esp_wifi.h>
#include <esp_idf_version.h>
#include <ESP32Servo.h>
#include "NodeConfig.h"
static constexpr uint8_t channel=1;
static bool radio=false;
static portMUX_TYPE mux=portMUX_INITIALIZER_UNLOCKED;
static char queued=0;
static void receive(
#if ESP_IDF_VERSION_MAJOR >= 5
 const esp_now_recv_info_t* info,
#else
 const uint8_t* mac,
#endif
 const uint8_t* data,int n){
#if ESP_IDF_VERSION_MAJOR >= 5
 const uint8_t* mac=info->src_addr;
#endif
 if(n!=1 || memcmp(mac,consoleMac,6))return;
 portENTER_CRITICAL(&mux);queued=static_cast<char>(data[0]);portEXIT_CRITICAL(&mux);
}
static char command(){portENTER_CRITICAL(&mux);char c=queued;queued=0;portEXIT_CRITICAL(&mux);return c;}
static void startRadio(){
 WiFi.mode(WIFI_STA);esp_wifi_set_channel(channel,WIFI_SECOND_CHAN_NONE);Serial.println(WiFi.macAddress());
 uint8_t zero[6]={};if(!memcmp(consoleMac,zero,6)||esp_now_init()!=ESP_OK)return;
 esp_now_peer_info_t peer={};memcpy(peer.peer_addr,consoleMac,6);peer.channel=channel;peer.ifidx=WIFI_IF_STA;
 radio=esp_now_add_peer(&peer)==ESP_OK;if(radio)esp_now_register_recv_cb(receive);
}
static void report(const char* s){Serial.println(s);if(radio)esp_now_send(consoleMac,(const uint8_t*)s,strlen(s));}
#if ANNA_NODE
Servo gate;
bool gasAlarm=false, gateOpen=false;
char mode='A';
uint32_t nextRead=0;
// Values are ADC counts after the divider; calibrate against a warmed-up module.
constexpr int gasOn=2400,gasOff=2100;
void setup(){Serial.begin(115200);pinMode(25,OUTPUT);pinMode(26,INPUT_PULLUP);gate.attach(13,1000,2000);gate.write(0);startRadio();}
void loop(){
 char c=command();if(c=='A'||c=='O'||c=='C')mode=c;
 bool local=!digitalRead(26);bool warm=millis()>=180000;
 int gasPin=34; int x=0;for(int i=0;i<16;++i)x+=analogRead(gasPin);x/=16;
 if(warm){if(x>=gasOn)gasAlarm=true;else if(x<=gasOff)gasAlarm=false;}
 bool open=local||gasAlarm||mode=='O';if(open!=gateOpen){gateOpen=open;gate.write(open?90:0);}digitalWrite(25,open);
 if(millis()-nextRead>=1000){nextRead=millis();char s[128];snprintf(s,sizeof(s),"ANNA,%d,%d,%d,%d,%c,%d",x,gateOpen,open,gasAlarm,local?'L':mode,warm);report(s);}delay(20);
}
#else
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>
#include <DHT.h>
#include <MFRC522.h>
DHT dht(32,DHT22);
Adafruit_BMP280 bmp;
MFRC522 rfid(4,255);
Servo nozzle,punch;
const uint8_t enablePins[]={14,27,26,16};
bool unlocked=false,bmpOK=false,denied=false,critLatched=false;
uint32_t driveAt=0,lastRead=0,actionAt=0;
char motion='S',action='S';
int phase=0;
void stop(){for(auto p:enablePins)digitalWrite(p,LOW);motion='S';}
void abortAction(){digitalWrite(33,LOW);nozzle.write(20);punch.write(20);action='S';phase=0;}
void drive(char c){
 const char* keys="FBLRQE";const uint8_t patterns[]={0,15,9,6,5,10};const char* k=strchr(keys,c);if(!k||!c)return;
 if(motion==c){driveAt=millis();return;}
 stop();Wire.beginTransmission(0x20);Wire.write(uint8_t(0xF0|patterns[k-keys]));if(Wire.endTransmission())return;
 for(auto p:enablePins)digitalWrite(p,HIGH);motion=c;driveAt=millis();
}
void beginAction(char c){stop();action=c;phase=0;actionAt=millis();if(c=='D')nozzle.write(75);else punch.write(60);}
void setup(){
 Serial.begin(115200);for(auto p:enablePins)pinMode(p,OUTPUT);stop();pinMode(33,OUTPUT);digitalWrite(33,LOW);
 Wire.begin(21,22);bmpOK=bmp.begin(0x76)||bmp.begin(0x77);dht.begin();SPI.begin(18,19,23,4);rfid.PCD_Init();
 nozzle.attach(13,1000,2000);punch.attach(25,1000,2000);abortAction();startRadio();
}
void loop(){
 if(rfid.PICC_IsNewCardPresent()&&rfid.PICC_ReadCardSerial()){
  Serial.print("UID:");for(int i=0;i<rfid.uid.size;i++)Serial.printf(" %02X",rfid.uid.uidByte[i]);Serial.println();
  if(keyLength&&rfid.uid.size==keyLength&&!memcmp(rfid.uid.uidByte,keyUid,keyLength)){unlocked=!unlocked;stop();abortAction();denied=false;command();}
  else{denied=true;unlocked=false;stop();abortAction();}
  rfid.PICC_HaltA();rfid.PCD_StopCrypto1();
 }
 uint32_t now=millis();char c=command();
 if(c=='S'){stop();abortAction();}
 if(motion!='S'&&now-driveAt>450)stop();
 if(unlocked&&action=='S'&&c&&c!='S'){
   if(c=='D'||c=='W')beginAction(c);else drive(c);
 }
 if(action=='D'&&now-actionAt>=400){if(!phase){digitalWrite(33,HIGH);phase=1;actionAt=now;}else abortAction();}
 if(action=='W'&&now-actionAt>=350)abortAction();
 if(now-lastRead>=2500){
  lastRead=now;float h=dht.readHumidity(),t=bmpOK?bmp.readTemperature():dht.readTemperature();float p=bmpOK?bmp.readPressure()/100.0f:NAN;
  float v=(isfinite(t)&&h>=0&&h<=100)?0.6108f*expf(17.27f*t/(t+237.3f))*(1-h/100):NAN;
  bool critical=isfinite(v)&&v<0.8f;
  if(!critical&&isfinite(v))critLatched=false;
  if(critical&&unlocked&&!critLatched&&action=='S'&&c!='S'){beginAction('D');critLatched=true;}
  const char* risk=!isfinite(v)?"INVALID":v<0.8?"CRITICAL":v<1.2?"HIGH":v<1.6?"MODERATE":v<2?"LOW":"DRY";
  char s[160];snprintf(s,sizeof(s),"KRISHI,%.2f,%.2f,%.2f,%.3f,%s,%d,%c,%c,%d",t,h,p,v,risk,unlocked,motion,action,denied);report(s);
 }
 delay(5);
}
#endif
#endif

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.

Open in Schematik