Friday, 17 July 2026

AI-Based Emotion Recognition Robot for Human Interaction

AI-Based Emotion Recognition Robot for Human Interaction Complete Project Documentation
AI-Based Emotion Recognition Robot - Complete Project Documentation

🤖 AI-Based Emotion Recognition Robot for Human Interaction

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

Complete Project Description, Components, Circuit Diagram, Flowchart, ESP32 Source Code, n8n Workflow, Telegram Integration, Google Sheets, ThingSpeak, AI Power Prediction and Deployment Guide

1. Project Overview

The AI-Based Emotion Recognition Robot for Human Interaction is an intelligent robotic system designed to recognize human emotional states and respond appropriately through voice, movement, display and IoT automation.

The system combines artificial intelligence, embedded systems, robotics, Internet of Things technology, cloud monitoring and workflow automation.

Complete Technology Stack:
  • ESP32 IoT Controller
  • AI Emotion Recognition
  • AI Agent Decision-Making
  • n8n Workflow Automation
  • Telegram Voice Notifications
  • Google Sheets Data Logging
  • ThingSpeak Cloud Dashboard
  • PHP IoT Web Dashboard
  • Power Consumption Monitoring
  • AI Power Consumption Prediction

2. Main Project Objective

The main objective of this project is to develop an intelligent human-interaction robot capable of recognizing human emotions and responding automatically.

The system detects emotions such as:

  • 😊 Happy
  • 😢 Sad
  • 😡 Angry
  • 😐 Neutral
  • 😨 Fear
  • 😲 Surprise
  • 😴 Tired or Sleepy

After detecting the emotional state, the robot analyzes the information using an AI Agent and performs a suitable action.

3. Complete System Architecture


                 +-------------------------+
                 |       HUMAN USER        |
                 | Face / Voice / Sensors  |
                 +------------+------------+
                              |
                              v
                 +-------------------------+
                 | EMOTION RECOGNITION    |
                 | AI Model / Camera /     |
                 | Voice Analysis          |
                 +------------+------------+
                              |
                              v
                 +-------------------------+
                 |      ESP32 CONTROLLER   |
                 |                         |
                 | Emotion Data            |
                 | Sensor Data             |
                 | Power Monitoring        |
                 +------------+------------+
                              |
                              | Wi-Fi
                              v
                 +-------------------------+
                 |       AI AGENT           |
                 | Emotion Interpretation   |
                 | Decision Making          |
                 +------------+------------+
                              |
                              v
                 +-------------------------+
                 |      n8n AUTOMATION      |
                 +-----+-----+-----+-------+
                       |     |     |
                       v     v     v
                 Telegram Google ThingSpeak
                  Voice    Sheets  Cloud
                  Alert    Logs    Dashboard
                       |
                       v
                 +-------------------------+
                 |       WEB DASHBOARD       |
                 | Emotion Status             |
                 | Robot Status              |
                 | Power Usage               |
                 | AI Prediction             |
                 +-------------------------+

4. Hardware Components

Component Function
ESP32 Development Board Main IoT controller
ESP32-CAM or Camera Module Facial emotion recognition
OLED Display Displays detected emotion
Microphone Module Voice and audio input
MAX98357A / DFPlayer Mini Audio output
Speaker Voice response
Servo Motors Robot head or hand movement
Motor Driver Controls DC motors
DC Motors Robot movement
Ultrasonic Sensor Obstacle detection
DHT22 / BME280 Temperature and humidity monitoring
INA219 Voltage and current measurement
Battery Power supply
LEDs Emotion indication
Buzzer Alert indication

5. ESP32 Pin Configuration


ESP32 GPIO 21  -> I2C SDA

ESP32 GPIO 22  -> I2C SCL

ESP32 GPIO 34  -> Analog Sensor Input

ESP32 GPIO 25  -> Servo Motor

ESP32 GPIO 26  -> Motor Driver IN1

ESP32 GPIO 27  -> Motor Driver IN2

ESP32 GPIO 32  -> Ultrasonic TRIG

ESP32 GPIO 33  -> Ultrasonic ECHO

ESP32 GPIO 4   -> Emotion LED

ESP32 GPIO 16  -> Audio RX

ESP32 GPIO 17  -> Audio TX

6. Circuit Schematic Diagram


                       +--------------------+
                       |       ESP32         |
                       |                    |
             SDA ------| GPIO 21            |
             SCL ------| GPIO 22            |
                       |                    |
 Emotion LED ----------| GPIO 4             |
                       |                    |
 Servo Signal ---------| GPIO 25            |
                       |                    |
 Motor IN1 ------------| GPIO 26            |
 Motor IN2 ------------| GPIO 27            |
                       |                    |
 Ultrasonic TRIG ------| GPIO 32            |
 Ultrasonic ECHO ------| GPIO 33            |
                       |                    |
 INA219 SDA -----------| GPIO 21            |
 INA219 SCL -----------| GPIO 22            |
                       +---------+----------+
                                 |
              +------------------+----------------+
              |                  |                |
              v                  v                v
       +--------------+   +-------------+  +-------------+
       | OLED Display |   | INA219      |  | BME280      |
       |              |   | Power       |  | Environment |
       +--------------+   | Sensor      |  +-------------+
                          +-------------+

                 +------------------+
                 | Camera / AI      |
                 | Emotion Module   |
                 +---------+--------+
                           |
                           v
                    +-------------+
                    | Emotion     |
                    | Detection   |
                    +-------------+

        ESP32 -------- Wi-Fi -------- Internet
                                         |
                +------------------------+--------------------+
                |                        |                    |
                v                        v                    v
             n8n Server              ThingSpeak           Web Server
                |
       +--------+----------+---------+
       |                   |         |
       v                   v         v
   Telegram            Google     AI Agent
   Voice Alert         Sheets

7. Complete Working Principle

Step 1: Human Interaction

The user interacts with the robot by looking at the robot, speaking to the robot, showing facial expressions or asking questions.

Step 2: Emotion Detection

The camera or AI emotion-recognition system analyzes the facial expression and identifies the emotional state.


{
    "emotion": "happy",
    "confidence": 0.94
}

Step 3: ESP32 Processing

The ESP32 receives the emotion data and combines it with sensor information.


Emotion       = SAD

Confidence    = 89%

Temperature   = 29.5 °C

Battery       = 7.4 V

Current       = 320 mA

Step 4: AI Agent Decision

The AI Agent analyzes the emotion and generates an appropriate response.


Input:

Emotion = Sad

Confidence = 89%


AI Output:

Response = "You seem a little sad. I am here with you."

Action = Comfort Mode

Robot Movement = Slow Head Movement

Alert Level = Medium

Step 5: n8n Automation

The ESP32 sends the information to the n8n webhook. n8n processes the data and automatically performs multiple actions.

  • Receives ESP32 data
  • Processes JSON
  • Sends data to AI Agent
  • Generates intelligent response
  • Sends Telegram notification
  • Generates voice notification
  • Stores data in Google Sheets
  • Uploads data to ThingSpeak
  • Updates the IoT web dashboard

8. Complete System Flowchart


                 +-------------+
                 |    START    |
                 +------+------+
                        |
                        v
                 +-------------+
                 | Initialize  |
                 | ESP32       |
                 +------+------+
                        |
                        v
                 +-------------+
                 | Connect WiFi|
                 +------+------+
                        |
                        v
                 +-------------+
                 | Capture Face|
                 | Voice Data  |
                 +------+------+
                        |
                        v
                 +-------------+
                 | Detect      |
                 | Emotion     |
                 +------+------+
                        |
                        v
              +---------------------+
              | Confidence > 60% ?  |
              +----------+----------+
                         |
                +--------+--------+
                |                 |
               NO                YES
                |                 |
                v                 v
        +---------------+  +--------------+
        | Retry Capture |  | Send ESP32   |
        +---------------+  | Emotion Data |
                           +------+-------+
                                  |
                                  v
                           +--------------+
                           | n8n Webhook  |
                           +------+-------+
                                  |
                                  v
                           +--------------+
                           | AI Agent     |
                           | Decision     |
                           +------+-------+
                                  |
                 +----------------+----------------+
                 |                |               |
                 v                v               v
            Telegram         Google Sheets     ThingSpeak
            Voice Alert      Data Logging      Cloud
                 |                |               |
                 +----------------+---------------+
                                  |
                                  v
                           +--------------+
                           | Robot        |
                           | Response     |
                           +------+-------+
                                  |
                                  v
                           +--------------+
                           | Continue Loop|
                           +--------------+

9. Emotion Recognition Logic

The emotion-recognition system may use one of the following architectures.

Option A: Cloud AI


Camera
   |
   v
ESP32-CAM
   |
   v
AI API
   |
   v
Emotion Result
   |
   v
ESP32

Option B: Edge AI


Camera
   |
   v
ESP32-S3 / Edge AI Model
   |
   v
Emotion Result

Option C: Computer Vision Computer


Camera
   |
   v
Python AI Computer
   |
   v
Emotion Detection
   |
   v
ESP32

10. Emotion Response Table

Emotion AI Response Robot Action Alert Level
Happy Encouraging message Fast movement Low
Sad Supportive message Slow movement Medium
Angry Calm response Stop movement High
Fear Reassurance Approach slowly High
Surprise Ask what happened Head movement Low
Neutral Greeting Normal operation Low

11. ESP32 Source Code



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

const char* WIFI_SSID = "YOUR_WIFI_NAME";

const char* WIFI_PASSWORD =
"YOUR_WIFI_PASSWORD";

const char* N8N_WEBHOOK =
"https://YOUR_N8N_SERVER/webhook/emotion-robot";

#define EMOTION_LED 4;

float voltage = 7.4;

float current = 0.32;

float power = 0.0;


void setup() {

    Serial.begin(115200);

    pinMode(
        EMOTION_LED,
        OUTPUT
    );

    WiFi.begin(
        WIFI_SSID,
        WIFI_PASSWORD
    );

    Serial.print(
        "Connecting to WiFi"
    );

    while (
        WiFi.status()
        != WL_CONNECTED
    ) {

        delay(500);

        Serial.print(".");

    }

    Serial.println();

    Serial.println(
        "WiFi Connected"
    );

    Serial.println(
        WiFi.localIP()
    );

}


void loop() {

    String emotion =
        detectEmotion();

    float confidence =
        0.92;

    power =
        voltage * current;

    sendEmotionData(
        emotion,
        confidence,
        voltage,
        current,
        power
    );

    delay(30000);

}


String detectEmotion() {

    String emotions[] = {

        "happy",

        "sad",

        "neutral",

        "angry",

        "surprise"

    };

    int index =
        random(0, 5);

    return emotions[index];

}


void sendEmotionData(

    String emotion,

    float confidence,

    float voltage,

    float current,

    float power

) {

    if (

        WiFi.status()
        == WL_CONNECTED

    ) {

        HTTPClient http;

        http.begin(
            N8N_WEBHOOK
        );

        http.addHeader(

            "Content-Type",

            "application/json"

        );

        DynamicJsonDocument doc(
            1024
        );

        doc["device_id"] =
            "EMOTION_ROBOT_001";

        doc["emotion"] =
            emotion;

        doc["confidence"] =
            confidence;

        doc["voltage"] =
            voltage;

        doc["current"] =
            current;

        doc["power"] =
            power;

        doc["robot_status"] =
            "ONLINE";

        String jsonData;

        serializeJson(
            doc,
            jsonData
        );

        int responseCode =
            http.POST(
                jsonData
            );

        Serial.println(
            "HTTP Response:"
        );

        Serial.println(
            responseCode
        );

        http.end();

    }

}

12. ESP32 JSON Data Format


{
    "device_id":
    "EMOTION_ROBOT_001",

    "emotion":
    "sad",

    "confidence":
    0.89,

    "temperature":
    29.5,

    "humidity":
    58,

    "battery_voltage":
    7.42,

    "current":
    0.32,

    "power_watt":
    2.38,

    "robot_status":
    "ONLINE",

    "location":
    "LAB",

    "timestamp":
    "2026-07-18T07:30:00"
}

13. AI Agent Logic

The AI Agent receives the emotion information and produces an intelligent response.

AI Agent Input


Emotion: SAD

Confidence: 89%

Battery: 7.42 V

Power: 2.38 W

AI Agent Prompt


You are an intelligent emotional interaction robot.

Analyze the following emotion:

Emotion: {{$json.emotion}}

Confidence: {{$json.confidence}}

Generate:

1. A short supportive response.

2. A robot action.

3. An alert level.

4. A suggested voice tone.

Return JSON only.

AI Agent Output


{
    "message":
    "You seem a little sad. I am here to talk with you.",

    "robot_action":
    "COMFORT_MODE",

    "alert_level":
    "MEDIUM",

    "voice_tone":
    "CALM"
}

14. n8n Workflow Architecture


+------------------+
| ESP32 Webhook    |
+--------+---------+
         |
         v
+------------------+
| JSON Parser      |
+--------+---------+
         |
         v
+------------------+
| AI Agent         |
| Emotion Analysis |
+--------+---------+
         |
         v
+------------------+
| IF Node          |
| Emotion Type     |
+----+--------+----+
     |        |
     v        v
  Happy      Sad
     |        |
     +--------+---------+
              |
              v
     +----------------+
     | Telegram Alert |
     +----------------+
              |
              v
     +----------------+
     | Voice Message   |
     +----------------+
              |
              v
     +----------------+
     | Google Sheets   |
     +----------------+
              |
              v
     +----------------+
     | ThingSpeak      |
     +----------------+
              |
              v
     +----------------+
     | Web Dashboard   |
     +----------------+

15. n8n Workflow JSON



{
  "name":
  "AI Emotion Recognition Robot",

  "nodes": [

    {

      "parameters": {

        "httpMethod":
        "POST",

        "path":
        "emotion-robot",

        "responseMode":
        "onReceived"

      },

      "name":
      "ESP32 Webhook",

      "type":
      "n8n-nodes-base.webhook"

    },

    {

      "parameters": {

        "jsCode":

"const data = $json.body || $json;

return [{

json: {

device_id:
data.device_id,

emotion:
data.emotion,

confidence:
data.confidence,

voltage:
data.voltage,

current:
data.current,

power:
data.power,

robot_status:
data.robot_status,

timestamp:
new Date().toISOString()

}

}];"

      },

      "name":
      "Process Emotion Data",

      "type":
      "n8n-nodes-base.code"

    },

    {

      "parameters": {

        "method":
        "POST",

        "url":
        "YOUR_AI_AGENT_ENDPOINT",

        "sendBody":
        true,

        "specifyBody":
        "json",

        "jsonBody":

"={

\"emotion\":
\"{{$json.emotion}}\",

\"confidence\":
\"{{$json.confidence}}\",

\"power\":
\"{{$json.power}}\"

}"

      },

      "name":
      "AI Emotion Agent",

      "type":
      "n8n-nodes-base.httpRequest"

    },

    {

      "parameters": {

        "operation":
        "append",

        "documentId":
        "YOUR_GOOGLE_SHEET_ID",

        "sheetName":
        "EmotionLogs"

      },

      "name":
      "Google Sheets Log",

      "type":
      "n8n-nodes-base.googleSheets"

    },

    {

      "parameters": {

        "chatId":
        "YOUR_TELEGRAM_CHAT_ID",

        "text":

"🤖 Emotion Robot Alert

Emotion:
{{$json.emotion}}

Confidence:
{{$json.confidence}}

Power:
{{$json.power}} W"

      },

      "name":
      "Telegram Alert",

      "type":
      "n8n-nodes-base.telegram"

    }

  ]

}

16. Telegram Bot Setup

Open Telegram and search for BotFather.


/newbot

Create a bot name such as:


Emotion Robot AI Bot

Telegram generates a bot token.


BOT_TOKEN

The token must be kept private.

The Telegram bot is used for:

  • Emotion alerts
  • Robot status alerts
  • Battery alerts
  • Power consumption alerts
  • AI voice notifications

17. Telegram Voice Notification Automation


Emotion Detected

       |

       v

AI Generates Message

       |

       v

Text-to-Speech

       |

       v

Audio File

       |

       v

Telegram Voice Message

Example:


Emotion: SAD

AI Message:

"You seem a little sad.
I am here to support you."

18. Google Sheets Integration

Create a Google Sheet named:


EmotionLogs

Timestamp Device ID Emotion Confidence Temperature Battery Current Power AI Response
2026-07-18 EMOTION_ROBOT_001 Happy 94% 29.5 °C 7.42 V 0.32 A 2.38 W You look happy today!

19. ThingSpeak Cloud Dashboard

Recommended ThingSpeak fields:


Field 1: Emotion Code

Field 2: Emotion Confidence

Field 3: Temperature

Field 4: Humidity

Field 5: Battery Voltage

Field 6: Current

Field 7: Power Consumption

Field 8: Robot Status

Emotion code example:


1 = Happy

2 = Sad

3 = Angry

4 = Neutral

5 = Fear

6 = Surprise

20. PHP IoT Web Dashboard



<?php

$emotion = "HAPPY";

$confidence = 94;

$temperature = 29.5;

$humidity = 58;

$battery = 7.42;

$power = 2.38;

$status = "ONLINE";

?>

<!DOCTYPE html>

<html>

<head>

<title>

AI Emotion Recognition Robot

</title>

</head>

<body>

<h1>

🤖 AI Emotion Recognition Robot

</h1>

<p>

Current Emotion:

<?php echo $emotion; ?>

</p>

<p>

Confidence:

<?php echo $confidence; ?>%

</p>

<p>

Temperature:

<?php echo $temperature; ?> °C

</p>

<p>

Humidity:

<?php echo $humidity; ?>%

</p>

<p>

Battery:

<?php echo $battery; ?> V

</p>

<p>

Power:

<?php echo $power; ?> W

</p>

<p>

Robot Status:

<?php echo $status; ?>

</p>

</body>

</html>

21. Power Consumption Monitoring


Battery

   |

   v

INA219 Sensor

   |

   v

ESP32

   |

   v

Power Calculation

Power is calculated using voltage and current measurement.


Power = Voltage x Current

Example:


Voltage = 7.42 V

Current = 0.32 A

Power = 7.42 x 0.32

Power = 2.37 W

22. AI Power Consumption Prediction

Historical power data is stored in Google Sheets or a cloud database. The AI system analyzes the historical data to predict future power consumption.


Time       Power

08:00      2.1 W

09:00      2.4 W

10:00      2.8 W

11:00      3.1 W

The AI Agent can identify increasing power consumption and generate an alert.


Power usage is increasing.

Expected power consumption
in the next hour = 3.4 W

23. Power Prediction Flowchart


+----------------+
| Power Sensor   |
+-------+--------+
        |
        v
+----------------+
| Collect Data   |
+-------+--------+
        |
        v
+----------------+
| Store History  |
+-------+--------+
        |
        v
+----------------+
| AI Analysis    |
+-------+--------+
        |
        v
+----------------+
| Predict Power  |
+-------+--------+
        |
        v
+----------------+
| Alert if High  |
+----------------+

24. Complete Data Flow


        HUMAN

          |

          v

    +-------------+

    | Camera      |

    | Microphone  |

    +------+------+ 

           |

           v

    +-------------+

    | AI Emotion  |

    | Recognition |

    +------+------+ 

           |

           v

    +-------------+

    | ESP32       |

    | Controller  |

    +------+------+ 

           |

           v

    +-------------+

    | Wi-Fi       |

    +------+------+ 

           |

           v

    +-------------+

    | n8n         |

    | Automation  |

    +------+------+ 

           |

      +----+----+---------+---------+

      |         |         |         |

      v         v         v         v

     AI      Telegram  Google   ThingSpeak

    Agent     Voice     Sheets    Cloud

               Alert

                |

                v

        +---------------+

        | Robot Response |

        +---------------+

25. Real-Time Example

Scenario: User Shows a Sad Expression


Camera:

Emotion = SAD

Confidence = 89%

ESP32 sends:


{

    "emotion": "sad",

    "confidence": 0.89

}

AI Agent generates:


"You seem a little sad.

I am here to talk with you."

Robot action:


Movement = Slow Head Movement

Voice = Calm

LED = Sad Indication

Telegram alert:


🤖 Emotion Alert

Emotion: SAD

Confidence: 89%

AI Action: COMFORT_MODE

26. Advantages

  • Human-friendly robotic interaction
  • Real-time emotion recognition
  • AI-powered decision making
  • IoT cloud connectivity
  • Automated Telegram notifications
  • Voice alerts
  • Google Sheets data storage
  • ThingSpeak visualization
  • Power consumption analysis
  • Expandable architecture
  • Remote monitoring
  • Suitable for academic research

27. Applications

  • Healthcare assistance
  • Elderly care
  • Education
  • Smart homes
  • Social robotics
  • Customer service
  • Human-robot interaction research
  • Emotional wellness support

This system should not be considered a medical diagnostic device.

28. Future Enhancements

  1. Multi-language voice interaction
  2. Advanced facial emotion recognition
  3. Voice emotion recognition
  4. Human identity recognition
  5. Personalized AI behavior
  6. Long-term emotion history analysis
  7. Reinforcement learning
  8. Edge AI processing
  9. Autonomous navigation
  10. Object recognition
  11. Human activity recognition
  12. Mobile application
  13. Mobile push notifications
  14. Cloud-based AI model training
  15. Battery health prediction
  16. Solar charging
  17. Multi-robot communication
  18. Offline AI operation
  19. Advanced speech recognition
  20. Personalized emotional memory

29. Deployment Guide

Hardware Deployment

  1. Assemble ESP32 circuit.
  2. Connect camera module.
  3. Connect sensors.
  4. Connect motor driver.
  5. Connect audio module.
  6. Connect battery.
  7. Test each component individually.

Software Deployment

  1. Install Arduino IDE.
  2. Install ESP32 Board Package.
  3. Install required libraries.
  4. Upload ESP32 firmware.
  5. Configure Wi-Fi.
  6. Create Telegram Bot.
  7. Configure n8n.
  8. Create Google Sheet.
  9. Create ThingSpeak channel.
  10. Deploy PHP dashboard.
  11. Test complete system.

30. Testing Procedure

ESP32 Testing


✓ ESP32 boots

✓ Wi-Fi connects

✓ IP address received

Sensor Testing


✓ Camera works

✓ Temperature sensor works

✓ Power sensor works

✓ Ultrasonic sensor works

Emotion Testing


Happy

Sad

Angry

Neutral

Surprise

n8n Testing


✓ Webhook receives data

✓ AI Agent responds

✓ Telegram notification works

✓ Google Sheets receives data

✓ ThingSpeak receives data

31. Final Project Summary

The AI-Based Emotion Recognition Robot for Human Interaction is a complete AI-powered Agentic IoT project that combines embedded systems, artificial intelligence, robotics, automation and cloud services.


AI Emotion Recognition

        +

ESP32 IoT Controller

        +

AI Agent

        +

n8n Automation

        +

Telegram Voice Alerts

        +

Google Sheets

        +

ThingSpeak Cloud

        +

PHP IoT Dashboard

        +

Power Prediction

The complete system follows the intelligent process:

SENSE → UNDERSTAND → DECIDE → RESPOND → NOTIFY → RECORD → PREDICT

AI-Based Emotion Recognition Robot for Human Interaction

ESP32 + AI Agent + n8n + Telegram + Google Sheets + ThingSpeak + PHP IoT Dashboard

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

AI Smart Voice Controlled Wheelchair for Disabled Persons

"GPIO 26", "Left Motor IN2" => "GPIO 27", "Right Motor IN1" => "GPIO 14", "Right Motor IN2" => "GPIO 12", "Ultrasonic TRIG" => "GPIO 5", "Ultrasonic ECHO" => "GPIO 18", "Battery Voltage Sensor" => "GPIO 34", "Current Sensor" => "GPIO 35", "Temperature Sensor" => "GPIO 32", "Emergency Button" => "GPIO 4", "Buzzer" => "GPIO 2" ]; $workflowSteps = [ "User gives voice command", "Speech is converted to text", "AI Agent identifies the command", "n8n validates the command", "ESP32 receives the command", "Safety sensors are checked", "Motor driver controls the wheelchair", "Sensor data is sent to the cloud", "Google Sheets stores data", "ThingSpeak displays data", "Telegram sends notifications", "AI predicts power consumption" ]; function showSectionTitle($title) { echo "

" . htmlspecialchars($title) . "

"; } ?> <?php echo $projectTitle; ?>

AI + ESP32 + IoT + n8n Automation + Telegram Voice Alerts

Google Sheets + ThingSpeak Cloud Dashboard + AI Power Prediction

The wheelchair is controlled through natural voice commands. The AI Agent understands the user's spoken command and converts it into an appropriate wheelchair movement command.

The ESP32 acts as the main controller. It communicates with motors, sensors, cloud platforms and automation services.

Project Working

  • Control wheelchair using voice commands.
  • Improve mobility for disabled persons.
  • Detect obstacles automatically.
  • Monitor battery voltage and percentage.
  • Measure motor current and power consumption.
  • Send emergency notifications.
  • Use AI for intelligent decision making.
  • Store IoT data in Google Sheets.
  • Visualize data using ThingSpeak.
  • Use n8n for automation.

USER / PATIENT | v VOICE COMMAND | v AI VOICE PROCESSING | v n8n AI AGENT | v ESP32 CONTROLLER | +----------------+ | | v v SENSORS MOTOR DRIVER | | v v CLOUD PLATFORM DC MOTORS | +----------------+ | | | v v v ThingSpeak Google Telegram Sheets Alerts
+----------------------+ | BATTERY | | 12V / 24V | +----------+-----------+ | +--------------+--------------+ | | v v +-------------+ +--------------+ | DC-DC BUCK | | MOTOR DRIVER | | 12V to 5V | | HIGH CURRENT | +------+------+ +------+-------+ | | v v +------------------------------------------+ | ESP32 | | | | GPIO 26/27 ------ LEFT MOTOR CONTROL | | GPIO 14/12 ------ RIGHT MOTOR CONTROL | | | | GPIO 5/18 -------- ULTRASONIC SENSOR | | GPIO 34 ---------- VOLTAGE SENSOR | | GPIO 35 ---------- CURRENT SENSOR | | GPIO 4 ----------- EMERGENCY BUTTON | | GPIO 2 ----------- BUZZER | +------------------------------------------+
$pin): ?>
Device ESP32 Pin
START | v INITIALIZE ESP32 | v CONNECT TO WIFI | v READ SENSORS | v EMERGENCY BUTTON PRESSED? | YES | v STOP MOTORS | SEND TELEGRAM ALERT | v LOOP NO | v OBSTACLE LESS THAN 30 CM? | YES | v STOP MOTORS | SEND WARNING | v LOOP NO | v RECEIVE AI COMMAND | v VALIDATE COMMAND | v CONTROL MOTORS | v SEND DATA TO CLOUD | v LOOP
Voice Command AI Intent

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

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

const char* n8nWebhook =
"https://YOUR-N8N-DOMAIN/webhook/wheelchair-data";

#define LEFT_IN1 26
#define LEFT_IN2 27

#define RIGHT_IN1 14
#define RIGHT_IN2 12

#define TRIG_PIN 5
#define ECHO_PIN 18

#define EMERGENCY_PIN 4
#define BUZZER_PIN 2

String movement = "STOP";

void setup() {

    Serial.begin(115200);

    pinMode(LEFT_IN1, OUTPUT);
    pinMode(LEFT_IN2, OUTPUT);

    pinMode(RIGHT_IN1, OUTPUT);
    pinMode(RIGHT_IN2, OUTPUT);

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

    pinMode(EMERGENCY_PIN, INPUT_PULLUP);
    pinMode(BUZZER_PIN, OUTPUT);

    stopMotors();

    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {

        delay(500);

        Serial.println("Connecting to WiFi...");

    }

    Serial.println("WiFi Connected");

}

void loop() {

    bool emergency =
        digitalRead(EMERGENCY_PIN) == LOW;

    float distance = readDistance();

    if (emergency) {

        stopMotors();

        digitalWrite(BUZZER_PIN, HIGH);

        movement = "EMERGENCY_STOP";

    }

    else if (distance > 0 && distance < 30) {

        stopMotors();

        digitalWrite(BUZZER_PIN, HIGH);

        movement = "OBSTACLE_STOP";

    }

    else {

        digitalWrite(BUZZER_PIN, LOW);

    }

    delay(5000);

}

void moveForward() {

    digitalWrite(LEFT_IN1, HIGH);
    digitalWrite(LEFT_IN2, LOW);

    digitalWrite(RIGHT_IN1, HIGH);
    digitalWrite(RIGHT_IN2, LOW);

    movement = "FORWARD";

}

void moveBackward() {

    digitalWrite(LEFT_IN1, LOW);
    digitalWrite(LEFT_IN2, HIGH);

    digitalWrite(RIGHT_IN1, LOW);
    digitalWrite(RIGHT_IN2, HIGH);

    movement = "BACKWARD";

}

void turnLeft() {

    digitalWrite(LEFT_IN1, LOW);
    digitalWrite(LEFT_IN2, HIGH);

    digitalWrite(RIGHT_IN1, HIGH);
    digitalWrite(RIGHT_IN2, LOW);

    movement = "LEFT";

}

void turnRight() {

    digitalWrite(LEFT_IN1, HIGH);
    digitalWrite(LEFT_IN2, LOW);

    digitalWrite(RIGHT_IN1, LOW);
    digitalWrite(RIGHT_IN2, HIGH);

    movement = "RIGHT";

}

void stopMotors() {

    digitalWrite(LEFT_IN1, LOW);
    digitalWrite(LEFT_IN2, LOW);

    digitalWrite(RIGHT_IN1, LOW);
    digitalWrite(RIGHT_IN2, LOW);

    movement = "STOP";

}

float readDistance() {

    digitalWrite(TRIG_PIN, LOW);

    delayMicroseconds(2);

    digitalWrite(TRIG_PIN, HIGH);

    delayMicroseconds(10);

    digitalWrite(TRIG_PIN, LOW);

    long duration =
        pulseIn(ECHO_PIN, HIGH);

    float distance =
        duration * 0.034 / 2;

    return distance;

}

    
ESP32 | v n8n WEBHOOK | v JSON DATA | v AI AGENT | +------------------+ | | v v LOW BATTERY OBSTACLE | | v v TELEGRAM ALERT MOTOR STOP | v GOOGLE SHEETS | v THINGSPEAK CLOUD

Example n8n JavaScript Code


const data = $json;

let alert = "NORMAL";
let message = "";

if (data.emergency === true) {

    alert = "EMERGENCY";

    message =
    "Emergency stop activated.";

}

else if (data.distance < 30) {

    alert = "OBSTACLE";

    message =
    "Obstacle detected. Wheelchair stopped.";

}

else if (data.battery_percentage < 20) {

    alert = "LOW_BATTERY";

    message =
    "Battery level is low.";

}

return [

    {

        json: {

            ...data,

            alert: alert,

            message: message,

            timestamp:
            new Date().toISOString()

        }

    }

];

    
  1. Open Telegram.
  2. Search for BotFather.
  3. Use the command /newbot.
  4. Create a bot name.
  5. Copy the Telegram Bot Token.
  6. Add Telegram credentials to n8n.
  7. Use Telegram Send Message node.
  8. Use Text-to-Speech for voice alerts.
Example Telegram Alert:

🚨 AI SMART WHEELCHAIR ALERT
Status: EMERGENCY STOP
Battery: 62%
Distance: 18 cm
Movement: STOP
Timestamp Battery Current Power Distance Movement Alert
10:00 78% 3.8 A 47 W 145 cm FORWARD NORMAL
10:05 65% 5.1 A 62 W 20 cm STOP OBSTACLE

ThingSpeak can be used to display real-time sensor information.

  • Field 1: Battery Voltage
  • Field 2: Battery Percentage
  • Field 3: Current
  • Field 4: Power Consumption
  • Field 5: Distance
  • Field 6: Temperature
  • Field 7: Movement Status
  • Field 8: Emergency Status

The system calculates electrical power using:

Power = Voltage × Current Example: Voltage = 12.4 V Current = 3.8 A Power = 12.4 × 3.8 Power = 47.12 Watts

Historical data from Google Sheets and ThingSpeak can be analyzed to predict future energy consumption.

HIGH CURRENT + LOW BATTERY + HIGH TEMPERATURE | v HIGH POWER CONSUMPTION | v AI PREDICTION | v TELEGRAM WARNING
The safety system has the highest priority.

Emergency Button → Immediate Motor Stop
Obstacle Detected → Automatic Motor Stop
Wi-Fi Failure → Safe Stop Mode
Low Battery → Warning Alert
Invalid AI Command → No Movement
  • AI Camera-Based Object Detection
  • GPS Tracking
  • Fall Detection
  • Offline Voice Recognition
  • Advanced AI Power Prediction
  • Health Monitoring Sensors
  • Mobile Application
  • Autonomous Navigation
  • Obstacle Avoidance Using AI Vision
  1. Assemble the wheelchair motors.
  2. Connect motor driver to ESP32.
  3. Install ultrasonic and safety sensors.
  4. Install emergency stop button.
  5. Upload ESP32 firmware.
  6. Connect ESP32 to Wi-Fi.
  7. Create n8n webhook.
  8. Configure Telegram Bot.
  9. Connect Google Sheets.
  10. Create ThingSpeak channel.
  11. Configure AI Agent.
  12. Test voice commands.
  13. Test obstacle detection.
  14. Test emergency stop.
  15. Perform complete safety testing.

The AI Smart Voice-Controlled Wheelchair combines artificial intelligence, IoT, ESP32, voice recognition, n8n automation, Telegram notifications, Google Sheets and ThingSpeak Cloud.

The system follows an Agentic IoT architecture:

SENSE ↓ UNDERSTAND ↓ ANALYZE ↓ DECIDE ↓ ACT ↓ NOTIFY ↓ PREDICT
Important Safety Notice:

This project is intended for prototype and educational development. A real human-carrying wheelchair requires high-current electrical protection, mechanical braking, emergency-stop redundancy, battery protection, professional engineering validation and extensive supervised testing.

AI Smart Voice-Controlled Wheelchair Project

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

AI Smart Vehicle Accident Severity Prediction System

AI Smart Vehicle Accident Severity Prediction System Using ESP32 + IoT + AI Agent + n8n Automation + Telegram Voice Alerts + Google Sheets + ThingSpeak Cloud
<?= htmlspecialchars($title) ?>

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

Table of Contents

1. Abstract 2. Objectives 3. System Architecture 4. Components List 5. Circuit Schematic 6. Working Principle 7. AI Accident Severity Prediction 8. n8n Automation Workflow 9. Telegram Bot and Voice Alerts 10. Google Sheets Integration 11. ThingSpeak Cloud Dashboard 12. ESP32 Source Code 13. PHP IoT Dashboard 14. AI Power Consumption Prediction 15. Testing Plan 16. Future Enhancements 17. Conclusion

1. Abstract

Road accidents are a major cause of injuries and fatalities. In many accident situations, emergency services are not informed immediately. This project proposes an AI-powered smart vehicle accident detection and severity prediction system using ESP32, IoT sensors, AI, n8n automation, Telegram voice alerts, Google Sheets, ThingSpeak, and a PHP-based IoT webpage.

The ESP32 continuously monitors vehicle parameters such as acceleration, vibration, gyroscope movement, vehicle tilt, speed, GPS location, battery voltage, and power consumption. When abnormal sensor values are detected, the ESP32 sends structured data to an n8n webhook.

The AI system analyzes the sensor data and classifies the event as Normal, Minor, Moderate, or Critical. Based on the result, n8n automatically sends Telegram text alerts, generates voice notifications, stores data in Google Sheets, updates ThingSpeak, and provides data to the IoT dashboard.

2. Project Objectives

  • Detect vehicle accidents using ESP32 and multiple sensors.
  • Predict accident severity using AI-based logic.
  • Send automatic emergency notifications.
  • Generate Telegram voice alerts.
  • Store accident records in Google Sheets.
  • Display real-time data on ThingSpeak.
  • Provide a PHP-based IoT monitoring webpage.
  • Use n8n as the automation and integration platform.
  • Predict vehicle power consumption.
  • Provide an AI Agent for intelligent decision-making.

3. Overall System Architecture

+-------------------------+ | VEHICLE SENSORS | | MPU6050 | GPS | Vibration| | Battery | Speed | Tilt | +------------+------------+ | v +-------------------------+ | ESP32 | | Edge Monitoring Device | +------------+------------+ | | Wi-Fi / Internet v +-------------------------+ | n8n AUTOMATION | | Webhook + AI Workflow | +------------+------------+ | v +-------------------------+ | AI AGENT / MODEL | | Severity Prediction | +------------+------------+ | v +-------------------------------------+ | DECISION ENGINE | +-------+---------+---------+---------+ | | | v v v Telegram Google ThingSpeak Text/Voice Sheets Dashboard | v +-------------------------+ | PHP IoT WEBPAGE | | Live Monitoring Panel | +-------------------------+

4. Components List

Component Purpose
ESP32 Main IoT controller with Wi-Fi connectivity
MPU6050 Acceleration and gyroscope measurement
GPS Module Vehicle location and speed
Vibration Sensor Impact and vibration detection
Voltage Sensor Vehicle battery monitoring
Buzzer Local emergency alert
Wi-Fi Network Internet communication
n8n Workflow automation and AI orchestration
Telegram Bot Text and voice notifications
Google Sheets Historical accident data storage
ThingSpeak Cloud IoT dashboard
PHP Web Server Custom IoT monitoring webpage

5. Circuit Schematic Diagram

+----------------------+ | ESP32 | | | MPU6050 SDA ------>| GPIO 21 | MPU6050 SCL ------>| GPIO 22 | | | GPS TX ----------->| GPIO 16 RX | GPS RX <-----------| GPIO 17 TX | | | Vibration -------->| GPIO 27 | | | Buzzer <-----------| GPIO 26 | | | Battery Sensor --->| ADC GPIO 34 | +----------+-----------+ | | Wi-Fi v +---------------+ | INTERNET | +-------+-------+ | v +---------------+ | n8n | +-------+-------+ | +-----------------+-----------------+ | | | v v v Telegram Google Sheets ThingSpeak

MPU6050 Connection

MPU6050 PinESP32 Pin
VCC3.3V
GNDGND
SDAGPIO 21
SCLGPIO 22

GPS Connection

GPS PinESP32 Pin
VCC5V / 3.3V according to module
GNDGND
TXGPIO 16
RXGPIO 17

6. System Working Principle

  1. The vehicle is powered ON.
  2. ESP32 connects to Wi-Fi.
  3. All sensors are initialized.
  4. Sensor data is continuously monitored.
  5. Abnormal acceleration, vibration, tilt, or rotation is detected.
  6. ESP32 collects complete accident data.
  7. Data is transmitted to the n8n webhook.
  8. The AI Agent analyzes the data.
  9. Accident severity is calculated.
  10. n8n decides the required action.
  11. Telegram notifications are sent when required.
  12. Voice alert is generated for critical accidents.
  13. Data is stored in Google Sheets.
  14. ThingSpeak is updated.
  15. The PHP dashboard displays monitoring information.
Vehicle | Sensors | ESP32 | Accident Detection | n8n Webhook | AI Agent | Severity Prediction | Decision | +-----------------------------+ | Normal / Minor / Moderate | | Critical Accident | +-----------------------------+ | Notifications + Cloud Storage

7. AI Accident Severity Prediction

The system combines several sensor values instead of depending on only one sensor.

Severity Categories

ScoreSeverityAction
0-20NormalContinue monitoring
21-40MinorStore event
41-70ModerateTelegram warning
71-100CriticalEmergency text and voice alert

Severity Formula


Severity Score =
    Acceleration Score
  + Gyroscope Score
  + Vibration Score
  + Speed Score
  + Tilt Score
    

Acceleration Formula


A = sqrt(Ax² + Ay² + Az²)
    

AI Agent Output Example

{
  "accident_detected": true,
  "severity": "CRITICAL",
  "confidence": 0.96,
  "severity_score": 89,
  "send_telegram_alert": true,
  "send_voice_alert": true,
  "store_in_google_sheets": true,
  "update_thingspeak": true
}

8. n8n Automation Workflow

ESP32 | v Webhook | v Validate JSON | v Calculate Severity | v AI Agent | v Critical? | +---- No ----> Google Sheets | +---- Yes ---> Telegram Text Alert | v Voice Generation | v Telegram Voice | v Google Sheets | v ThingSpeak

n8n Severity Prediction Code


const data = $json;

const acceleration = Number(data.acceleration || 0);
const gyro = Number(data.gyro || 0);
const vibration = Number(data.vibration || 0);
const speed = Number(data.speed || 0);
const tilt = Number(data.tilt || 0);

let score = 0;

if (acceleration >= 8) {
    score += 40;
} else if (acceleration >= 5) {
    score += 30;
} else if (acceleration >= 3) {
    score += 20;
}

if (gyro >= 250) {
    score += 20;
} else if (gyro >= 150) {
    score += 15;
} else if (gyro >= 80) {
    score += 10;
}

if (vibration === 1) {
    score += 15;
}

if (speed >= 80) {
    score += 15;
} else if (speed >= 50) {
    score += 10;
}

if (tilt >= 45) {
    score += 10;
} else if (tilt >= 25) {
    score += 5;
}

let severity = "NORMAL";

if (score >= 70) {
    severity = "CRITICAL";
} else if (score >= 41) {
    severity = "MODERATE";
} else if (score >= 21) {
    severity = "MINOR";
}

return [{
    json: {
        ...data,
        severity_score: score,
        severity: severity,
        accident_detected: score >= 21
    }
}];
    

9. Telegram Bot and Voice Alert Setup

  1. Open Telegram.
  2. Search for BotFather.
  3. Create a new bot.
  4. Copy the Bot Token.
  5. Send a message to your bot.
  6. Obtain the Chat ID.
  7. Configure Telegram credentials in n8n.
  8. Use the Send Message node for text alerts.
  9. Use a Text-to-Speech service to generate audio.
  10. Send the generated audio using Telegram.

Example Emergency Alert


🚨 VEHICLE ACCIDENT ALERT 🚨

Vehicle ID: ESP32_VEHICLE_001

Severity: CRITICAL
Severity Score: 85

Acceleration: 8.4 g
Gyroscope: 245.6
Speed: 65.2 km/h
Tilt: 43.5°
Vibration: Detected

Battery: 12.4 V

Location:
Latitude: 17.4123
Longitude: 78.4567

Immediate assistance may be required.
    

Voice Message


Emergency alert. A critical vehicle accident has been detected.
The estimated accident severity is critical.
The vehicle location has been identified.
Emergency assistance may be required immediately.
    

10. Google Sheets Integration

Timestamp Vehicle ID Acceleration Gyro Vibration Speed Tilt Severity Score Latitude Longitude Battery
2026-07-18 ESP32_VEHICLE_001 8.4 245.6 1 65.2 43.5 CRITICAL 85 17.4123 78.4567 12.4

11. ThingSpeak Cloud Dashboard

FieldData
Field 1Acceleration
Field 2Gyroscope
Field 3Speed
Field 4Tilt
Field 5Battery Voltage
Field 6Severity Score
Field 7Accident Status

field1 = 8.4
field2 = 245.6
field3 = 65.2
field4 = 43.5
field5 = 12.4
field6 = 85
field7 = 1
    

12. ESP32 Source Code


#include <WiFi.h>
#include <HTTPClient.h>
#include <Wire.h>
#include <MPU6050.h>

MPU6050 mpu;

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

const char* webhookURL =
"https://YOUR_N8N_DOMAIN/webhook/vehicle-accident";

#define VIBRATION_PIN 27
#define BUZZER_PIN 26

void setup() {

    Serial.begin(115200);

    pinMode(VIBRATION_PIN, INPUT);
    pinMode(BUZZER_PIN, OUTPUT);

    Wire.begin();

    mpu.initialize();

    WiFi.begin(ssid, password);

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

    Serial.println("WiFi Connected");
}

void loop() {

    int16_t ax, ay, az;
    int16_t gx, gy, gz;

    mpu.getMotion6(
        &ax,
        &ay,
        &az,
        &gx,
        &gy,
        &gz
    );

    float accelerationX = ax / 16384.0;
    float accelerationY = ay / 16384.0;
    float accelerationZ = az / 16384.0;

    float acceleration =
        sqrt(
            accelerationX * accelerationX +
            accelerationY * accelerationY +
            accelerationZ * accelerationZ
        );

    float gyro =
        sqrt(
            gx * gx +
            gy * gy +
            gz * gz
        ) / 131.0;

    int vibration = digitalRead(VIBRATION_PIN);

    if (acceleration > 3.0 || vibration == HIGH) {

        digitalWrite(BUZZER_PIN, HIGH);

        sendDataToN8N(
            acceleration,
            gyro,
            vibration
        );

        delay(10000);

        digitalWrite(BUZZER_PIN, LOW);
    }

    delay(1000);
}

void sendDataToN8N(
    float acceleration,
    float gyro,
    int vibration
) {

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

        HTTPClient http;

        http.begin(webhookURL);

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

        String jsonData = "{";

        jsonData += "\"device_id\":\"ESP32_VEHICLE_001\",";
        jsonData += "\"acceleration\":";
        jsonData += String(acceleration, 2);
        jsonData += ",";

        jsonData += "\"gyro\":";
        jsonData += String(gyro, 2);
        jsonData += ",";

        jsonData += "\"vibration\":";
        jsonData += String(vibration);
        jsonData += ",";

        jsonData += "\"speed\":0,";
        jsonData += "\"tilt\":0,";
        jsonData += "\"battery_voltage\":12.4";

        jsonData += "}";

        int responseCode = http.POST(jsonData);

        Serial.print("HTTP Response: ");
        Serial.println(responseCode);

        http.end();
    }
}
    

13. PHP IoT Web Dashboard

This PHP page can be hosted on XAMPP, WAMP, LAMP, a VPS, or a PHP-enabled web server. It can be connected to a database, n8n webhook, ThingSpeak API, or another IoT backend.

+--------------------------------+ | AI VEHICLE DASHBOARD | +--------------------------------+ | Vehicle Status: ONLINE | | Accident Status: NORMAL | | Severity Score: 0 | | Acceleration: 1.1 g | | Speed: 54 km/h | | Battery: 12.6 V | | GPS: CONNECTED | +--------------------------------+ | LIVE SENSOR GRAPH | +--------------------------------+ | GPS LOCATION | +--------------------------------+ | ACCIDENT HISTORY | +--------------------------------+

Example PHP Dynamic Data Section


<?php

$vehicleStatus = "ONLINE";
$accidentStatus = "NORMAL";
$severityScore = 0;
$acceleration = 1.1;
$speed = 54;
$battery = 12.6;

?>

<h2>Vehicle Monitoring Dashboard</h2>

<p>Vehicle Status:
    <?= $vehicleStatus ?>
</p>

<p>Accident Status:
    <?= $accidentStatus ?>
</p>

<p>Severity Score:
    <?= $severityScore ?>
</p>

<p>Acceleration:
    <?= $acceleration ?> g
</p>

<p>Speed:
    <?= $speed ?> km/h
</p>

<p>Battery:
    <?= $battery ?> V
</p>
    

14. AI Power Consumption Prediction

The system can monitor battery voltage and current to calculate power consumption.


Power = Voltage × Current

Example:

Voltage = 12.4 V
Current = 4.5 A

Power = 12.4 × 4.5
Power = 55.8 W
    

Power Prediction Logic


const voltage = Number($json.battery_voltage || 0);
const current = Number($json.current || 0);

const power = voltage * current;

let prediction = "NORMAL";

if (power > 150) {
    prediction = "HIGH POWER CONSUMPTION";
}

if (power > 250) {
    prediction = "CRITICAL POWER CONSUMPTION";
}

return [{
    json: {
        ...$json,
        calculated_power: power,
        power_prediction: prediction
    }
}];
    

15. Testing Plan

Test Input Condition Expected Result
Normal Driving Acceleration 1.2 g, low vibration Normal monitoring
Minor Impact Acceleration 3.5 g Minor accident
Moderate Impact Acceleration 5.5 g, gyro 160 Moderate alert
Severe Impact Acceleration 8.5 g, vibration high, tilt 50 degrees Critical text and voice alert

16. Future Enhancements

  • GSM or 4G LTE emergency communication.
  • ESP32-CAM or Raspberry Pi camera integration.
  • Machine learning models such as Random Forest, XGBoost, or Neural Networks.
  • Automatic emergency service integration.
  • Driver health monitoring.
  • Fire and smoke detection.
  • Fleet management dashboard.
  • Multi-vehicle cloud monitoring.
  • Predictive vehicle maintenance.
  • Voice-based AI conversation after an accident.

17. Conclusion

The AI Smart Vehicle Accident Severity Prediction System combines ESP32 IoT sensing, AI-based accident analysis, n8n workflow automation, Telegram notifications, voice alerts, Google Sheets data storage, ThingSpeak cloud monitoring, and PHP web dashboard technology.

The ESP32 operates as the edge device, collecting real-time sensor information. The n8n automation system processes and routes the data. The AI Agent analyzes the accident situation and predicts severity. Telegram provides immediate communication, while Google Sheets and ThingSpeak provide storage and visualization.

The system is expandable and can be developed into a complete smart transportation safety platform for personal vehicles, public transportation, fleet management, insurance systems, and smart city applications.

Important: This prototype should be extensively tested and validated before being used as a certified emergency or safety-critical system.

AI Smart Vehicle Accident Severity Prediction System

ESP32 + AI + n8n + Telegram + Google Sheets + ThingSpeak + PHP IoT Dashboard