Sunday, 16 August 2026

AI Based Autonomous Farming Robot with Crop Health Monitoring

AI-Based Autonomous Farming Robot with Crop Health Monitoring

Below is a complete reference architecture and implementation guide for an autonomous agricultural robot built around ESP32 + ESP32-CAM + IoT + n8n + AI Agent + Telegram + Google Sheets + ThingSpeak.

The design is suitable for a college final-year project, diploma project, research prototype, or working agricultural IoT prototype. I recommend building it in stages rather than trying to make the robot autonomous on day one.

The current Arduino-ESP32 documentation supports Wi-Fi station mode and HTTP/network communication, which fits this architecture well.


1. Project Title

AI-Based Autonomous Farming Robot with Crop Health Monitoring using ESP32, ESP32-CAM, IoT, n8n Automation, AI Agent, Telegram Voice Alerts, Google Sheets and ThingSpeak

Short title

AgriBot AI – Autonomous IoT Farming Robot


2. Project Abstract

The proposed system is an AI-powered autonomous agricultural robot capable of monitoring crop and environmental conditions, detecting abnormal crop conditions, navigating through a farm/greenhouse, and notifying the farmer through Telegram.

The robot uses an ESP32 as the primary IoT controller and an ESP32-CAM for crop-image acquisition. Sensors measure soil moisture, temperature, humidity, light intensity, water level, battery voltage and optionally soil pH.

The collected sensor information is transmitted through Wi-Fi to an n8n automation server. n8n acts as the central workflow and automation layer. It receives data through webhooks, stores measurements in Google Sheets, publishes numerical measurements to ThingSpeak, and passes important events to an AI Agent.

The AI Agent analyzes sensor readings and crop images and determines whether the farm is operating normally or whether an action/alert is required.

For example:

Soil moisture = 19%
Temperature = 35°C
Humidity = 42%
Crop image = possible leaf stress

The AI Agent can produce:

WARNING: Soil moisture is critically low and crop stress is suspected. Irrigation is recommended.

n8n can then automatically send a Telegram text and voice notification to the farmer.

ThingSpeak provides the time-series IoT dashboard, while a separate web dashboard can display the current robot state, environmental parameters, crop-health status and alerts.

ThingSpeak supports REST and MQTT interfaces for channel data, and a channel can contain up to eight fields.


3. Main Objectives

The project has seven major objectives.

Objective 1 — Autonomous movement

The robot should:

  • move forward
  • move backward
  • turn left
  • turn right
  • stop
  • avoid obstacles
  • optionally follow crop rows

Objective 2 — Agricultural sensing

Measure:

  • soil moisture
  • temperature
  • humidity
  • light
  • water-tank level
  • battery voltage
  • optional soil pH
  • optional NPK
  • optional air-quality parameters

Objective 3 — Crop monitoring

Capture crop images using an ESP32-CAM.

The AI system can classify conditions such as:

  • healthy
  • dry/stressed
  • yellowing
  • possible fungal infection
  • possible pest damage
  • abnormal leaf pattern

Important: image AI should be treated as a decision-support system, not as definitive agricultural diagnosis.

Objective 4 — IoT cloud monitoring

Upload sensor data to:

  • ThingSpeak
  • Google Sheets
  • custom web dashboard

Objective 5 — AI Agent

The AI Agent should:

  • interpret sensor data
  • correlate multiple parameters
  • analyze crop-image results
  • prioritize alerts
  • recommend actions
  • answer farmer questions
  • optionally issue approved robot commands

Objective 6 — Automation

Use n8n to automate:

Sensor data
n8n
Data processing
AI Agent
Decision
┌────┼─────┐
↓ ↓ ↓
Sheets ThingSpeak Telegram
Voice Alert

Objective 7 — Voice interaction

The farmer can receive messages such as:

"Alert. Soil moisture in field section A is 17 percent. Irrigation is recommended."

Telegram's current Bot API supports sending voice messages through sendVoice; voice files can be supplied by file ID, URL, or upload.


4. Complete System Architecture

┌─────────────────────────┐
│ FARMER │
│ Smartphone / Telegram │
└────────────┬────────────┘
Text / Voice / Commands
┌────────────────────────────────┐
│ n8n │
│ Automation Server │
│ │
│ Webhook │
│ AI Agent │
│ Rules / Conditions │
│ Google Sheets │
│ Telegram │
│ HTTP Requests │
└───────┬──────────┬─────────────┘
│ │
┌──────────┘ └─────────────┐
▼ ▼
┌───────────────────┐ ┌─────────────────┐
│ AI SERVICE │ │ ThingSpeak │
│ │ │ │
│ Vision │ │ Charts │
│ Reasoning │ │ Sensor history │
│ Speech-to-text │ │ IoT dashboard │
│ Text-to-speech │ └─────────────────┘
└─────────┬─────────┘
┌───────────────────────┐
│ ESP32 Robot │
│ │
│ Wi-Fi │
│ Sensors │
│ Motor control │
│ Pump control │
│ Battery monitoring │
└──────────┬────────────┘
┌────────┴─────────┐
▼ ▼
┌──────────────┐ ┌───────────────┐
│ ESP32-CAM │ │ Motor Driver │
│ Crop Camera │ │ TB6612FNG │
└──────────────┘ └───────┬───────┘
┌────────┴─────────┐
▼ ▼
Motors Pump

5. Recommended Hardware

Main controller

1. ESP32 DevKit

Recommended as the main controller.

Functions:

  • Wi-Fi
  • sensor acquisition
  • motor control
  • pump control
  • communication with n8n
  • local web server
  • robot state management

ESP32 is particularly appropriate here because the Arduino-ESP32 framework provides Wi-Fi and network APIs suitable for IoT applications.


2. ESP32-CAM

Use it as the crop-image node.

Functions:

Capture image
JPEG
Upload to n8n
AI vision analysis
Crop-health result

You can alternatively use an ESP32-S3 camera board if you want more memory/performance.


6. Sensors

Recommended minimum configuration:

Sensor Purpose
Capacitive soil moisture Soil-water estimation
DHT22/SHT31 Temperature + humidity
BH1750 Light intensity
HC-SR04/ToF Obstacle detection
Float switch/ultrasonic Water tank
Voltage divider Battery monitoring
Camera Crop image
pH sensor Soil pH
NPK sensor Nutrient estimation

For a first prototype, use:

soil moisture + temperature/humidity + light + ultrasonic + camera.

Add pH/NPK later.


7. Motor System

I recommend:

ESP32
├── PWM
├── Direction
TB6612FNG
├──── Motor A
└──── Motor B

Use geared DC motors with adequate torque.

Example:

FRONT
┌───────────────┐
│ CAMERA │
│ 📷 │
│ │
│ O O │
│ │
│ Electronics │
│ │
│ O O │
└───────────────┘
REAR

8. Irrigation System

Add:

  • DC water pump
  • water tank
  • tubing
  • MOSFET/relay driver
  • optional solenoid valve
  • water-level sensor

Architecture:

ESP32 GPIO
MOSFET Driver
DC Pump
Water Tank → Tube → Crop

Do not power the pump directly from an ESP32 GPIO.


9. Power Architecture

A practical robot should have separate power paths.

Battery
┌────────┴─────────┐
│ │
▼ ▼
Motor Power DC-DC Buck
│ │
▼ ▼
Motors 5V/3.3V
┌───────────┼────────────┐
▼ ▼ ▼
ESP32 Sensors ESP32-CAM

Use:

  • fuse
  • reverse-polarity protection
  • common ground
  • proper buck converter
  • motor noise suppression
  • emergency stop

10. Electrical Schematic

A conceptual schematic:

+----------------+
| ESP32 |
| |
Soil Moisture -----►| GPIO34 |
DHT22 -------------►| GPIO4 |
BH1750 SDA --------►| GPIO21 |
BH1750 SCL --------►| GPIO22 |
Ultrasonic TRIG --->| GPIO5 |
Ultrasonic ECHO --->| GPIO18 |
| |
| GPIO25 --------+---- Motor A PWM
| GPIO26 --------+---- Motor A IN1
| GPIO27 --------+---- Motor A IN2
| GPIO14 --------+---- Motor B PWM
| GPIO32 --------+---- Motor B IN1
| GPIO33 --------+---- Motor B IN2
| |
| GPIO23 --------+---- Pump MOSFET
└───────┬────────┘
GND
┌────────────────────────────┼────────────────────────┐
│ │ │
▼ ▼ ▼
Motor Driver Sensors ESP32-CAM
├──────── Motor L
└──────── Motor R

Note: GPIO assignments depend on the exact ESP32 board and camera board. ESP32-CAM boards have pins reserved for the camera, so don't blindly use the same pin map on both boards.


11. ESP32-CAM Architecture

I recommend making the camera a separate node rather than forcing the main ESP32 to perform everything.

ESP32 Main
│ Wi-Fi
┌──────┴──────┐
│ │
Sensors ESP32-CAM
Camera
JPEG
n8n
AI Vision

This is much easier to debug.


12. Software Architecture

The project consists of five software layers.

┌─────────────────────────────┐
│ Layer 5: Farmer Interface │
│ Telegram + Web Dashboard │
└──────────────┬──────────────┘
┌──────────────▼──────────────┐
│ Layer 4: AI Agent │
│ Vision + reasoning + tools │
└──────────────┬──────────────┘
┌──────────────▼──────────────┐
│ Layer 3: n8n Automation │
│ workflows + rules + alerts │
└──────────────┬──────────────┘
┌──────────────▼──────────────┐
│ Layer 2: Cloud │
│ ThingSpeak + Google Sheets │
└──────────────┬──────────────┘
┌──────────────▼──────────────┐
│ Layer 1: Robot │
│ ESP32 + sensors + motors │
└─────────────────────────────┘

13. Data Flow

The normal monitoring cycle is:

START
Read sensors
Validate sensor values
Create JSON
Send HTTPS request
n8n Webhook
├──────────────► Google Sheets
├──────────────► ThingSpeak
AI/rule evaluation
├── Normal ───────► Log
└── Abnormal
AI Agent
Alert decision
├────► Telegram text
└────► Telegram voice

14. JSON Data Format

The ESP32 should send structured JSON.

Example:

{
"device_id": "AGRIBOT_001",
"timestamp": 1723800000,
"soil_moisture": 22.5,
"temperature": 34.2,
"humidity": 46.8,
"light_lux": 18450,
"water_level": 68,
"battery": 11.9,
"robot_speed": 80,
"robot_state": "PATROLLING",
"latitude": 0,
"longitude": 0
}

Later you can add:

{
"ph": 6.5,
"npk_n": 42,
"npk_p": 21,
"npk_k": 38,
"crop_health": 87,
"disease_probability": 0.18
}

15. ThingSpeak Configuration

Create a ThingSpeak channel:

Channel name:

AgriBot AI Farm Monitor

Configure fields:

Field 1 = Soil Moisture
Field 2 = Temperature
Field 3 = Humidity
Field 4 = Light
Field 5 = Water Level
Field 6 = Battery
Field 7 = Crop Health
Field 8 = Robot State

ThingSpeak provides REST endpoints for updating channel data, including https://api.thingspeak.com/update.json.

For example:

https://api.thingspeak.com/update.json
?api_key=YOUR_WRITE_KEY
&field1=22
&field2=34
&field3=47
&field4=18000

Keep the Write API Key secret. ThingSpeak uses separate read/write keys for channel access.

Also account for ThingSpeak update limits; the current documentation states a free license permits channel updates every 15 seconds, while paid licenses can update more frequently.

For this project, 30–60 seconds is more than sufficient for normal environmental monitoring.


16. Google Sheets Database

Create:

Spreadsheet: AgriBot_Database

Sheet:

Sensor_Log

Columns:

Timestamp
Device_ID
Soil_Moisture
Temperature
Humidity
Light
Water_Level
Battery
Crop_Health
AI_Status
AI_Recommendation
Robot_State
Alert_Level

Example:

Timestamp Soil Temp Humidity Crop Health Status
10:00 58 29 68 96 Normal
10:10 42 31 60 91 Normal
10:20 24 34 48 73 Warning
10:30 17 36 42 59 Critical

n8n has native Google Sheets operations for working with spreadsheets and sheets.


17. n8n Workflow 1 — Sensor Monitoring

Create:

ESP32
Webhook
JSON Validation
Set / Code
├─────────────┐
▼ ▼
Google Sheets ThingSpeak
│ │
└──────┬──────┘
Rule Engine
┌───┴────┐
│ │
Normal Abnormal
│ │
▼ ▼
END AI Agent

18. n8n Webhook

Create:

Webhook node

Method:

POST

Path:

agribot/sensor

The ESP32 sends:

POST /webhook/agribot/sensor
Content-Type: application/json

Body:

{
"device_id": "AGRIBOT_001",
"soil_moisture": 18.4,
"temperature": 35.8,
"humidity": 42,
"light_lux": 22000,
"water_level": 72,
"battery": 11.8
}

19. n8n Data Validation

Add a Code node.

const d = $json;
const warnings = [];
if (d.soil_moisture < 0 || d.soil_moisture > 100) {
warnings.push("Invalid soil moisture");
}
if (d.temperature < -10 || d.temperature > 70) {
warnings.push("Invalid temperature");
}
if (d.humidity < 0 || d.humidity > 100) {
warnings.push("Invalid humidity");
}
if (d.battery < 9) {
warnings.push("Low battery");
}
return [{
json: {
...d,
valid: warnings.length === 0,
warnings
}
}];

20. Basic Agricultural Rule Engine

Before AI, use deterministic safety rules.

For example:

const d = $json;
let level = "NORMAL";
const alerts = [];
if (d.soil_moisture < 20) {
level = "WARNING";
alerts.push("Soil moisture is low");
}
if (d.soil_moisture < 12) {
level = "CRITICAL";
alerts.push("Soil moisture is critically low");
}
if (d.temperature > 40) {
level = "WARNING";
alerts.push("High temperature");
}
if (d.water_level < 15) {
level = "CRITICAL";
alerts.push("Water tank is nearly empty");
}
if (d.battery < 10.5) {
level = "CRITICAL";
alerts.push("Robot battery is low");
}
return [{
json: {
...d,
alert_level: level,
alerts
}
}];

This is important because safety decisions should not depend entirely on an LLM.


21. AI Agent

The AI Agent receives:

Sensor values
+
Historical information
+
Crop image analysis
+
Robot status

Then generates:

{
"status": "WARNING",
"crop_health": 72,
"reason": "Low soil moisture combined with elevated temperature",
"recommendation": "Inspect irrigation and consider watering",
"urgency": "MEDIUM"
}

n8n currently provides an AI Agent node and supports tool-based agent workflows.


22. Recommended AI Agent System Prompt

Use something similar to:

You are AgriBot AI, an agricultural monitoring assistant.
Your job is to analyze environmental and crop-monitoring information.
Inputs may include:
- soil moisture
- temperature
- humidity
- light
- water level
- battery
- crop-health score
- image-analysis results
- robot state
- historical sensor information
Rules:
1. Never invent sensor measurements.
2. Clearly distinguish measured data from recommendations.
3. If sensor data is missing, say so.
4. Do not claim that an image proves a disease.
5. Treat image results as probable observations.
6. Prioritize safety.
7. A low battery must prevent unnecessary robot movement.
8. A low water level must prevent irrigation commands.
9. Do not directly issue unrestricted motor commands.
10. Any physical robot action must pass a safety/rule layer.
11. Return concise farmer-friendly recommendations.
Output JSON:
{
"status": "NORMAL|WARNING|CRITICAL",
"crop_health": 0-100,
"observations": [],
"recommendation": "",
"urgency": "LOW|MEDIUM|HIGH",
"action_required": true/false
}

23. Crop Image AI

The ESP32-CAM captures:

plant.jpg

The image goes to:

ESP32-CAM
n8n
Vision AI
Structured result

Example output:

{
"crop": "tomato",
"leaf_condition": "yellowing",
"visible_damage": "minor spots",
"estimated_health": 68,
"possible_causes": [
"water stress",
"nutrient deficiency",
"possible disease"
],
"confidence": 0.76
}

Do not make the AI say:

"The plant definitely has fungal disease."

Instead:

"The image shows patterns consistent with possible fungal damage; field verification is recommended."


24. Crop Health Score

A simple prototype score can combine AI and sensor data:

Crop Health Score =
0.50 × Image Health
+ 0.20 × Soil Score
+ 0.10 × Temperature Score
+ 0.10 × Humidity Score
+ 0.10 × Light Score

For example:

Image health = 70
Soil score = 40
Temperature = 60
Humidity = 70
Light = 80

Then:

Health =
0.5(70)
+ 0.2(40)
+ 0.1(60)
+ 0.1(70)
+ 0.1(80)
= 35 + 8 + 6 + 7 + 8
= 64%

So:

0–39 Critical
40–59 Poor
60–74 Warning
75–89 Good
90–100 Excellent

These thresholds should be calibrated for the particular crop and environment rather than treated as universal agricultural standards.


25. Telegram Alert Workflow

n8n:

Sensor
Rule Engine
IF Critical?
├── NO → Store
└── YES
AI Agent
Generate alert text
├───────────────┐
▼ ▼
Telegram Text Text-to-Speech
Telegram Voice

n8n has a built-in Telegram integration and Telegram Trigger node.


26. Example Telegram Text Alert

🚨 AGRIBOT CRITICAL ALERT
Field: Zone A
Soil moisture: 16%
Temperature: 36.2°C
Humidity: 42%
Water tank: 68%
Battery: 11.7V
Crop health: 61%
Observation:
Possible water stress detected.
Recommendation:
Inspect irrigation and provide water if required.
Robot status:
PATROLLING

27. Telegram Voice Alert

The AI generates:

Attention. AgriBot has detected critically low soil moisture in Zone A. Soil moisture is sixteen percent and temperature is thirty-six point two degrees Celsius. Please inspect the irrigation system.

Then:

AI Text
Text-to-Speech
Audio file
Telegram sendVoice
Farmer smartphone

Telegram's Bot API currently documents sendVoice, including supported voice-message formats and a maximum bot voice-message size of 50 MB.


28. Bidirectional Voice Control

The system can also work in the opposite direction:

Farmer
│ 🎤
Telegram
n8n Telegram Trigger
Get voice file
Speech-to-text
AI Agent
Command validation
ESP32

Example:

Farmer says:

"What is the soil moisture?"

AI replies:

"Current soil moisture is 24 percent."

Or:

"Move forward for ten seconds."

The AI Agent should not directly execute this.

Instead:

Voice
AI
Command
Safety Validator
Approved?
├── NO → Reject
└── YES → ESP32

29. Robot Command Format

Use a restricted command protocol.

{
"command": "MOVE",
"direction": "FORWARD",
"duration_ms": 3000,
"speed": 100,
"request_id": "CMD-001"
}

Allowed commands:

MOVE_FORWARD
MOVE_BACKWARD
TURN_LEFT
TURN_RIGHT
STOP
PUMP_ON
PUMP_OFF
CAPTURE_IMAGE
STATUS

Avoid giving the AI arbitrary GPIO access.


30. Command Safety Rules

For example:

const cmd = $json;
const allowedDirections = [
"FORWARD",
"BACKWARD",
"LEFT",
"RIGHT"
];
if (cmd.command === "MOVE") {
if (!allowedDirections.includes(cmd.direction)) {
throw new Error("Invalid direction");
}
if (cmd.duration_ms > 5000) {
throw new Error("Movement duration too long");
}
if (cmd.speed < 0 || cmd.speed > 180) {
throw new Error("Invalid speed");
}
}
return [{json: cmd}];

For a real robot, add:

Obstacle detected?
Battery OK?
Emergency stop?
Communication alive?
Motor current normal?

before movement.


31. ESP32 Main Firmware

The following is a prototype firmware architecture rather than a board-specific production firmware. Pin definitions must be adjusted for your exact ESP32 board.

#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <DHT.h>
#define DHT_PIN 4
#define DHT_TYPE DHT22
#define SOIL_PIN 34
#define PUMP_PIN 23
#define TRIG_PIN 5
#define ECHO_PIN 18
#define MOTOR_A_PWM 25
#define MOTOR_A_IN1 26
#define MOTOR_A_IN2 27
#define MOTOR_B_PWM 14
#define MOTOR_B_IN1 32
#define MOTOR_B_IN2 33
const char* WIFI_SSID = "YOUR_WIFI";
const char* WIFI_PASSWORD = "YOUR_PASSWORD";
const char* N8N_URL =
"https://YOUR-N8N-DOMAIN/webhook/agribot/sensor";
DHT dht(DHT_PIN, DHT_TYPE);
unsigned long lastSend = 0;
const unsigned long SEND_INTERVAL = 30000;
void setup() {
Serial.begin(115200);
dht.begin();
pinMode(SOIL_PIN, INPUT);
pinMode(PUMP_PIN, OUTPUT);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
pinMode(MOTOR_A_IN1, OUTPUT);
pinMode(MOTOR_A_IN2, OUTPUT);
pinMode(MOTOR_B_IN1, OUTPUT);
pinMode(MOTOR_B_IN2, OUTPUT);
pinMode(MOTOR_A_PWM, OUTPUT);
pinMode(MOTOR_B_PWM, OUTPUT);
digitalWrite(PUMP_PIN, LOW);
connectWiFi();
}
void connectWiFi() {
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("WiFi connected");
Serial.println(WiFi.localIP());
}

The Arduino-ESP32 networking APIs support station-mode Wi-Fi and network clients suitable for this type of HTTPS/HTTP IoT communication.


32. Important ESP32 Firmware Improvement

For a production-quality robot, don't put everything inside loop().

Use independent tasks:

Task 1 → Sensor monitoring
Task 2 → Motor control
Task 3 → Wi-Fi communication
Task 4 → Camera communication
Task 5 → Command processing
Task 6 → Safety monitoring

ESP32 FreeRTOS makes this architecture possible.


33. Autonomous Navigation

A simple prototype can use ultrasonic sensors.

FRONT
Ultrasonic
┌──────┴──────┐
│ │
Motor L Motor R

Algorithm:

START
Measure distance
Distance < 30cm?
/ \
YES NO
│ │
▼ ▼
STOP FORWARD
Scan left/right
Which side is clear?
/ \
LEFT RIGHT
│ │
▼ ▼
Turn left Turn right
│ │
└────┬─────┘
FORWARD

34. Better Autonomous Navigation

For an actual field, ultrasonic-only navigation is not enough.

A better system can combine:

Wheel encoders
+
IMU
+
Ultrasonic/ToF
+
Camera
+
GPS/RTK-GPS

Architecture:

GPS ────────┐
IMU ────────┤
Encoders ───┤
Camera ─────┤
Distance ───┤
Navigation
Algorithm
Motor Control

For a college prototype, however, row following + obstacle avoidance is much easier to demonstrate.


35. Crop Row Following

A camera can identify the green crop region.

Simplified algorithm:

Camera frame
Convert RGB → HSV
Green mask
Find crop centroid
Calculate error
error =
image_center - crop_center

Then:

error ≈ 0
Move straight
error > 0
Turn left
error < 0
Turn right

This can be implemented locally without AI for basic navigation.


36. AI vs Conventional Computer Vision

Use both.

Conventional CV

Good for:

  • navigation
  • line following
  • obstacle detection
  • fast response

AI

Good for:

  • crop health
  • image classification
  • natural-language reasoning
  • farmer interaction
  • anomaly interpretation

Therefore:

Real-time control
Conventional algorithm
Agricultural intelligence
AI

This hybrid architecture is much safer than asking an LLM to drive motors directly.


37. n8n Master Workflow

Recommended complete workflow:

┌───────────────┐
│ ESP32 Sensor │
└───────┬───────┘
┌────────────┐
│ Webhook │
└─────┬──────┘
Validate Data
┌─────────────┐
│ Normalize │
└─────┬───────┘
┌───────────┼───────────┐
▼ ▼ ▼
Google Sheets ThingSpeak Database
│ │
└─────┬─────┘
Rule Engine
┌──────┴───────┐
▼ ▼
Normal Abnormal
│ │
│ ▼
│ AI Agent
│ │
│ ┌──────┴──────┐
│ ▼ ▼
│ Recommendation Health
│ │
└───────┬┘
Alert Required?
/ \
NO YES
│ │
▼ ▼
END Telegram Text
Text-to-Speech
Telegram Voice

38. Separate Image Workflow

ESP32-CAM
Capture JPEG
HTTP POST
n8n Webhook
Image preprocessing
AI Vision
Crop health JSON
├──────────► Google Sheets
├──────────► Dashboard
AI Agent
Alert?
├── NO → Store
└── YES → Telegram

39. Telegram Command Workflow

Telegram
Telegram Trigger
┌──────┴──────┐
│ │
Text Voice
│ │
│ Download audio
│ │
│ ▼
│ Speech-to-text
│ │
└──────┬──────┘
AI Agent
Intent Detection
┌────────────┼────────────┐
▼ ▼ ▼
STATUS SENSOR ROBOT
│ │ │
▼ ▼ ▼
Read data Read data Safety check
┌────┴────┐
▼ ▼
Reject Approve
ESP32

40. Farmer Chat Examples

Farmer:

How is the farm?

AI:

Farm status: WARNING.
Soil moisture is 24%.
Temperature is 34°C.
Humidity is 47%.
Crop health is estimated at 78%.
The main concern is decreasing soil moisture.

Farmer:

Is irrigation required?

AI:

Irrigation is recommended for Zone A based on the current
soil-moisture reading.
Current moisture: 18%.
Water tank level: 72%.
Please verify that irrigation lines are functioning before
starting automatic watering.

Farmer:

Move the robot forward.

AI:

I can request forward movement, but the robot must first
pass its obstacle and battery safety checks.

41. Web Dashboard

The dashboard can be a simple HTML page.

Example architecture:

Browser
Dashboard
├──── Current sensor data
├──── Crop health
├──── Robot status
├──── Battery
├──── Water tank
└──── Alerts

42. Dashboard HTML

A basic frontend:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>AgriBot AI Dashboard</title>
<style>
body {
font-family: Arial, sans-serif;
background: #eef7ee;
margin: 0;
}
header {
background: #176b2c;
color: white;
padding: 20px;
}
.container {
padding: 20px;
}
.grid {
display: grid;
grid-template-columns:
repeat(auto-fit, minmax(180px, 1fr));
gap: 15px;
}
.card {
background: white;
border-radius: 12px;
padding: 20px;
box-shadow:
0 3px 10px rgba(0,0,0,.1);
}
.value {
font-size: 30px;
color: #176b2c;
font-weight: bold;
}
.alert {
background: #fff0f0;
border-left: 5px solid red;
}
</style>
</head>
<body>
<header>
<h1>🌱 AgriBot AI</h1>
<p>Autonomous Farming Robot</p>
</header>
<div class="container">
<div class="grid">
<div class="card">
<h3>Soil Moisture</h3>
<div class="value" id="soil">--%</div>
</div>
<div class="card">
<h3>Temperature</h3>
<div class="value" id="temperature">--°C</div>
</div>
<div class="card">
<h3>Humidity</h3>
<div class="value" id="humidity">--%</div>
</div>
<div class="card">
<h3>Crop Health</h3>

43. Dashboard API

The /api/status endpoint can be another n8n webhook.

Browser
│ GET
n8n Webhook
Get latest database record
Return JSON

Example:

{
"soil_moisture": 24,
"temperature": 34.2,
"humidity": 47,
"crop_health": 78,
"battery": 11.9,
"water_level": 68,
"recommendation": "Monitor soil moisture"
}

44. AI Agent Tools

Give the agent carefully selected tools.

AI Agent
├── get_latest_sensor_data()
├── get_sensor_history()
├── get_crop_health()
├── get_robot_status()
├── send_alert()
└── request_robot_command()

Do not give:

execute_any_gpio()
execute_raw_code()

45. Example Tool Schema

A robot command tool could conceptually accept:

{
"command": "STOP"
}

or:

{
"command": "PUMP_ON",
"duration_seconds": 10
}

Then n8n validates it.


46. Robot Safety Controller

Use this hierarchy:

AI
Command Request
n8n Safety Layer
┌───────┴────────┐
▼ ▼
Unsafe Safe
│ │
Reject ▼
ESP32
Local Safety Layer
┌─────────┴────────┐
▼ ▼
Obstacle Emergency
detected stop
│ │
└────────┬─────────┘
STOP

The ESP32 must always have the final local safety authority.


47. Sensor Calibration

Soil Moisture

Do not assume:

ADC 0 = 100%
ADC 4095 = 0%

Calibrate experimentally.

Take readings:

Dry soil → ADCdry
Wet soil → ADCwet

Then:

Moisture =
100 × (ADCdry - ADCactual)
/
(ADCdry - ADCwet)

Clamp:

0–100%

48. Temperature/Humidity

Use DHT22 for a low-cost prototype.

For better reliability:

SHT31 is preferable.


49. Light

BH1750 provides lux.

Example:

250 lux → very dark
2,000 lux → low/moderate
10,000 lux → bright
30,000+ → strong daylight

These values should be interpreted relative to the crop and environment.


50. Battery Monitoring

Use a resistor divider.

For example:

Battery +
R1
├──── ESP32 ADC
R2
GND

Formula:

Vbattery =
VADC × (R1 + R2) / R2

Never exceed the ESP32 ADC input limit.


51. Complete Data Pipeline

The finished system works like this:

FARM
┌────────┼───────────┐
│ │ │
Soil Weather Crop
Sensors Sensors Camera
│ │ │
└────────┼───────────┘
ESP32
Wi-Fi
n8n
┌────────┼───────────┐
│ │ │
▼ ▼ ▼
ThingSpeak Sheets AI Agent
│ │ │
│ │ ┌────┴─────┐
│ │ ▼ ▼
│ │ Decision Health
│ │ │ │
│ │ └────┬─────┘
│ │ ▼
│ │ Telegram
│ │ ┌────┴────┐
│ │ ▼ ▼
│ │ Text Voice
│ │
└────────┴──────────► Dashboard

52. Recommended n8n Workflows

Don't put the entire project into one enormous workflow.

Use six workflows.

Workflow 1

Sensor ingestion

ESP32 → Webhook → Validation → Storage

Workflow 2

AI crop analysis

ESP32-CAM → Webhook → Vision AI → Database

Workflow 3

Alert engine

Sensor event → Rules → AI → Telegram

Workflow 4

Telegram assistant

Telegram → AI Agent → Tools → Telegram

Workflow 5

Robot command

AI command → Safety validator → ESP32

Workflow 6

Dashboard API

Browser → n8n → Latest data → JSON

This makes troubleshooting much easier.


53. Suggested Google Sheets Structure

Sheet 1 — Sensor_Log

timestamp
device_id
soil_moisture
temperature
humidity
light
water_level
battery
robot_state

Sheet 2 — Crop_Health

timestamp
image_id
crop
health_score
observations
possible_causes
confidence

Sheet 3 — Alerts

timestamp
severity
alert_type
message
ai_recommendation
acknowledged

Sheet 4 — Commands

timestamp
user
command
parameters
approved
executed
result

54. AI Agent Decision Example

Input:

{
"soil_moisture": 14,
"temperature": 37,
"humidity": 39,
"water_level": 65,
"battery": 12.0,
"crop_health": 61
}

AI:

{
"status": "CRITICAL",
"crop_health": 61,
"observations": [
"Soil moisture is critically low",
"Temperature is elevated",
"Humidity is relatively low"
],
"recommendation":
"Inspect irrigation and provide water if required",
"urgency": "HIGH",
"action_required": true
}

n8n then sends:

🚨 CRITICAL FARM ALERT
Soil moisture: 14%
Temperature: 37°C
Humidity: 39%
Crop health: 61%
Recommendation:
Inspect irrigation immediately.

55. Autonomous Irrigation Logic

A safer system should use deterministic conditions.

Soil < threshold?
YES
Water tank > minimum?
┌──┴──┐
NO YES
│ │
▼ ▼
Alert Start pump
10 seconds
Stop pump
Wait 2 minutes
Read soil

AI can recommend irrigation, but the actual pump controller should have hard limits.


56. Example Pump Logic

void irrigateSafely() {
float soil = readSoilMoisture();
if (soil >= 30) {
return;
}
// Never irrigate if water level is known to be low.
if (waterLevelPercent() < 15) {
Serial.println("Water level too low");
return;
}
digitalWrite(PUMP_PIN, HIGH);
delay(10000);
digitalWrite(PUMP_PIN, LOW);
}

In a real system, replace the blocking delay with a state machine.


57. Fault Detection

The robot should detect:

Sensor disconnected
Wi-Fi lost
n8n unavailable
Battery low
Motor stalled
Pump timeout
Water empty
Obstacle continuously detected
Camera unavailable

Example:

If Wi-Fi lost:
Continue local safety operation
Store essential data locally
Retry connection
If battery low:
STOP
Send alert when possible
If obstacle detected:
STOP
If pump runs but soil doesn't change:
Generate irrigation fault

58. Offline Operation

This is extremely important for farming.

Don't design:

Internet lost
Robot becomes uncontrollable

Instead:

Internet lost
Local controller continues
Obstacle avoidance
Emergency stop
Sensor monitoring
Store data locally
Internet restored
Upload queued data

59. Local Data Buffer

Use ESP32 flash/NVS or an SD card.

Example:

sensor_001.json
sensor_002.json
sensor_003.json

When Wi-Fi returns:

Local queue
n8n
Google Sheets
ThingSpeak

60. Security Architecture

Never put:

Telegram bot token
AI API key
n8n credentials
ThingSpeak write key
Google credentials

inside publicly shared firmware.

Instead:

ESP32
│ device authentication
n8n
├── API credentials
├── Telegram credentials
├── AI credentials
└── Google credentials

The ESP32 only knows the n8n endpoint and its own authentication mechanism.


61. n8n Security

Use:

HTTPS
Authentication
Webhook secret
Credential manager
Access control
Rate limiting

Do not expose an unauthenticated robot-control webhook to the public Internet.


62. Telegram Security

Only accept commands from authorized Telegram user IDs.

Example:

const allowedUsers = [
123456789
];
const userId = $json.message?.from?.id;
if (!allowedUsers.includes(userId)) {
throw new Error("Unauthorized user");
}
return [{json: $json}];

Telegram's Bot API identifies chats/users through chat IDs, so access control should be applied at the workflow level.


63. AI Voice Assistant

A complete voice conversation becomes:

FARMER
🎤 Voice
Telegram
n8n Trigger
Download Audio
Speech-to-Text
AI Agent
┌─────────┴─────────┐
▼ ▼
Information Command
│ │
▼ ▼
Generate answer Safety validator
│ │
└─────────┬─────────┘
Text-to-Speech
Telegram
🔊 Voice

64. AI Technology Choices

You can implement the AI layer with different providers.

For example:

Option A
OpenAI Vision + reasoning + speech
Option B
Google Gemini Vision + speech
Option C
Local vision model + cloud LLM
Option D
Edge ML + n8n LLM

For an academic prototype, a cloud multimodal model is generally the simplest.

The OpenAI API documentation currently supports text, multimodal/vision, audio and agentic application workflows.


65. ThingSpeak Dashboard

ThingSpeak can provide:

Soil Moisture ───── Line chart
Temperature ─────── Line chart
Humidity ────────── Line chart
Light ───────────── Line chart
Battery ─────────── Gauge/chart
Crop Health ─────── Line chart

The ThingSpeak REST API supports both writing and reading channel data.


66. Recommended User Interface

Your final system can have:

Telegram

/status
/soil
/crop
/robot
/photo
/stop
/help

Web dashboard

┌─────────────────────────────────────┐
│ 🌱 AGRIBOT AI │
├─────────────┬─────────────┬─────────┤
│ Soil 24% │ Temp 34°C │ Hum 47% │
├─────────────┼─────────────┼─────────┤
│ Health 78% │ Battery 92% │ Water68% │
├─────────────┴─────────────┴─────────┤
│ │
│ FARM CAMERA │
│ │
├─────────────────────────────────────┤
│ AI STATUS: WARNING │
│ Monitor soil moisture │
├─────────────────────────────────────┤
│ ROBOT: PATROLLING │
└─────────────────────────────────────┘

67. Full Project Flow

POWER ON
ESP32 Initialization
Wi-Fi Connect
┌──────┴───────┐
│ │
OK FAIL
│ │
▼ ▼
Start Robot Offline Mode
Read Sensors
Check Safety
┌─────┴──────┐
│ │
Safe Unsafe
│ │
▼ ▼
Navigation STOP
Capture Image
Send IoT Data
n8n
┌─────┼───────────┐
▼ ▼ ▼
Sheets ThingSpeak AI
Crop Health
Decision
┌─────────┴─────────┐
▼ ▼
Normal Abnormal
│ │
│ ▼
│ Telegram
│ ┌─────┴────┐
│ ▼ ▼
│ Text Voice
Continue

68. Project Modules

For your report, divide the project into these modules.

Module 1 — Robotic platform

  • chassis
  • wheels
  • motors
  • motor driver
  • battery

Module 2 — ESP32 controller

  • Wi-Fi
  • sensors
  • motor control
  • pump

Module 3 — Camera

  • ESP32-CAM
  • image acquisition

Module 4 — IoT

  • HTTP
  • n8n
  • ThingSpeak

Module 5 — AI

  • crop-image analysis
  • anomaly detection
  • AI Agent

Module 6 — Automation

  • n8n
  • Google Sheets
  • Telegram

Module 7 — Farmer interface

  • Telegram
  • web dashboard
  • voice alerts

69. Development Stages

Do not build everything simultaneously.

Stage 1

ESP32 + one sensor.

ESP32 → Serial Monitor

Stage 2

Add Wi-Fi.

ESP32 → Wi-Fi

Stage 3

Send data to n8n.

ESP32 → n8n Webhook

Stage 4

Add ThingSpeak.

ESP32 → n8n → ThingSpeak

Stage 5

Add Google Sheets.

ESP32 → n8n → Sheets

Stage 6

Add Telegram.

n8n → Telegram

Stage 7

Add AI Agent.

Sensor → AI

Stage 8

Add ESP32-CAM.

Camera → AI Vision

Stage 9

Add motors.

ESP32 → Motor Driver → Motors

Stage 10

Add autonomous navigation.

Stage 11

Add irrigation.

Stage 12

Integrate everything.


70. Testing Plan

Sensor testing

Test:

Dry soil
Wet soil
Normal room
High temperature
Different light conditions

Network testing

Disconnect Wi-Fi.

Verify:

Robot remains safe
Motors stop when required
Data is buffered
Connection retries

AI testing

Provide:

Normal crop
Dry crop
Yellow leaves
Leaf spots
Pest damage

Verify that AI returns structured results.


Telegram testing

Test:

Normal notification
Warning
Critical alert
Voice message
Unauthorized user

Robot testing

Test:

Forward
Backward
Left
Right
Stop
Obstacle
Low battery
Emergency stop

71. Evaluation Parameters

You can evaluate:

Sensor accuracy

Error =
|Measured - Reference|

Soil moisture accuracy

Compare against a calibrated reference.

Obstacle detection

Measure:

Detection distance
False positives
False negatives

AI crop classification

Use:

Accuracy
Precision
Recall
F1 score

Network

Measure:

Sensor → n8n latency
Alert latency
Packet loss

Robot

Measure:

Navigation success rate
Obstacle avoidance rate
Battery endurance

72. Sample Experimental Table

Test Expected Result
Dry soil Warning Pass
Very dry soil Critical alert Pass
High temperature Warning Pass
Low battery Stop Pass
Obstacle Stop Pass
Crop image AI analysis Pass
Telegram alert Message Pass
Voice alert Audio Pass
Google Sheets Row inserted Pass
ThingSpeak Graph updated Pass

73. Advantages

Technical advantages

  • IoT-enabled
  • AI-enabled
  • autonomous navigation
  • cloud dashboard
  • voice alerts
  • remote monitoring
  • historical data
  • modular architecture

Agricultural advantages

  • continuous monitoring
  • reduced manual inspection
  • early detection of abnormal conditions
  • targeted irrigation
  • historical crop information
  • remote farmer notifications

74. Limitations

A realistic project report should explicitly state:

  1. ESP32 is not powerful enough for large vision models locally.
  2. Wi-Fi availability limits Internet-dependent functionality.
  3. Soil sensors require calibration.
  4. Crop-health AI can produce false positives/negatives.
  5. A camera image cannot always identify the real cause of plant stress.
  6. Autonomous navigation in open farms is harder than in greenhouses.
  7. Battery capacity limits operating time.
  8. Weather and lighting affect image analysis.
  9. AI recommendations should not replace professional agronomic decisions.

75. Future Scope

The project can later be upgraded with:

RTK-GPS
Centimeter-level navigation
Multispectral camera
NDVI / vegetation analysis
NPK sensor
Nutrient monitoring
Solar charging
Longer operation
LoRaWAN
Long-range farm communication
Edge AI
Offline crop analysis
Multiple robots
Swarm farming
Digital farm map
Zone-based treatment

76. Advanced Multi-Robot Architecture

Future version:

n8n + AI Agent
┌───────────┼────────────┐
│ │ │
▼ ▼ ▼
Robot 01 Robot 02 Robot 03
│ │ │
Zone A Zone B Zone C
│ │ │
└───────────┼────────────┘
Farm Database

The AI Agent could assign tasks:

Robot 1 → inspect Zone A
Robot 2 → irrigation
Robot 3 → crop image survey

But all physical actions should still pass local safety and authorization checks.


77. Suggested Final Hardware Block Diagram

┌───────────────────┐
│ 12V/24V Battery │
└─────────┬─────────┘
┌───────────────┴───────────────┐
│ │
▼ ▼
Motor Power DC-DC
│ │
▼ ▼
TB6612FNG ESP32
│ │ │
│ ├──── Motor L ├── Soil Sensor
│ └──── Motor R ├── DHT22
│ ├── BH1750
│ ├── Ultrasonic
│ ├── Battery ADC
│ │
│ ├── Pump MOSFET
│ │
│ └── Wi-Fi
└─────────────────────┐
Motors
ESP32-CAM
Camera
Wi-Fi / HTTP
n8n

78. Complete Cloud/AI Architecture

INTERNET
┌───────────────┼─────────────────┐
│ │ │
▼ ▼ ▼
ThingSpeak Google Telegram
Sheets │
▲ ▲ │
│ │ │
└───────────────┼─────────────────┘
┌───────────┐
│ n8n │
│ │
│ Webhooks │
│ Rules │
│ AI Agent │
│ Tools │
└─────┬─────┘
┌─────────┴─────────┐
▼ ▼
AI/Vision TTS/STT
│ │
└─────────┬─────────┘
ESP32
┌───────────┼────────────┐
▼ ▼ ▼
Sensors Motors Pump
ESP32-CAM

79. Recommended Project Folder Structure

AgriBot-AI/
├── esp32/
│ ├── agribot.ino
│ ├── sensors.h
│ ├── motors.h
│ ├── communication.h
│ └── config.h
├── esp32_cam/
│ ├── camera.ino
│ └── camera_config.h
├── n8n/
│ ├── sensor_workflow
│ ├── crop_ai_workflow
│ ├── telegram_workflow
│ ├── robot_command_workflow
│ └── dashboard_workflow
├── dashboard/
│ ├── index.html
│ ├── style.css
│ └── app.js
├── ai/
│ ├── prompts/
│ ├── schemas/
│ └── test_images/
├── documentation/
│ ├── architecture.md
│ ├── hardware.md
│ ├── software.md
│ ├── testing.md
│ └── user_manual.md
└── README.md

80. Final End-to-End Demonstration

For your final project demonstration, use this scenario:

Step 1

Robot starts.

AGRIBOT ONLINE

Step 2

ESP32 reads:

Soil = 18%
Temperature = 35°C
Humidity = 44%
Battery = 12V

Step 3

ESP32 sends JSON to n8n.

Step 4

n8n stores the data.

Step 5

ThingSpeak graph updates.

Step 6

Google Sheets receives a new row.

Step 7

Robot camera captures a leaf.

Step 8

AI analyzes the image.

Estimated crop health: 65%
Observation: leaf yellowing

Step 9

AI combines:

Low soil moisture
+
High temperature
+
Leaf yellowing

Step 10

AI determines:

WARNING — probable water stress

Step 11

n8n sends Telegram:

🌱 AGRIBOT ALERT
Possible crop water stress detected.
Soil moisture: 18%
Temperature: 35°C
Crop health: 65%
Recommendation:
Inspect irrigation in Zone A.

Step 12

n8n generates voice.

Farmer receives:

🔊 "AgriBot warning. Low soil moisture and possible crop water stress have been detected in Zone A. Please inspect irrigation."

Step 13

Farmer asks:

🎤 "What is the current soil moisture?"

Step 14

Telegram → n8n → AI Agent → sensor data.

Step 15

Robot replies:

🔊 "The current soil moisture is eighteen percent."

That demonstrates the complete Agentic IoT + ESP32 + AI + n8n + Telegram + cloud dashboard architecture.


81. Most Important Design Principle

The project should not be:

AI → directly controls motors

It should be:

AI
Recommendation / Command
n8n authorization
Safety validation
ESP32
Local safety controller
├── Obstacle?
├── Battery?
├── Emergency stop?
├── Motor fault?
└── Sensor fault?
MOTOR

This makes the system much more defensible as an engineering project.


82. Recommended Technology Stack

Layer Technology
Main MCU ESP32
Camera ESP32-CAM / ESP32-S3 camera
Firmware Arduino ESP32 / C++
Communication Wi-Fi + HTTPS
Automation n8n
AI Agent n8n AI Agent
Vision Multimodal AI
Voice STT Speech-to-text API
Voice TTS Text-to-speech API
Messaging Telegram Bot
IoT dashboard ThingSpeak
Database/logging Google Sheets
Web dashboard HTML/CSS/JavaScript
Motor driver TB6612FNG
Navigation Ultrasonic/ToF + row following
Irrigation Pump + MOSFET
Power Li-ion/LiFePO4 + buck converter

83. Useful Official Documentation

For implementation, these are the most useful references:


84. Recommended Final Project Name

For a college/project presentation, I would use:

“AgriBot AI: An Autonomous IoT Farming Robot for Crop Health Monitoring and Smart Agriculture using ESP32, AI Agent, n8n Automation, ThingSpeak and Telegram Voice Alerts”

One-line architecture for your presentation

ESP32 + Sensors + ESP32-CAM
Wi-Fi
n8n IoT
AI Agent + Vision + Rules
┌────────┼───────────┐
▼ ▼ ▼
ThingSpeak Google Telegram
Sheets Text + Voice
Web Dashboard

This gives you a strong hardware + embedded + robotics + IoT + cloud + AI + automation + voice interface project rather than just an ESP32 sensor-monitoring project.

No comments:

Post a Comment