Friday, 17 July 2026

AI-Based Autonomous Line Following Delivery Robot

AI-Based Autonomous Line-Following Delivery Robot ESP32 + AI Agent + IoT Web Dashboard + n8n Automation + Telegram Voice Alerts + Google Sheets + ThingSpeak Below is a complete project documentation structure suitable for a final-year engineering project, academic project report, prototype demonstration, or product development.
AI-Based Autonomous Line-Following Delivery Robot

AI-Based Autonomous Line-Following Delivery Robot

ESP32 + AI Agent + Agentic IoT + n8n Automation + Telegram Voice Alerts + Google Sheets + ThingSpeak

AI-Powered ESP32 Agentic IoT Autonomous Robot Cloud Dashboard

1. Full Project Description

The AI-Based Autonomous Line-Following Delivery Robot is an intelligent robotic system designed to transport small packages autonomously along a predefined line path.

The robot uses an ESP32 microcontroller as its central processing unit. An IR sensor array detects and follows the path, while ultrasonic sensors detect obstacles and prevent collisions.

The system is connected to the Internet through Wi-Fi and uses an Agentic IoT architecture based on n8n automation. Sensor data, robot status, battery level, power consumption, delivery events, and obstacle information are transmitted to cloud services.

The n8n automation workflow processes the incoming data and automatically performs actions such as Telegram notifications, Telegram voice alerts, Google Sheets data logging, ThingSpeak dashboard updates, and AI-based power consumption prediction.

Project Objective

  • Develop an autonomous line-following delivery robot.
  • Detect and avoid obstacles automatically.
  • Monitor robot status remotely through IoT.
  • Send real-time Telegram notifications.
  • Generate Telegram voice alerts.
  • Store historical data in Google Sheets.
  • Display sensor data on ThingSpeak.
  • Use AI to predict power consumption.
  • Provide a web-based IoT monitoring dashboard.

2. Problem Statement

Traditional short-distance delivery systems require human operators. This increases labor requirements, delivery time, and operational cost. The proposed robot provides an autonomous solution for transporting small packages in indoor environments such as hospitals, warehouses, offices, laboratories, and educational campuses.

3. Proposed Solution

+-------------------------------------------------------+ | AUTONOMOUS DELIVERY ROBOT | | | | IR Sensors -----------+ | | | | | Ultrasonic Sensors ---+--> ESP32 --> Motor Driver | | | | | | Battery Sensor -------+ +--> Motors | | | | Servo Delivery Box | +---------------------------+---------------------------+ | | Wi-Fi v +---------------+ | n8n Automation | +-------+-------+ | +-----------------+------------------+ | | | v v v Telegram Google Sheets ThingSpeak Voice Alert Data Logging Cloud Dashboard | v AI Agent | v Power Prediction Smart Decisions

4. Components List

Component Quantity Purpose
ESP32 Development Board 1 Main controller and Wi-Fi connectivity
IR Line Sensor Array 1 Line detection
Ultrasonic Sensor 1 or 2 Obstacle detection
Motor Driver 1 DC motor control
DC Geared Motors 2 or 4 Robot movement
Robot Chassis 1 Mechanical structure
Servo Motor 1 Delivery box mechanism
Rechargeable Battery 1 Power supply
Voltage Regulator 1 Stable power supply
Buzzer 1 Local warning
LED Indicators Several Status indication
n8n Automation 1 Workflow automation
Telegram Bot 1 Notifications and voice alerts
Google Sheets 1 Cloud data logging
ThingSpeak 1 IoT visualization

5. System Architecture

+---------------------------------------------------------+ | ROBOT HARDWARE | | | | IR Sensor Array | | Ultrasonic Sensor | | Battery Sensor | | Delivery Sensor | | | | | v | | ESP32 | | | | | v | | Motor Driver | | | | | v | | DC Motors | +-------------------------+-------------------------------+ | | Wi-Fi v +----------------+ | n8n Automation | +-------+--------+ | +-----------------+------------------+ | | | v v v AI Agent Telegram Google Sheets | Alerts Logging | v Power Prediction | v ThingSpeak Dashboard

6. Circuit Schematic Diagram

``` +----------------+ | BATTERY | +-------+--------+ | +--------------+--------------+ | | v v +-------------+ +--------------+ | Motor | | Voltage | | Driver | | Regulator | +------+------+ +------+-------+ | | v v DC Motors ESP32 | +-----------------------------+ | +------+------+------+------+------+ | | | | | v v v v v IR1 IR2 IR3 IR4 IR5 Ultrasonic Sensor | v ESP32 Servo Motor | v ESP32 ```

ESP32 Pin Configuration

Device ESP32 Pin
IR Sensor 1 GPIO 32
IR Sensor 2 GPIO 33
IR Sensor 3 GPIO 34
IR Sensor 4 GPIO 35
IR Sensor 5 GPIO 36
Motor IN1 GPIO 25
Motor IN2 GPIO 26
Motor IN3 GPIO 27
Motor IN4 GPIO 14
Motor ENA GPIO 13
Motor ENB GPIO 12
Ultrasonic TRIG GPIO 5
Ultrasonic ECHO GPIO 18
Servo GPIO 23

7. System Flowchart

``` +---------+ | START | +----+----+ | v +----------------+ | Initialize ESP32| +--------+-------+ | v +----------------+ | Connect Wi-Fi | +--------+-------+ | v +----------------+ | Read Sensors | +--------+-------+ | v +----------------+ | Obstacle Found?| +----+-------+---+ | | YES NO | | v v Stop Read Line Robot | | v | Calculate Error | | | v | Motor Control | | +---------+ | v Destination? | +----+----+ | | NO YES | | | v | Stop Robot | | | v | Open Delivery Box | | | v | Delivery Completed | | +---------+ | v Send Cloud Data ```

8. Operating Principle

  1. Power ON the robot.
  2. ESP32 initializes all sensors and actuators.
  3. ESP32 connects to Wi-Fi.
  4. IR sensors detect the line.
  5. The ESP32 calculates the line position.
  6. Motor speed is adjusted to follow the line.
  7. Ultrasonic sensors continuously detect obstacles.
  8. If an obstacle is detected, the robot stops.
  9. n8n receives the robot status through a webhook.
  10. n8n sends Telegram and voice notifications.
  11. Robot data is stored in Google Sheets.
  12. ThingSpeak displays cloud data.
  13. AI predicts future power consumption.

9. ESP32 Source Code

#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <ESP32Servo.h>

const char* ssid = "YOUR_WIFI_NAME";
const char* password = "YOUR_WIFI_PASSWORD";

const char* webhookURL =
"https://YOUR_N8N_DOMAIN/webhook/robot-data";

#define IN1 25
#define IN2 26
#define IN3 27
#define IN4 14

#define ENA 13
#define ENB 12

#define IR1 32
#define IR2 33
#define IR3 34
#define IR4 35
#define IR5 36

#define TRIG_PIN 5
#define ECHO_PIN 18

#define SERVO_PIN 23

Servo deliveryServo;

unsigned long lastSendTime = 0;

void setup() {

    Serial.begin(115200);

    pinMode(IN1, OUTPUT);
    pinMode(IN2, OUTPUT);
    pinMode(IN3, OUTPUT);
    pinMode(IN4, OUTPUT);

    pinMode(ENA, OUTPUT);
    pinMode(ENB, OUTPUT);

    pinMode(IR1, INPUT);
    pinMode(IR2, INPUT);
    pinMode(IR3, INPUT);
    pinMode(IR4, INPUT);
    pinMode(IR5, INPUT);

    pinMode(TRIG_PIN, OUTPUT);
    pinMode(ECHO_PIN, INPUT);

    deliveryServo.attach(SERVO_PIN);
    deliveryServo.write(0);

    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }

    Serial.println("Wi-Fi Connected");
}

long getDistance() {

    digitalWrite(TRIG_PIN, LOW);
    delayMicroseconds(2);

    digitalWrite(TRIG_PIN, HIGH);
    delayMicroseconds(10);

    digitalWrite(TRIG_PIN, LOW);

    long duration = pulseIn(ECHO_PIN, HIGH, 30000);

    long distance = duration * 0.034 / 2;

    return distance;
}

void stopMotors() {

    digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);

    digitalWrite(IN3, LOW);
    digitalWrite(IN4, LOW);
}

void moveForward() {

    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);

    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);

    analogWrite(ENA, 180);
    analogWrite(ENB, 180);
}

void turnLeft() {

    digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);

    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);

    analogWrite(ENA, 100);
    analogWrite(ENB, 200);
}

void turnRight() {

    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);

    digitalWrite(IN3, LOW);
    digitalWrite(IN4, LOW);

    analogWrite(ENA, 200);
    analogWrite(ENB, 100);
}

void lineFollowing() {

    int s1 = digitalRead(IR1);
    int s2 = digitalRead(IR2);
    int s3 = digitalRead(IR3);
    int s4 = digitalRead(IR4);
    int s5 = digitalRead(IR5);

    if (s3 == LOW) {
        moveForward();
    }

    else if (s1 == LOW || s2 == LOW) {
        turnLeft();
    }

    else if (s4 == LOW || s5 == LOW) {
        turnRight();
    }

    else {
        stopMotors();
    }
}

void sendTelemetry(String status) {

    if (WiFi.status() == WL_CONNECTED) {

        HTTPClient http;

        http.begin(webhookURL);

        http.addHeader(
            "Content-Type",
            "application/json"
        );

        StaticJsonDocument<512> doc;

        doc["robot_id"] = "ROBOT_001";
        doc["status"] = status;
        doc["distance"] = getDistance();
        doc["wifi_rssi"] = WiFi.RSSI();
        doc["timestamp"] = millis();

        String jsonData;

        serializeJson(doc, jsonData);

        http.POST(jsonData);

        http.end();
    }
}

void loop() {

    long distance = getDistance();

    if (distance > 0 && distance < 20) {

        stopMotors();

        sendTelemetry(
            "OBSTACLE_DETECTED"
        );

        delay(2000);
    }

    else {

        lineFollowing();
    }

    if (millis() - lastSendTime > 10000) {

        sendTelemetry(
            "ROBOT_RUNNING"
        );

        lastSendTime = millis();
    }

    delay(50);
}

10. n8n Automation Workflow

ESP32 | v Webhook | v Read JSON Data | v Check Robot Status | +---- OBSTACLE DETECTED | | | v | Telegram Alert | | | v | Voice Notification | +---- LOW BATTERY | | | v | Telegram Warning | +---- DELIVERY COMPLETED | v Google Sheets | v ThingSpeak Update

Example n8n Workflow JSON

{
  "name": "AI Delivery Robot Automation",

  "nodes": [

    {
      "name": "ESP32 Webhook",
      "type": "n8n-nodes-base.webhook",
      "parameters": {
        "path": "robot-data",
        "httpMethod": "POST"
      }
    },

    {
      "name": "Robot Status",
      "type": "n8n-nodes-base.if",
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json.status}}",
              "operation": "equal",
              "value2": "OBSTACLE_DETECTED"
            }
          ]
        }
      }
    },

    {
      "name": "Telegram Alert",
      "type": "n8n-nodes-base.telegram",
      "parameters": {
        "text": "Obstacle detected. Robot stopped."
      }
    },

    {
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "parameters": {
        "operation": "append"
      }
    }

  ]

}

11. Telegram Bot Setup

  1. Open Telegram.
  2. Create a new bot.
  3. Copy the Bot Token.
  4. Send a message to the bot.
  5. Configure the Telegram node in n8n.
  6. Enter the Chat ID.
  7. Send automated notifications.

Example Telegram Message

🚨 AI DELIVERY ROBOT ALERT

Robot: ROBOT_001

Status: OBSTACLE DETECTED

Distance: 12 cm

Battery: 67%

Action:
Robot stopped automatically.

12. Telegram Voice Notification Automation

Robot Event | v n8n Workflow | v Generate Alert Text | v Text-to-Speech | v Audio File | v Telegram Voice Message

Example voice message:

"Attention. The autonomous delivery robot has detected an obstacle and has stopped."

13. Google Sheets Integration

Google Sheets is used as a cloud-based data logging platform.

Timestamp Robot ID Status Battery Distance Power Event
10:00 ROBOT_001 RUNNING 90% 40 cm 8.4 W Normal
10:05 ROBOT_001 OBSTACLE 86% 15 cm 9.8 W Warning
10:20 ROBOT_001 DELIVERED 72% 0 cm 7.2 W Complete

14. ThingSpeak Cloud Dashboard

ThingSpeak can display real-time sensor and robot data.

  • Battery Voltage
  • Battery Percentage
  • Motor Current
  • Power Consumption
  • Robot Speed
  • Distance
  • Obstacle Count
  • Delivery Status
ESP32 | v ThingSpeak API | v Cloud Channel | v Charts and Graphs | v Remote Monitoring

15. AI Power Consumption Prediction

The AI system analyzes historical energy consumption and predicts future power requirements.

Input Features

  • Battery Voltage
  • Motor Current
  • Robot Speed
  • Payload Weight
  • Distance Travelled
  • Runtime
  • Obstacle Count
  • Battery Level

Power Calculation

Power = Voltage × Current

Example:

Power = 7.4 × 1.2

Power = 8.88 Watts

AI Decision Logic

IF current consumption > historical average
THEN
    Predict reduced battery runtime

IF battery < 20%
THEN
    Generate LOW BATTERY alert

IF power increases continuously
THEN
    Detect possible motor or mechanical problem

16. AI Agent Decision System

Sensor Data | v ESP32 | v n8n Automation | v AI Agent | v Analyze Current State | +------------------+ | | v v Normal Operation Abnormal Condition | | v v Continue Robot Smart Decision | +---------+---------+ | | | v v v Telegram Stop Robot Log Data

17. Safety Features

  • Emergency stop button.
  • Automatic obstacle detection.
  • Low-battery protection.
  • Motor overload protection.
  • Wi-Fi communication failure handling.
  • Safe mode operation.
  • Automatic robot stop during abnormal conditions.

18. Testing Procedure

Test Input Expected Output
ESP32 Test Power ON ESP32 boots successfully
Wi-Fi Test Network Available Wi-Fi Connected
Line Test Black Line Robot follows line
Obstacle Test Object detected Robot stops
Cloud Test Telemetry Data n8n receives data
Telegram Test Robot Event Alert received
Google Sheets Test Telemetry Data Data logged
ThingSpeak Test Sensor Data Dashboard updated

19. Future Enhancements

Computer Vision

Add camera-based object detection, human detection, package recognition, and visual navigation.

GPS Navigation

Use GPS for outdoor autonomous delivery.

LiDAR Mapping

Create advanced obstacle maps and navigation systems.

Multi-Robot Fleet

AI can assign delivery tasks to multiple autonomous robots.

Predictive Maintenance

Detect motor degradation, battery problems, and mechanical failures.

Voice Command Control

Users can send commands such as Start Delivery, Stop Robot, and Return Home.

20. Final Project Workflow

``` USER | v Web Dashboard / Telegram | v AI Agent | v n8n Cloud | v ESP32 Robot | +---------+---------+ | | | v v v Line Sensor Obstacle Battery | | | +---------+---------+ | v Motor Control | v Autonomous Movement | v Delivery Completed | v Telegram Voice Alert | v Google Sheets | v ThingSpeak Cloud ```

21. Project Conclusion

The AI-Based Autonomous Line-Following Delivery Robot combines robotics, embedded systems, artificial intelligence, IoT, cloud computing, and workflow automation into a single intelligent platform.

The ESP32 provides real-time control of the robot. The IR sensors enable line following, ultrasonic sensors provide obstacle detection, and the motor driver controls the robot movement.

The n8n automation platform provides the connection between the robot, AI Agent, Telegram, Google Sheets, and ThingSpeak. The AI system can analyze historical power consumption and predict future energy usage.

The complete system follows the intelligent automation cycle:

SENSE → PROCESS → DECIDE → ACT → COMMUNICATE → LEARN

© AI-Based Autonomous Line-Following Delivery Robot

ESP32 | AI Agent | Agentic IoT | n8n | Telegram | Google Sheets | ThingSpeak

No comments:

Post a Comment