Sunday, 19 July 2026

AI-Based Smart Factory Automation with Predictive Maintenance

AI-Based Smart Factory Automation with Predictive Maintenance

AI-Based Smart Factory Automation with Predictive Maintenance

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

1. Full Project Description

The AI-Based Smart Factory Automation with Predictive Maintenance system is an intelligent Industrial IoT solution designed to continuously monitor factory machines and predict possible equipment failures before they occur.

The system uses an ESP32 microcontroller as the primary IoT controller. Multiple sensors are connected to the ESP32 to monitor temperature, vibration, voltage, current, power consumption, machine runtime and operational conditions.

The ESP32 collects real-time sensor data and transmits the data through Wi-Fi to an IoT webpage and an n8n automation workflow.

The n8n workflow acts as an automation engine. It receives the machine data, stores the data in Google Sheets, updates ThingSpeak cloud dashboards, sends the sensor information to an AI Agent and automatically generates predictive maintenance decisions.

The AI Agent analyzes machine health parameters and predicts whether the machine is operating normally, showing warning symptoms or approaching a possible failure condition.

When a dangerous condition is detected, n8n automatically sends Telegram text alerts and voice notifications to the maintenance team.

The complete system represents an Agentic IoT architecture because the AI Agent can analyze data, make decisions, generate recommendations and trigger automated actions.

2. Project Objectives

  • Monitor industrial machines in real time.
  • Measure machine temperature.
  • Measure vibration levels.
  • Monitor voltage and current.
  • Calculate power consumption.
  • Predict possible machine failures.
  • Detect abnormal energy consumption.
  • Store historical machine data.
  • Generate AI maintenance recommendations.
  • Send Telegram text alerts.
  • Send Telegram voice notifications.
  • Display machine status on an IoT webpage.
  • Store data in Google Sheets.
  • Display cloud analytics using ThingSpeak.
  • Automatically control warning devices.

3. System Architecture


INDUSTRIAL MACHINE

        |

        v

TEMPERATURE SENSOR

VIBRATION SENSOR

CURRENT SENSOR

VOLTAGE SENSOR

        |

        v

ESP32 IoT CONTROLLER

        |

        | Wi-Fi

        v

IOT WEBPAGE / PHP API

        |

        v

n8n AUTOMATION WORKFLOW

        |

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

        |                         |

        v                         v

AI AGENT              GOOGLE SHEETS

PREDICTIVE             DATA STORAGE

ANALYSIS

        |

        v

THINGSPEAK CLOUD

DASHBOARD

        |

        v

FAILURE DECISION

        |

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

        |                         |

        v                         v

TELEGRAM TEXT          TELEGRAM VOICE

ALERT                   NOTIFICATION

        |

        v

MAINTENANCE ACTION

4. Hardware Components List

Component Purpose
ESP32 Development Board Main IoT controller
DS18B20 / DHT22 Temperature monitoring
MPU6050 / ADXL345 Vibration monitoring
ACS712 / PZEM Current measurement
ZMPT101B / PZEM Voltage measurement
OLED Display Local machine status display
Relay Module Automatic control
Buzzer Local warning notification
Red LED Critical status indication
Green LED Normal status indication
Wi-Fi Router Internet connectivity
Industrial Motor Machine under monitoring

5. Circuit Schematic Diagram


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

                    |        ESP32         |

                    |                      |

                    | GPIO 4  <------------ DS18B20 DATA

                    |                      |

                    | GPIO 21 <------------ MPU6050 SDA

                    |                      |

                    | GPIO 22 <------------ MPU6050 SCL

                    |                      |

                    | GPIO 34 <------------ Current Sensor

                    |                      |

                    | GPIO 35 <------------ Voltage Sensor

                    |                      |

                    | GPIO 25 ------------> Relay Module

                    |                      |

                    | GPIO 26 ------------> Buzzer

                    |                      |

                    | GPIO 27 ------------> RED LED

                    |                      |

                    | GPIO 14 ------------> GREEN LED

                    |                      |

                    | 3.3V ---------------> Sensors

                    |                      |

                    | GND ----------------> Common GND

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

Safety Warning: Industrial AC voltage and motors must be isolated using appropriate fuses, contactors, optocouplers and certified electrical protection. Never connect mains voltage directly to an ESP32 or a breadboard.

6. Detailed Circuit Connections

DS18B20 Temperature Sensor

DS18B20 Pin ESP32 Pin
VCC 3.3V
GND GND
DATA GPIO 4

A 4.7 kΩ pull-up resistor should be connected between DATA and 3.3V.

MPU6050 Vibration Sensor

MPU6050 ESP32
VCC 3.3V
GND GND
SDA GPIO 21
SCL GPIO 22

7. Complete Flowchart


START

  |

  v

INITIALIZE ESP32

  |

  v

CONNECT TO WI-FI

  |

  v

READ TEMPERATURE

  |

  v

READ VIBRATION

  |

  v

READ VOLTAGE

  |

  v

READ CURRENT

  |

  v

CALCULATE POWER

  |

  v

SEND DATA TO SERVER

  |

  v

n8n RECEIVES DATA

  |

  v

AI AGENT ANALYZES DATA

  |

  v

CALCULATE FAILURE RISK

  |

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

  |                           |

  v                           v

NORMAL                    WARNING / CRITICAL

  |                           |

  v                           v

STORE DATA                SEND TELEGRAM ALERT

  |                           |

  v                           v

UPDATE CLOUD              GENERATE VOICE ALERT

                              |

                              v

                       MAINTENANCE ACTION

                              |

                              v

                       REPEAT MONITORING

8. Predictive Maintenance Logic

The system calculates a machine health score based on multiple parameters.


Temperature Risk       = 25 Percent

Vibration Risk         = 30 Percent

Power Consumption Risk = 25 Percent

Current Risk           = 20 Percent

Total Risk Score

=

Temperature Risk * 0.25

+

Vibration Risk * 0.30

+

Power Risk * 0.25

+

Current Risk * 0.20

Temperature Threshold

Temperature Status
Below 60 °C NORMAL
60 °C to 75 °C WARNING
Above 75 °C CRITICAL

Machine Risk Score


0 to 30     = NORMAL

31 to 60    = WARNING

61 to 100   = CRITICAL

9. AI Power Consumption Prediction Logic

The system records historical power consumption and uses the historical trend to identify abnormal energy usage.


09:00  = 2200 W

09:10  = 2300 W

09:20  = 2500 W

09:30  = 2800 W

The AI Agent detects that power consumption is increasing abnormally.


CURRENT POWER:

2800 W

PREDICTED FUTURE POWER:

3400 W

POSSIBLE CAUSES:

1. Motor overload

2. Bearing friction

3. Mechanical obstruction

4. Voltage instability

10. ESP32 Source Code



#include <WiFi.h>

#include <HTTPClient.h>

#include <Wire.h>

#include <OneWire.h>

#include <DallasTemperature.h>

#include <ArduinoJson.h>

const char* ssid = "YOUR_WIFI_NAME";

const char* password = "YOUR_WIFI_PASSWORD";

const char* serverURL =

"https://your-domain.com/api/receive_data.php";

#define ONE_WIRE_BUS 4

#define RELAY_PIN 25

#define BUZZER_PIN 26

#define RED_LED 27

#define GREEN_LED 14

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

float temperature;

float vibration;

float voltage;

float current;

float power;

void setup()

{

    Serial.begin(115200);

    pinMode(RELAY_PIN, OUTPUT);

    pinMode(BUZZER_PIN, OUTPUT);

    pinMode(RED_LED, OUTPUT);

    pinMode(GREEN_LED, OUTPUT);

    sensors.begin();

    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED)

    {

        delay(500);

        Serial.print(".");

    }

    Serial.println("WiFi Connected");

}

void loop()

{

    sensors.requestTemperatures();

    temperature = sensors.getTempCByIndex(0);

    vibration = analogRead(34);

    voltage = analogRead(35) * 0.1;

    current = analogRead(32) * 0.01;

    power = voltage * current;

    String status = "NORMAL";

    if (

        temperature > 75 ||

        vibration > 3000 ||

        power > 3000

    )

    {

        status = "CRITICAL";

        digitalWrite(RED_LED, HIGH);

        digitalWrite(GREEN_LED, LOW);

        digitalWrite(BUZZER_PIN, HIGH);

    }

    else if (

        temperature > 60 ||

        vibration > 2000 ||

        power > 2500

    )

    {

        status = "WARNING";

        digitalWrite(RED_LED, HIGH);

        digitalWrite(GREEN_LED, LOW);

        digitalWrite(BUZZER_PIN, LOW);

    }

    else

    {

        status = "NORMAL";

        digitalWrite(RED_LED, LOW);

        digitalWrite(GREEN_LED, HIGH);

        digitalWrite(BUZZER_PIN, LOW);

    }

    if (WiFi.status() == WL_CONNECTED)

    {

        HTTPClient http;

        http.begin(serverURL);

        http.addHeader(

            "Content-Type",

            "application/json"

        );

        StaticJsonDocument<512> doc;

        doc["machine_id"] = "MACHINE_01";

        doc["temperature"] = temperature;

        doc["vibration"] = vibration;

        doc["voltage"] = voltage;

        doc["current"] = current;

        doc["power"] = power;

        doc["status"] = status;

        String jsonData;

        serializeJson(doc, jsonData);

        int httpResponseCode =

            http.POST(jsonData);

        Serial.println(httpResponseCode);

        http.end();

    }

    delay(10000);

}

11. PHP IoT API File

Save the following file as:


receive_data.php



<?php

header("Content-Type: application/json");

$data = json_decode(

    file_get_contents("php://input"),

    true

);

if (!$data)

{

    echo json_encode(

        [

            "status" => "error",

            "message" => "Invalid JSON data"

        ]

    );

    exit;

}

$machine_id =

    $data["machine_id"] ?? "UNKNOWN";

$temperature =

    $data["temperature"] ?? 0;

$vibration =

    $data["vibration"] ?? 0;

$voltage =

    $data["voltage"] ?? 0;

$current =

    $data["current"] ?? 0;

$power =

    $data["power"] ?? 0;

$status =

    $data["status"] ?? "UNKNOWN";

$file = "machine_data.json";

$old_data = [];

if (file_exists($file))

{

    $old_data =

        json_decode(

            file_get_contents($file),

            true

        );

}

$record =

    [

        "machine_id" => $machine_id,

        "temperature" => $temperature,

        "vibration" => $vibration,

        "voltage" => $voltage,

        "current" => $current,

        "power" => $power,

        "status" => $status,

        "timestamp" => date(

            "Y-m-d H:i:s"

        )

    ];

$old_data[] = $record;

file_put_contents(

    $file,

    json_encode(

        $old_data,

        JSON_PRETTY_PRINT

    )

);

echo json_encode(

    [

        "status" => "success",

        "message" =>

            "Machine data received",

        "data" => $record

    ]

);

?>

12. IoT Web Dashboard

The dashboard displays real-time machine information.


SMART FACTORY MONITORING DASHBOARD

Machine Status: NORMAL

Temperature: 45 °C

Vibration: 1.5 mm/s

Voltage: 230 V

Current: 9.5 A

Power: 2200 W

Health Score: 92 Percent

13. n8n Automation Workflow


ESP32

  |

  v

WEBHOOK

  |

  v

JSON DATA PROCESSING

  |

  v

DATA VALIDATION

  |

  v

AI PREDICTIVE MAINTENANCE AGENT

  |

  v

FAILURE RISK ANALYSIS

  |

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

  |                          |

  v                          v

NORMAL                    HIGH RISK

  |                          |

  v                          v

GOOGLE SHEETS             TELEGRAM ALERT

  |                          |

  v                          v

THINGSPEAK CLOUD          VOICE ALERT

                              |

                              v

                       MAINTENANCE ACTION

14. AI Agent Prompt


You are an industrial predictive maintenance AI Agent.

Analyze the following machine data.

Machine ID:

Temperature:

Vibration:

Voltage:

Current:

Power:

Determine:

1. Machine health status.

2. Failure risk.

3. Failure probability.

4. Possible failure cause.

5. Recommended maintenance action.

6. Whether Telegram alert is required.

Return the result in JSON format.

15. Example AI Prediction


{

    "health_status": "WARNING",

    "failure_risk": "HIGH",

    "failure_probability": 78,

    "possible_cause":

        "Motor bearing overheating",

    "recommendation":

        "Inspect bearing lubrication",

    "alert_required": true

}

16. Telegram Bot Setup

Create a Telegram bot using BotFather.


Step 1:

Open Telegram.

Step 2:

Search for BotFather.

Step 3:

Send:

/newbot

Step 4:

Enter:

Smart Factory Alert Bot

Step 5:

Copy the generated BOT TOKEN.

Step 6:

Configure the token inside the n8n Telegram node.

17. Telegram Alert Message


SMART FACTORY ALERT

Machine ID: MACHINE_01

Temperature: 78 °C

Vibration: HIGH

Power Consumption: 3400 W

AI Failure Risk: 85 Percent

Predicted Problem:

Motor bearing failure.

Recommended Action:

Inspect motor bearing and lubrication immediately.

18. Voice Notification Automation


AI PREDICTION

        |

        v

GENERATE ALERT TEXT

        |

        v

TEXT-TO-SPEECH

        |

        v

GENERATE AUDIO FILE

        |

        v

SEND AUDIO THROUGH TELEGRAM

Example voice message:


Warning.

Machine number one is showing a high failure risk.

The motor temperature is 78 degrees Celsius.

Vibration is above the safe operating limit.

Immediate maintenance inspection is recommended.

19. Google Sheets Integration

Column Data
Timestamp Machine timestamp
Machine ID Machine identification number
Temperature Temperature value
Vibration Vibration value
Voltage Voltage value
Current Current value
Power Power consumption
Health Status Normal, Warning or Critical
Failure Risk AI predicted risk
Recommendation AI maintenance recommendation

20. ThingSpeak Cloud Dashboard


FIELD 1:

Temperature

FIELD 2:

Vibration

FIELD 3:

Voltage

FIELD 4:

Current

FIELD 5:

Power

FIELD 6:

Health Score

The ThingSpeak dashboard can display real-time and historical machine sensor data using charts and graphs.

21. Agentic IoT Architecture


SENSOR

  |

  v

ESP32

  |

  v

AI AGENT

  |

  v

ANALYZE

  |

  v

DECIDE

  |

  v

TAKE ACTION

  |

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

  |                            |

  v                            v

SEND TELEGRAM ALERT       LOG DATA

  |                            |

  v                            v

VOICE NOTIFICATION        GOOGLE SHEETS

  |

  v

CONTROL RELAY

  |

  v

MAINTENANCE RECOMMENDATION

22. Project Software Requirements

  • Arduino IDE
  • ESP32 Board Package
  • Wi-Fi Library
  • HTTP Client Library
  • ArduinoJson Library
  • OneWire Library
  • DallasTemperature Library
  • PHP Server
  • n8n Automation
  • Telegram Bot
  • Google Sheets
  • ThingSpeak Cloud
  • AI API
  • Text-to-Speech Service

23. Project Folder Structure


smart-factory-project/

|

|-- esp32/

|   |

|   |-- smart_factory.ino

|

|-- web/

|   |

|   |-- index.php

|   |

|   |-- receive_data.php

|   |

|   |-- machine_data.json

|

|-- n8n/

|   |

|   |-- smart_factory_workflow.json

|

|-- docs/

|   |

|   |-- circuit_diagram

|   |

|   |-- flowchart

|   |

|   |-- project_report

|

|-- README.md

24. Complete Project Operation


MACHINE STARTS

        |

        v

ESP32 STARTS

        |

        v

WI-FI CONNECTION

        |

        v

SENSOR READING

        |

        v

TEMPERATURE MONITORING

        |

        v

VIBRATION MONITORING

        |

        v

CURRENT MONITORING

        |

        v

VOLTAGE MONITORING

        |

        v

POWER CALCULATION

        |

        v

DATA SENT TO n8n

        |

        v

AI AGENT ANALYSIS

        |

        v

FAILURE PREDICTION

        |

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

        |                           |

        v                           v

NORMAL                    WARNING / CRITICAL

        |                           |

        v                           v

STORE DATA                TELEGRAM ALERT

        |                           |

        v                           v

CLOUD UPDATE              VOICE NOTIFICATION

                                    |

                                    v

                            MAINTENANCE ACTION

25. Advantages

  • Real-time machine monitoring.
  • Early failure detection.
  • Reduced machine downtime.
  • Reduced maintenance cost.
  • AI-based predictive analysis.
  • Energy consumption monitoring.
  • Telegram notifications.
  • Voice notification support.
  • Cloud data storage.
  • Historical machine analysis.
  • Remote monitoring.
  • Scalable architecture.
  • Agentic IoT automation.

26. Future Enhancements

  • Digital Twin of the factory.
  • Advanced machine learning models.
  • LSTM-based failure prediction.
  • Random Forest prediction.
  • XGBoost predictive analytics.
  • Computer vision for machine inspection.
  • Oil leakage detection.
  • Smoke detection.
  • Multi-machine monitoring.
  • Mobile application.
  • Advanced energy analytics.
  • Automatic maintenance scheduling.
  • Voice-controlled factory automation.
  • AI-based spare parts prediction.

27. Deployment Guide

  1. Assemble the ESP32 and industrial sensors.
  2. Connect the sensors according to the circuit diagram.
  3. Upload the ESP32 firmware.
  4. Configure Wi-Fi credentials.
  5. Deploy the PHP IoT webpage.
  6. Create the n8n workflow.
  7. Configure the AI Agent.
  8. Configure Google Sheets authentication.
  9. Create the ThingSpeak channel.
  10. Create and configure the Telegram Bot.
  11. Configure the voice notification system.
  12. Test normal machine conditions.
  13. Test warning conditions.
  14. Test critical conditions.
  15. Verify Telegram notifications.
  16. Verify Google Sheets data logging.
  17. Verify ThingSpeak cloud charts.

28. Final Project Summary

The AI-Based Smart Factory Automation with Predictive Maintenance system integrates ESP32, industrial sensors, AI Agent technology, n8n automation, Telegram notifications, voice alerts, Google Sheets and ThingSpeak cloud monitoring into one intelligent industrial automation platform.

The system collects real-time machine data, analyzes machine health, detects abnormal conditions, predicts possible failures, estimates future power consumption and automatically sends alerts to the maintenance team.

This project demonstrates the complete concept of Agentic IoT, where sensors collect data, the ESP32 transmits the data, AI analyzes the information, n8n automates the workflow and the system automatically performs appropriate actions.

AI-Based Smart Exam Proctoring System Using Face Tracking

AI-Based Smart Exam Proctoring System Using Face Tracking

AI-Based Smart Exam Proctoring System Using Face Tracking

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

1. Complete Project Title

AI-Based Smart Exam Proctoring System Using Face Tracking with ESP32, AI Agent, n8n Automation, Telegram Voice Alerts, Google Sheets and ThingSpeak Cloud Dashboard.

2. Full Project Description

The AI-Based Smart Exam Proctoring System Using Face Tracking is an intelligent examination monitoring system that combines Artificial Intelligence, Computer Vision, IoT, ESP32, cloud computing, workflow automation and real-time notification services.

The main purpose of this project is to monitor examination environments using face detection and face tracking technology. The system analyzes the candidate's presence, face position, head direction and number of detected faces.

When the system detects unusual or suspicious events such as multiple faces, absence of the candidate or repeated looking away from the examination screen, an event is generated.

The event is transmitted through an IoT communication system to an ESP32 and cloud-based automation platform.

The n8n automation workflow receives the event and automatically performs multiple actions.

  • Stores the event in Google Sheets.
  • Updates the ThingSpeak cloud dashboard.
  • Sends a Telegram text alert.
  • Generates a Telegram voice notification.
  • Allows an AI agent to analyze the examination event.
  • Generates a risk score and examination summary.

The ESP32 functions as the IoT controller and can monitor system status, environmental parameters and power consumption.

The project provides a complete Agentic IoT architecture combining AI, ESP32, n8n automation, Telegram alerts, cloud dashboards and intelligent data analysis.

3. Main Project Objectives

  • Monitor examination candidates using AI-based face tracking.
  • Detect whether the candidate is present.
  • Detect multiple faces in the examination area.
  • Monitor head direction and repeated looking away.
  • Generate automatic suspicious activity alerts.
  • Use ESP32 for IoT communication and sensor monitoring.
  • Use n8n for workflow automation.
  • Send Telegram text and voice alerts.
  • Store examination events in Google Sheets.
  • Display cloud data using ThingSpeak.
  • Use AI agents for event analysis.
  • Predict future power consumption.

4. System Architecture

+-----------------------------+ | EXAM CANDIDATE | | STUDENT | +-------------+---------------+ | v +-----------------------------+ | AI CAMERA SYSTEM | | Face Detection and Tracking | | Head Pose Analysis | | Multiple Face Detection | +-------------+---------------+ | v +-----------------------------+ | ESP32 | | Wi-Fi Controller | | Sensors | | OLED Display | | Buzzer | | LED Indicators | +-------------+---------------+ | v +-----------------------------+ | IoT WEBPAGE | | Live Monitoring Dashboard | +-------------+---------------+ | v +-----------------------------+ | n8n | | Workflow Automation | | AI Agent Processing | +-------------+---------------+ | +-------------------+-------------------+ | | | v v v +-------------+ +-------------+ +-------------+ | Telegram | | Google | | ThingSpeak | | Alerts | | Sheets | | Cloud | +------+------+ +-------------+ +-------------+ | v +-------------+ | Voice Alert | +-------------+

5. Hardware Components List

Component Purpose
ESP32 Development Board Main IoT controller
USB Camera Face tracking and monitoring
ESP32-CAM Optional camera-based alternative
OLED Display Displays system status
Buzzer Local warning alert
Red LED Suspicious activity indicator
Green LED Normal system status indicator
DHT11 or DHT22 Temperature and humidity monitoring
PIR Sensor Optional movement detection
LDR Sensor Light monitoring
MicroSD Module Local event storage
5V Power Supply System power

6. Hardware Circuit Schematic

ESP32 +--------------------------+ | | | GPIO 21 -------- SDA |------ OLED | GPIO 22 -------- SCL |------ OLED | | | GPIO 4 --------- DATA |------ DHT11 | | | GPIO 25 -------- BUZZER |------ Buzzer | | | GPIO 26 -------- RED LED |------ Red LED | | | GPIO 27 -------- GREEN |------ Green LED | | | 3.3V ------------ VCC | | GND ------------- GND | +-------------+------------+ | v Wi-Fi Network | v Cloud Server

OLED Connection

OLED Pin ESP32 Pin
VCC 3.3V
GND GND
SDA GPIO 21
SCL GPIO 22

DHT11 Connection

DHT11 Pin ESP32 Pin
VCC 3.3V
DATA GPIO 4
GND GND

7. Software Flowchart

+----------------+ | START | +--------+-------+ | v +----------------+ | Initialize ESP32| | Wi-Fi and Sensors| +--------+-------+ | v +----------------+ | Start Exam | +--------+-------+ | v +----------------+ | Capture Camera | | Frame | +--------+-------+ | v +----------------+ | Detect Face | +----+-------+----+ | | YES NO | | v v +------------+ +---------------+ | Track Face | | Start Timer | +------+-----+ +-------+-------+ | | | v | +---------------+ | | Timeout? | | +-------+-------+ | | | v | +---------------+ | | Absence Alert | | +---------------+ | v +----------------+ | Analyze Head | | Direction | +--------+--------+ | v +----------------+ | Generate Event | +--------+--------+ | v +----------------+ | Send to n8n | +--------+--------+ | v +----------------+ | Telegram Alert | | Google Sheets | | ThingSpeak | +----------------+

8. AI Face Tracking Logic

The AI camera captures the candidate's video stream and analyzes each frame.

  1. Capture video frame.
  2. Detect all faces.
  3. Count the number of detected faces.
  4. Extract face landmarks.
  5. Estimate head direction.
  6. Measure the duration of unusual behavior.
  7. Apply a time threshold.
  8. Generate an examination event.
  9. Send the event to the server and automation workflow.

Possible Event Types

  • NORMAL
  • FACE_NOT_DETECTED
  • MULTIPLE_FACES
  • LOOKING_LEFT
  • LOOKING_RIGHT
  • LOOKING_DOWN
  • LOOKING_AWAY
  • EXAM_STARTED
  • EXAM_FINISHED
  • SYSTEM_ERROR

9. Face Detection Decision Logic

CAMERA FRAME | v FACE DETECTION | +----------+----------+ | | | v v v 0 FACES 1 FACE 2+ FACES | | | v v v ABSENT NORMAL MULTIPLE FACE ALERT

10. AI Event JSON Format


{
    "student_id": "STUDENT_001",
    "exam_id": "EXAM_2026_001",
    "event_type": "MULTIPLE_FACES",
    "face_count": 2,
    "confidence": 0.94,
    "timestamp": "2026-07-20T10:30:00",
    "device_id": "ESP32_PROCTOR_01",
    "temperature": 28.5,
    "humidity": 62
}

11. ESP32 Source Code


#include <WiFi.h>

#include <HTTPClient.h>

#include <Wire.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

#include <DHT.h>

#define SCREEN_WIDTH 128

#define SCREEN_HEIGHT 64

#define OLED_RESET -1

#define OLED_ADDRESS 0x3C

Adafruit_SSD1306 display(

    SCREEN_WIDTH,

    SCREEN_HEIGHT,

    &Wire,

    OLED_RESET

);

#define DHTPIN 4

#define DHTTYPE DHT11

DHT dht(

    DHTPIN,

    DHTTYPE

);

#define BUZZER_PIN 25

#define RED_LED 26

#define GREEN_LED 27

const char* WIFI_SSID =

    "YOUR_WIFI_NAME";

const char* WIFI_PASSWORD =

    "YOUR_WIFI_PASSWORD";

String serverURL =

    "http://YOUR_SERVER_IP/proctoring_event.php";

String thingSpeakURL =

    "https://api.thingspeak.com/update";

String thingSpeakAPIKey =

    "YOUR_THINGSPEAK_WRITE_API_KEY";

String deviceID =

    "ESP32_PROCTOR_01";

void setup()

{

    Serial.begin(115200);

    pinMode(

        BUZZER_PIN,

        OUTPUT

    );

    pinMode(

        RED_LED,

        OUTPUT

    );

    pinMode(

        GREEN_LED,

        OUTPUT

    );

    digitalWrite(

        BUZZER_PIN,

        LOW

    );

    digitalWrite(

        RED_LED,

        LOW

    );

    digitalWrite(

        GREEN_LED,

        HIGH

    );

    dht.begin();

    display.begin(

        SSD1306_SWITCHCAPVCC,

        OLED_ADDRESS

    );

    display.clearDisplay();

    display.setTextSize(1);

    display.setTextColor(

        SSD1306_WHITE

    );

    display.setCursor(0, 0);

    display.println(

        "AI PROCTORING"

    );

    display.println(

        "SYSTEM STARTING"

    );

    display.display();

    WiFi.begin(

        WIFI_SSID,

        WIFI_PASSWORD

    );

    while (

        WiFi.status()

        != WL_CONNECTED

    )

    {

        delay(500);

        Serial.print(".");

    }

    Serial.println();

    Serial.println(

        "WiFi Connected"

    );

    display.clearDisplay();

    display.setCursor(0, 0);

    display.println(

        "WiFi Connected"

    );

    display.println(

        WiFi.localIP()

    );

    display.display();

    delay(2000);

}

void loop()

{

    float temperature =

        dht.readTemperature();

    float humidity =

        dht.readHumidity();

    if (isnan(temperature))

    {

        temperature = 0;

    }

    if (isnan(humidity))

    {

        humidity = 0;

    }

    display.clearDisplay();

    display.setCursor(0, 0);

    display.println(

        "AI PROCTORING"

    );

    display.setCursor(0, 15);

    display.println(

        "STATUS: MONITORING"

    );

    display.setCursor(0, 30);

    display.print(

        "TEMP: "

    );

    display.print(

        temperature

    );

    display.println(

        " C"

    );

    display.setCursor(0, 45);

    display.print(

        "HUM: "

    );

    display.print(

        humidity

    );

    display.println(

        " %"

    );

    display.display();

    sendThingSpeakData(

        temperature,

        humidity,

        1

    );

    delay(15000);

}

12. ESP32 Suspicious Activity Alert Function


void activateSuspiciousAlert()

{

    digitalWrite(

        RED_LED,

        HIGH

    );

    digitalWrite(

        GREEN_LED,

        LOW

    );

    digitalWrite(

        BUZZER_PIN,

        HIGH

    );

    delay(1000);

    digitalWrite(

        BUZZER_PIN,

        LOW

    );

    delay(1000);

    digitalWrite(

        RED_LED,

        LOW

    );

    digitalWrite(

        GREEN_LED,

        HIGH

    );

}

13. ESP32 HTTP Event Function


void sendProctoringEvent(

    String eventType,

    int faceCount,

    float confidence

)

{

    if (

        WiFi.status()

        == WL_CONNECTED

    )

    {

        HTTPClient http;

        http.begin(

            serverURL

        );

        http.addHeader(

            "Content-Type",

            "application/json"

        );

        float temperature =

            dht.readTemperature();

        float humidity =

            dht.readHumidity();

        String jsonData = "{";

        jsonData +=

            "\"device_id\":\"";

        jsonData +=

            deviceID;

        jsonData +=

            "\",";

        jsonData +=

            "\"event_type\":\"";

        jsonData +=

            eventType;

        jsonData +=

            "\",";

        jsonData +=

            "\"face_count\":";

        jsonData +=

            faceCount;

        jsonData +=

            ",";

        jsonData +=

            "\"confidence\":";

        jsonData +=

            confidence;

        jsonData +=

            ",";

        jsonData +=

            "\"temperature\":";

        jsonData +=

            temperature;

        jsonData +=

            ",";

        jsonData +=

            "\"humidity\":";

        jsonData +=

            humidity;

        jsonData +=

            "}";

        int responseCode =

            http.POST(

                jsonData

            );

        Serial.print(

            "Server Response: "

        );

        Serial.println(

            responseCode

        );

        http.end();

    }

}

14. ThingSpeak Cloud Update Code


void sendThingSpeakData(

    float temperature,

    float humidity,

    int systemStatus

)

{

    if (

        WiFi.status()

        == WL_CONNECTED

    )

    {

        HTTPClient http;

        String url =

            thingSpeakURL +

            "?api_key=" +

            thingSpeakAPIKey +

            "&field1=" +

            String(

                temperature

            ) +

            "&field2=" +

            String(

                humidity

            ) +

            "&field3=" +

            String(

                systemStatus

            );

        http.begin(

            url

        );

        int responseCode =

            http.GET();

        Serial.print(

            "ThingSpeak Response: "

        );

        Serial.println(

            responseCode

        );

        http.end();

    }

}

15. PHP Backend API

Create a file named:

proctoring_event.php

<?php

header(

    "Content-Type: application/json"

);

$data = json_decode(

    file_get_contents(

        "php://input"

    ),

    true

);

if (!$data)

{

    echo json_encode(

        [

            "status" => "error",

            "message" =>

            "Invalid JSON data"

        ]

    );

    exit;

}

$device_id =

    $data["device_id"]

    ?? "UNKNOWN";

$event_type =

    $data["event_type"]

    ?? "UNKNOWN";

$face_count =

    $data["face_count"]

    ?? 0;

$confidence =

    $data["confidence"]

    ?? 0;

$temperature =

    $data["temperature"]

    ?? 0;

$humidity =

    $data["humidity"]

    ?? 0;

$timestamp =

    date(

        "Y-m-d H:i:s"

    );

$log =

    [

        "device_id" =>

        $device_id,

        "event_type" =>

        $event_type,

        "face_count" =>

        $face_count,

        "confidence" =>

        $confidence,

        "temperature" =>

        $temperature,

        "humidity" =>

        $humidity,

        "timestamp" =>

        $timestamp

    ];

file_put_contents(

    "proctoring_logs.json",

    json_encode(

        $log

    ) . PHP_EOL,

    FILE_APPEND

);

echo json_encode(

    [

        "status" =>

        "success",

        "message" =>

        "Proctoring event received",

        "data" =>

        $log

    ]

);

?>

16. IoT Monitoring Dashboard

The IoT webpage displays the latest examination monitoring event and event history.

+------------------------------------------------+ | AI SMART EXAM PROCTORING DASHBOARD | +------------------------------------------------+ | Latest Event | Face Count | Confidence | Temp | +------------------------------------------------+ | EVENT HISTORY TABLE | +------------------------------------------------+ | Time | Device | Event | Faces | Confidence | +------------------------------------------------+

17. n8n Automation Workflow

ESP32 / AI SYSTEM | v WEBHOOK TRIGGER | v PARSE JSON DATA | v AI EVENT ANALYSIS | v SUSPICIOUS EVENT? | / \ YES NO | | v v TELEGRAM GOOGLE ALERT SHEETS | v VOICE ALERT | v THINGSPEAK UPDATE

18. n8n Workflow JSON


{

    "name":

    "AI Exam Proctoring Automation",

    "nodes":

    [

        {

            "parameters":

            {

                "httpMethod":

                "POST",

                "path":

                "exam-proctoring"

            },

            "name":

            "Proctoring Webhook",

            "type":

            "n8n-nodes-base.webhook"

        },

        {

            "parameters":

            {

                "conditions":

                {

                    "string":

                    [

                        {

                            "value1":

                            "={{$json.event_type}}",

                            "operation":

                            "notEqual",

                            "value2":

                            "NORMAL"

                        }

                    ]

                }

            },

            "name":

            "Suspicious Event Check",

            "type":

            "n8n-nodes-base.if"

        },

        {

            "parameters":

            {

                "chatId":

                "YOUR_TELEGRAM_CHAT_ID",

                "text":

                "AI EXAM PROCTORING ALERT"

            },

            "name":

            "Telegram Alert",

            "type":

            "n8n-nodes-base.telegram"

        },

        {

            "parameters":

            {

                "operation":

                "append",

                "documentId":

                "YOUR_GOOGLE_SHEET_ID",

                "sheetName":

                "ExamEvents"

            },

            "name":

            "Google Sheets Logger",

            "type":

            "n8n-nodes-base.googleSheets"

        }

    ]

}

19. Telegram Bot Setup

  1. Open Telegram.
  2. Search for BotFather.
  3. Send /start.
  4. Send /newbot.
  5. Enter the bot name.
  6. Copy the generated bot token.
  7. Configure the Telegram credential in n8n.
  8. Find the Telegram chat ID.
  9. Configure the chat ID in the Telegram node.

Example Telegram Alert

AI EXAM PROCTORING ALERT

Event: MULTIPLE_FACES
Detected Faces: 2
AI Confidence: 94%
Device: ESP32_PROCTOR_01
Action: Supervisor review recommended.

20. Telegram Voice Notification Automation

AI EVENT | v n8n WEBHOOK | v AI AGENT ANALYSIS | v GENERATE ALERT TEXT | v TEXT-TO-SPEECH | v AUDIO FILE | v TELEGRAM VOICE MESSAGE

Example voice message:

Attention. Suspicious examination activity has been detected. Multiple faces were identified in the examination area. Supervisor review is recommended.

21. Google Sheets Integration

Timestamp Student ID Device ID Event Type Face Count Confidence Temperature Humidity
2026-07-20 10:30:00 STUDENT_001 ESP32_PROCTOR_01 MULTIPLE_FACES 2 0.94 28.5 62

22. ThingSpeak Cloud Dashboard Setup

Field Data
Field 1 Temperature
Field 2 Humidity
Field 3 Face Count
Field 4 Suspicious Event Code
Field 5 AI Confidence
Field 6 Exam Status
Field 7 Power Consumption
Field 8 Risk Score

23. AI Power Consumption Prediction Logic

The system can monitor voltage, current, environmental parameters and device activity to estimate power consumption.


Power = Voltage x Current

Example:

Voltage = 5V

Current = 0.45A

Power = 5 x 0.45

Power = 2.25 Watts

Historical Power Data | v Temperature Data | v Wi-Fi Activity | v Camera Activity | v AI Regression Model | v Predicted Power Consumption | v Power Optimization

24. AI Risk Score Logic


Multiple Face Detection      = +50 Points

Face Missing                 = +30 Points

Repeated Looking Away        = +20 Points

Repeated Suspicious Events   = Additional Points

Risk Score = Total Event Score

0 - 20      = NORMAL

21 - 50     = LOW RISK

51 - 75     = MEDIUM RISK

76 - 100    = HIGH RISK

25. AI Agent Architecture

PROCTORING DATA | v AI AGENT | +--------------+--------------+ | | | v v v ANALYZE RISK SCORE SUMMARY | | | +--------------+--------------+ | v AUTOMATION WORKFLOW | +---------------+---------------+ | | | v v v TELEGRAM GOOGLE SHEETS THINGSPEAK

26. Complete Project Workflow

STUDENT STARTS EXAM | v CAMERA CAPTURES VIDEO | v AI DETECTS FACE | v FACE TRACKING | v HEAD DIRECTION ANALYSIS | v SUSPICIOUS EVENT DETECTION | v ESP32 IoT DATA COLLECTION | v n8n WEBHOOK | v AI AGENT ANALYSIS | v RISK SCORE CALCULATION | +----------------+ | | v v NORMAL ALERT | | v v GOOGLE SHEETS TELEGRAM | | v v THINGSPEAK VOICE ALERT

27. Recommended Project Folder Structure


AI-Exam-Proctoring/

|

+-- esp32/

|   +-- exam_proctoring.ino

|

+-- ai/

|   +-- face_tracking.py

|   +-- face_detection.py

|   +-- requirements.txt

|

+-- web/

|   +-- index.php

|   +-- proctoring_event.php

|   +-- config.php

|   +-- proctoring_logs.json

|

+-- n8n/

|   +-- exam_proctoring_workflow.json

|

+-- database/

|   +-- exam_events.sql

|

+-- documentation/

    +-- project_report.md

28. Installation Procedure

Step 1: Install Arduino IDE

Install Arduino IDE and configure the ESP32 board package.

Step 2: Install Required Libraries

  • WiFi.h
  • HTTPClient.h
  • Wire.h
  • Adafruit GFX Library
  • Adafruit SSD1306 Library
  • DHT Sensor Library

Step 3: Configure Wi-Fi


const char* WIFI_SSID =

    "YOUR_WIFI_NAME";

const char* WIFI_PASSWORD =

    "YOUR_WIFI_PASSWORD";

Step 4: Upload ESP32 Firmware

  1. Connect ESP32 to computer.
  2. Select ESP32 board.
  3. Select COM port.
  4. Compile the program.
  5. Upload the program.
  6. Open Serial Monitor.

Step 5: Configure PHP Server

Place the PHP files inside the XAMPP htdocs folder.


C:/xampp/htdocs/proctoring/

Step 6: Configure n8n

  1. Create Webhook node.
  2. Add JSON processing node.
  3. Add IF condition.
  4. Add Telegram node.
  5. Add Google Sheets node.
  6. Add HTTP Request node for ThingSpeak.
  7. Add voice notification automation.
  8. Activate the workflow.

29. Security Recommendations

  • Use HTTPS communication.
  • Use API authentication tokens.
  • Protect the PHP API.
  • Use secure passwords.
  • Restrict database access.
  • Use role-based access control.
  • Do not store unnecessary raw video.
  • Protect biometric information.
  • Use encrypted communication.

30. Privacy and Responsible AI Design

Because this project uses face tracking and AI-based monitoring, it should be deployed responsibly.

  • Inform candidates about monitoring.
  • Obtain appropriate consent where required.
  • Avoid unnecessary storage of raw video.
  • Protect sensitive personal data.
  • Use AI alerts as review signals.
  • Do not automatically declare a student guilty based only on AI detection.
  • Provide human review for important examination decisions.
  • Consider false positives caused by poor lighting, camera failure and network problems.

31. Future Enhancements

  • Advanced face recognition.
  • Registered candidate verification.
  • Eye gaze tracking.
  • Advanced head pose estimation.
  • Multi-camera monitoring.
  • AI object detection.
  • Cloud database integration.
  • Mobile application.
  • AI-generated examination reports.
  • Advanced power consumption prediction.
  • Edge AI processing.
  • Offline event storage.
  • Multi-examination center support.

32. Final Project Abstract

The AI-Based Smart Exam Proctoring System Using Face Tracking is an intelligent examination monitoring solution that combines artificial intelligence, computer vision, ESP32-based IoT technology, cloud services and workflow automation.

The system continuously monitors a candidate's face during an examination and identifies events such as face absence, multiple faces and repeated head movement or looking away.

The ESP32 controller collects environmental and device information and communicates with the IoT webpage and cloud platforms.

Through n8n automation, the system processes detected events and automatically logs them into Google Sheets, updates the ThingSpeak cloud dashboard and sends real-time Telegram text and voice notifications to the examination supervisor.

An AI agent can analyze the complete event history, calculate a risk score and generate an examination monitoring summary.

The proposed system reduces the need for continuous manual supervision and provides a scalable, intelligent and automated platform for modern online and computer-based examinations.

33. Complete Technology Stack

Artificial Intelligence
Computer Vision
Face Tracking
ESP32
IoT
PHP Webpage
n8n Automation
AI Agent
Telegram Alerts
Voice Notifications
Google Sheets
ThingSpeak Cloud Dashboard
HTML; ?>

AI-Based Smart E-Voting System with Face Authentication

<?php echo $title; ?>

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

1. Full Project Description

2. Main Project Objectives

3. System Architecture

VOTER ↓ AI FACE AUTHENTICATION ↓ AUTHORIZED VOTER VERIFICATION ↓ WEB VOTING INTERFACE ↓ ESP32 IoT CONTROLLER ↓ n8n AUTOMATION WORKFLOW ↓ AI AGENT ANALYSIS ↓ GOOGLE SHEETS LOGGING ↓ THINGSPEAK CLOUD DASHBOARD ↓ TELEGRAM TEXT ALERT ↓ TELEGRAM VOICE ALERT

4. Hardware Components List

Component Purpose
Used for implementing the AI-powered IoT voting system.

5. Software Requirements

6. Circuit Schematic Diagram


                         +----------------------+
                         |        ESP32         |
                         |                      |
                         | GPIO 25 <------------ Button 1
                         | GPIO 26 <------------ Button 2
                         | GPIO 27 <------------ Button 3
                         | GPIO 14 <------------ Button 4
                         |                      |
                         | GPIO 21 ------------ SDA
                         | GPIO 22 ------------ SCL
                         |                      |
                         | GPIO 18 ------------ Buzzer
                         | GPIO 2  ------------ Auth LED
                         | GPIO 4  ------------ Vote LED
                         | GPIO 5  ------------ Error LED
                         +----------+-----------+
                                    |
              +---------------------+---------------------+
              |                     |                     |
              v                     v                     v
        +-----------+        +-----------+        +-------------+
        | OLED      |        | INA219    |        | ESP32-CAM   |
        | Display   |        | Sensor    |        | Camera      |
        +-----------+        +-----------+        +-------------+

7. Pin Connection Table

Device ESP32 Pin
Candidate Button 1 GPIO 25
Candidate Button 2 GPIO 26
Candidate Button 3 GPIO 27
Candidate Button 4 GPIO 14
OLED SDA GPIO 21
OLED SCL GPIO 22
Buzzer GPIO 18
Authentication LED GPIO 2
Voting LED GPIO 4
Error LED GPIO 5

8. Complete System Flowchart


START

↓

Initialize ESP32

↓

Connect Wi-Fi

↓

Initialize Camera

↓

Initialize Sensors

↓

Wait for Voter

↓

Capture Face

↓

AI Face Authentication

↓

Is Face Authorized?

├── NO
│
├── Display Authentication Failed
│
├── Record Failed Attempt
│
└── Send Telegram Alert

YES

↓

Check Duplicate Voting Status

↓

Already Voted?

├── YES
│
├── Reject Voting Attempt
│
└── Send Security Alert

NO

↓

Display Candidate Options

↓

Voter Selects Candidate

↓

Confirm Voting Selection

↓

Create Voting Event

↓

Send Event to n8n Webhook

↓

AI Agent Analysis

↓

Google Sheets Logging

↓

ThingSpeak Update

↓

Telegram Text Alert

↓

Telegram Voice Alert

↓

Update IoT Dashboard

↓

END

9. Data Flow Diagram

CAMERA ↓ FACE IMAGE ↓ AI FACE RECOGNITION ↓ AUTHENTICATION TOKEN ↓ ESP32 ↓ HTTPS / WEBHOOK ↓ n8n ↓ AI AGENT ↓ ┌───────────────────┬──────────────────┬───────────────────┐ │ │ │ GOOGLE SHEETS THINGSPEAK TELEGRAM │ │ │ VOTING LOG IoT DATA TEXT ALERT │ ↓ VOICE ALERT

10. ESP32 Source Code



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

const char* WIFI_SSID = "YOUR_WIFI_NAME";

const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";

const char* N8N_WEBHOOK_URL =
"https://your-n8n-domain.com/webhook/e-voting";

#define BUTTON_1 25
#define BUTTON_2 26
#define BUTTON_3 27
#define BUTTON_4 14

#define LED_AUTH 2
#define LED_VOTE 4
#define BUZZER 18

bool authenticated = false;

bool voteSubmitted = false;

void setup() {

    Serial.begin(115200);

    pinMode(BUTTON_1, INPUT_PULLUP);

    pinMode(BUTTON_2, INPUT_PULLUP);

    pinMode(BUTTON_3, INPUT_PULLUP);

    pinMode(BUTTON_4, INPUT_PULLUP);

    pinMode(LED_AUTH, OUTPUT);

    pinMode(LED_VOTE, OUTPUT);

    pinMode(BUZZER, 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() {

    if (!authenticated) {

        Serial.println("Waiting for AI Face Authentication");

        delay(3000);

        authenticated = true;

        digitalWrite(LED_AUTH, HIGH);

        tone(BUZZER, 1000, 300);

        Serial.println("Face Authentication Successful");

    }

    if (authenticated && !voteSubmitted) {

        digitalWrite(LED_VOTE, HIGH);

        if (digitalRead(BUTTON_1) == LOW) {

            submitVote("CANDIDATE_1");

        }

        if (digitalRead(BUTTON_2) == LOW) {

            submitVote("CANDIDATE_2");

        }

        if (digitalRead(BUTTON_3) == LOW) {

            submitVote("CANDIDATE_3");

        }

        if (digitalRead(BUTTON_4) == LOW) {

            submitVote("CANDIDATE_4");

        }

    }

}

void submitVote(String candidate) {

    voteSubmitted = true;

    digitalWrite(LED_VOTE, LOW);

    tone(BUZZER, 1500, 500);

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

        HTTPClient http;

        http.begin(N8N_WEBHOOK_URL);

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

        String jsonData = "{";

        jsonData += "\"event\":\"VOTE_SUBMITTED\",";

        jsonData += "\"candidate\":\"" + candidate + "\",";

        jsonData += "\"device\":\"ESP32_STATION_01\",";

        jsonData += "\"authentication\":\"FACE_AUTHENTICATED\"";

        jsonData += "}";

        int responseCode = http.POST(jsonData);

        Serial.print("n8n Response Code: ");

        Serial.println(responseCode);

        http.end();

    }

}

11. n8n Workflow Architecture


ESP32

↓

n8n Webhook Trigger

↓

Validate JSON Data

↓

Check Authentication

↓

Check Event Type

↓

AI Agent Analysis

↓

┌───────────────────────────┐
│                           │
▼                           ▼
Google Sheets          ThingSpeak
Logging                 Cloud Update
│                           │
└──────────────┬────────────┘
               ▼
        Telegram Notification
               │
               ▼
        Text-to-Speech
               │
               ▼
        Telegram Voice Alert

12. n8n Workflow JSON



{
  "name": "AI E-Voting IoT Automation",

  "nodes": [

    {
      "parameters": {
        "httpMethod": "POST",
        "path": "e-voting",
        "responseMode": "onReceived"
      },

      "name": "ESP32 Voting Webhook",

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

      "typeVersion": 2

    },

    {
      "parameters": {
        "jsCode": "const data = $json.body || $json;

return [{
  json: {
    event: data.event,
    candidate: data.candidate,
    device: data.device,
    authentication: data.authentication,
    timestamp: new Date().toISOString()
  }
}];"
      },

      "name": "Validate Voting Data",

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

      "typeVersion": 2

    },

    {
      "parameters": {
        "operation": "append",
        "documentId": "GOOGLE_SHEET_ID",
        "sheetName": "Votes"
      },

      "name": "Google Sheets Logging",

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

      "typeVersion": 4

    },

    {
      "parameters": {
        "method": "POST",
        "url": "https://api.thingspeak.com/update"
      },

      "name": "ThingSpeak Update",

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

      "typeVersion": 4

    },

    {
      "parameters": {
        "chatId": "TELEGRAM_CHAT_ID",
        "text": "New authenticated voting event received."
      },

      "name": "Telegram Notification",

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

      "typeVersion": 1

    }

  ]

}

13. Telegram Bot Setup

  1. Open Telegram.
  2. Search for BotFather.
  3. Execute the command /newbot.
  4. Enter a bot name.
  5. Enter a unique bot username.
  6. Copy the generated Bot Token.
  7. Send a message to your bot.
  8. Obtain the Telegram Chat ID.
  9. Add Telegram credentials inside n8n.
  10. Test a notification workflow.

14. Telegram Notification Examples


FACE AUTHENTICATION SUCCESSFUL

Voting Station:
ESP32_STATION_01

Status:
Authorized voter detected.

---------------------------------

VOTE EVENT

Candidate:
CANDIDATE_1

Station:
ESP32_STATION_01

Status:
Vote event recorded successfully.

---------------------------------

SECURITY ALERT

Multiple authentication failures detected.

Device:
ESP32_STATION_01

Action:
System monitoring activated.

15. Telegram Voice Notification Automation

VOTING EVENT ↓ n8n WEBHOOK ↓ AI AGENT ↓ GENERATE TEXT MESSAGE ↓ TEXT-TO-SPEECH SERVICE ↓ AUDIO FILE ↓ TELEGRAM SEND AUDIO

Example voice notification:

Attention. A new authenticated voting event has been recorded at voting station one.

16. Google Sheets Integration

Column Description
Timestamp Date and time of event
Event Type Voting or authentication event
Candidate Selected candidate identifier
Station ID ESP32 station identifier
Authentication Status Success or failure
Voltage Measured voltage
Current Measured current
Power Power consumption
AI Risk Level Low, medium or high

17. ThingSpeak Cloud Dashboard

ThingSpeak Field Data
Field 1 Voting Events
Field 2 Authentication Success
Field 3 Authentication Failures
Field 4 Voltage
Field 5 Current
Field 6 Power
Field 7 Energy
Field 8 AI Power Prediction

18. AI Power Consumption Prediction Logic


Voltage

+

Current

↓

Power Calculation

↓

Historical Power Data

↓

Average Power

↓

Voting Activity Factor

↓

AI Prediction

↓

Future Power Consumption

The basic electrical power relationship is:


Power = Voltage × Current

For example:


Voltage = 5 Volts

Current = 0.25 Amperes

Power = 5 × 0.25

Power = 1.25 Watts

19. AI Anomaly Detection

  • Too many authentication failures.
  • Repeated voting requests.
  • Unusual power consumption.
  • Unexpected ESP32 device activity.
  • Multiple requests from the same device.
  • Invalid API requests.

20. PHP IoT Dashboard



<?php

$esp32_status = "ONLINE";

$authentication_status = "ACTIVE";

$total_votes = 245;

$authentication_failures = 3;

$power_consumption = "1.25 W";

$ai_risk_level = "LOW";

?>

<!DOCTYPE html>

<html>

<head>

<title>AI Smart E-Voting Dashboard</title>

</head>

<body>

<h1>AI-Based Smart E-Voting IoT Dashboard</h1>

<p>ESP32 Status: <?php echo $esp32_status; ?></p>

<p>Face Authentication:
<?php echo $authentication_status; ?>
</p>

<p>Total Voting Events:
<?php echo $total_votes; ?>
</p>

<p>Authentication Failures:
<?php echo $authentication_failures; ?>
</p>

<p>Power Consumption:
<?php echo $power_consumption; ?>
</p>

<p>AI Risk Level:
<?php echo $ai_risk_level; ?>
</p>

</body>

</html>

21. Recommended Database Structure

Voter Table


voter_id

face_template_hash

authentication_status

voted_status

registration_timestamp

Vote Event Table


event_id

anonymous_voter_token

candidate_id

timestamp

station_id

22. Project Folder Structure


AI-E-VOTING-SYSTEM/

│

├── esp32/

│   └── smart_voting_esp32.ino

│

├── face-authentication/

│   ├── face_authentication.py

│   ├── authorized_users/

│   └── model/

│

├── web-dashboard/

│   ├── index.php

│   ├── dashboard.php

│   ├── config.php

│   └── api.php

│

├── n8n/

│   └── ai_e_voting_workflow.json

│

├── database/

│   └── database.sql

│

└── documentation/

    ├── circuit-diagram

    ├── flowchart

    └── project-report

23. Complete Project Operation

  1. Power ON the ESP32.
  2. ESP32 connects to Wi-Fi.
  3. Camera captures the voter face.
  4. AI face authentication verifies the voter.
  5. The system checks duplicate voting status.
  6. The voting interface displays candidates.
  7. The voter selects a candidate.
  8. ESP32 creates a voting event.
  9. ESP32 sends data to the n8n webhook.
  10. n8n validates the data.
  11. AI Agent analyzes the event.
  12. Google Sheets stores the event.
  13. ThingSpeak updates the IoT dashboard.
  14. Telegram sends a notification.
  15. Text-to-Speech generates a voice message.
  16. Telegram sends the voice alert.

24. Security Architecture


CAMERA

↓

AI FACE AUTHENTICATION

↓

AUTHENTICATION TOKEN

↓

ESP32

↓

HTTPS

↓

n8n WEBHOOK

↓

VALIDATION

↓

AI ANALYSIS

↓

CLOUD LOGGING

Recommended security features include HTTPS, API authentication, device authentication, secure Wi-Fi, encrypted credentials, duplicate-event protection, replay protection, timestamps and audit logs.

25. Future Enhancements

26. Final Complete Project Workflow


VOTER

↓

AI FACE AUTHENTICATION

↓

AUTHORIZED VOTER

↓

DUPLICATE VOTE CHECK

↓

VOTING INTERFACE

↓

CANDIDATE SELECTION

↓

ESP32

↓

n8n AUTOMATION

↓

AI AGENT

↓

GOOGLE SHEETS

↓

THINGSPEAK

↓

TELEGRAM TEXT ALERT

↓

TEXT-TO-SPEECH

↓

TELEGRAM VOICE ALERT

↓

AI POWER PREDICTION

↓

IOT CLOUD DASHBOARD

27. Project Summary

This project combines Artificial Intelligence, Face Authentication, ESP32 IoT technology, n8n workflow automation, AI Agents, Telegram notifications, voice alerts, Google Sheets, ThingSpeak cloud monitoring and AI power consumption prediction into a single intelligent e-voting IoT platform. The system provides a complete workflow from voter authentication to voting event processing, cloud data logging, AI analysis, IoT monitoring and real-time notification automation.

AI-Based Smart E-Voting System with Face Authentication

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

AI-Based Smart Border Surveillance Robot with Thermal Vision

AI-Based Smart Border Surveillance Robot with Thermal Vision"; echo "

Project Description

"; echo "

"; echo "The AI-Based Smart Border Surveillance Robot with Thermal Vision is an intelligent IoT-enabled mobile robotic platform designed for continuous monitoring of authorized borders, restricted areas, industrial perimeters, campuses, forests and remote inspection zones."; echo "

"; echo "

"; echo "The robot uses an ESP32 microcontroller as the main IoT controller. The system collects real-time information using thermal sensors, PIR motion sensors, ultrasonic distance sensors, GPS modules, environmental sensors and battery monitoring circuits."; echo "

"; echo "

"; echo "The collected data is transmitted to an n8n automation platform through Wi-Fi or another authorized communication network. An AI Agent analyzes the sensor data and generates an event interpretation."; echo "

"; echo "

"; echo "When a significant thermal or motion anomaly is detected, the system automatically generates an event, sends the event to the AI Agent, stores the data in Google Sheets, updates the ThingSpeak cloud dashboard and sends Telegram text and voice notifications to the authorized operator."; echo "

"; echo "

"; echo "The system also monitors battery voltage, current consumption and power usage. AI-based power consumption prediction can estimate future battery usage and identify abnormal power consumption."; echo "

"; echo "

"; echo "The robot is designed as a monitoring and alerting system. Final decisions remain with authorized human operators."; echo "

"; /* =========================================================== 2. MAIN OBJECTIVES =========================================================== */ echo "

Main Objectives

"; echo "
    "; echo "
  • Monitor authorized remote locations continuously.
  • "; echo "
  • Detect thermal anomalies.
  • "; echo "
  • Detect motion using PIR sensors.
  • "; echo "
  • Measure distance and detect obstacles.
  • "; echo "
  • Track robot GPS location.
  • "; echo "
  • Monitor battery voltage and current.
  • "; echo "
  • Send real-time Telegram alerts.
  • "; echo "
  • Generate Telegram voice notifications.
  • "; echo "
  • Store event information in Google Sheets.
  • "; echo "
  • Display sensor data using ThingSpeak.
  • "; echo "
  • Use AI Agent analysis for sensor events.
  • "; echo "
  • Automate workflows using n8n.
  • "; echo "
  • Predict future power consumption.
  • "; echo "
  • Provide a web-based IoT dashboard.
  • "; echo "
  • Support predictive maintenance.
  • "; echo "
"; /* =========================================================== 3. SYSTEM CONCEPT =========================================================== */ echo "

System Concept

"; echo "
";

echo "
REMOTE OPERATOR
      |
      v
WEB DASHBOARD + TELEGRAM
      |
      v
n8n AUTOMATION PLATFORM
      |
      +-----------------------+
      |                       |
      v                       v
AI AGENT              EVENT PROCESSING
      |                       |
      +-----------+-----------+
                  |
                  v
              ESP32 ROBOT
                  |
      +-----------+-----------+
      |           |           |
      v           v           v
THERMAL       PIR SENSOR   DISTANCE
SENSOR        MOTION        SENSOR
      |
      +-----------+-----------+
                  |
        +---------+---------+
        |                   |
        v                   v
      GPS          BATTERY MONITOR
        |
        v
   ENVIRONMENTAL SENSORS
";

echo "
"; /* =========================================================== 4. COMPONENTS LIST =========================================================== */ echo "

Hardware Components List

"; echo "

Main Controller

"; echo "
    "; echo "
  • ESP32 DevKit V1
  • "; echo "
  • ESP32-WROOM-32
  • "; echo "
  • ESP32-S3 for advanced processing
  • "; echo "
"; echo "

Thermal Vision

"; echo "
    "; echo "
  • AMG8833 Thermal Sensor
  • "; echo "
  • MLX90640 Thermal Sensor
  • "; echo "
  • Thermal Camera Module for advanced applications
  • "; echo "
"; echo "

Motion Detection

"; echo "
    "; echo "
  • HC-SR501 PIR Motion Sensor
  • "; echo "
"; echo "

Distance Measurement

"; echo "
    "; echo "
  • HC-SR04 Ultrasonic Sensor
  • "; echo "
"; echo "

GPS Tracking

"; echo "
    "; echo "
  • NEO-6M GPS Module
  • "; echo "
  • NEO-M8N GPS Module
  • "; echo "
"; echo "

Environmental Sensors

"; echo "
    "; echo "
  • DHT22 Temperature and Humidity Sensor
  • "; echo "
  • BME280 Temperature, Humidity and Pressure Sensor
  • "; echo "
  • Air Quality Sensors
  • "; echo "
  • Rain Sensor
  • "; echo "
  • Light Sensor
  • "; echo "
"; echo "

Battery Monitoring

"; echo "
    "; echo "
  • INA219 Current Sensor
  • "; echo "
  • INA226 Current Sensor
  • "; echo "
  • Voltage Divider
  • "; echo "
  • Rechargeable Battery Pack
  • "; echo "
  • Battery Management System
  • "; echo "
"; echo "

Motor System

"; echo "
    "; echo "
  • DC Geared Motors
  • "; echo "
  • Robot Wheels
  • "; echo "
  • L298N Motor Driver
  • "; echo "
  • TB6612FNG Motor Driver
  • "; echo "
  • BTS7960 High Current Motor Driver
  • "; echo "
"; echo "

Communication

"; echo "
    "; echo "
  • Wi-Fi Communication
  • "; echo "
  • 4G/LTE Communication
  • "; echo "
  • LoRa Communication
  • "; echo "
"; /* =========================================================== 5. CIRCUIT SCHEMATIC DIAGRAM =========================================================== */ echo "

Circuit Schematic Diagram

"; echo "
";

echo "
                         +----------------------+
                         |      ESP32 DEVKIT    |
                         |                      |
          +--------------| GPIO21 SDA          |
          |              | GPIO22 SCL          |
          |              | GPIO27              |
          |              | GPIO5               |
          |              | GPIO18              |
          |              | GPIO16 RX           |
          |              | GPIO17 TX           |
          |              | GPIO25              |
          |              | GPIO26              |
          |              | GPIO32              |
          |              | GPIO33              |
          |              +----------+-----------+
          |                         |
          |                         |
     +----v-----+             +-----v------+
     | Thermal  |             | INA219     |
     | Sensor   |             | Current    |
     +----------+             | Sensor     |
                               +------------+

     +-----------+        +--------------+
     | GPS       |        | Ultrasonic   |
     | NEO-6M    |        | HC-SR04      |
     +-----------+        +--------------+

                  +----------------+
                  | Motor Driver   |
                  | L298N/TB6612   |
                  +-------+--------+
                          |
                +---------+---------+
                |                   |
          +-----v-----+       +-----v-----+
          | Left Motor|       |Right Motor|
          +-----------+       +-----------+

                    BATTERY PACK
                         |
                 +-------v--------+
                 | Power Regulation|
                 | 5V / 3.3V       |
                 +----------------+
";

echo "
"; /* =========================================================== 6. ESP32 PIN CONNECTIONS =========================================================== */ echo "

ESP32 Pin Connections

"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
DevicePinESP32 GPIO
Thermal Sensor SDASDAGPIO 21
Thermal Sensor SCLSCLGPIO 22
PIR SensorOUTGPIO 27
Ultrasonic TriggerTRIGGPIO 5
Ultrasonic EchoECHOGPIO 18
GPS RXRXGPIO 16
GPS TXTXGPIO 17
Motor Driver IN1IN1GPIO 25
Motor Driver IN2IN2GPIO 26
Motor Driver IN3IN3GPIO 32
Motor Driver IN4IN4GPIO 33
"; /* =========================================================== 7. OPERATIONAL FLOWCHART =========================================================== */ echo "

Operational Flowchart

"; echo "
";

echo "
START
  |
  v
Initialize ESP32 Hardware
  |
  v
Connect Wi-Fi
  |
  v
Read Sensors
  |
  +----------------------------+
  |                            |
  v                            v
Thermal Data              Motion Data
  |                            |
  +-------------+--------------+
                |
                v
       Detect Thermal Anomaly?
                |
          +-----+-----+
          |           |
         NO          YES
          |           |
          |           v
          |     Check Motion
          |           |
          |           v
          |     Motion Detected?
          |           |
          |      +----+----+
          |      |         |
          |     NO        YES
          |      |         |
          |      v         v
          |    NORMAL   CREATE EVENT
          |                  |
          |                  v
          |             SEND TO n8n
          |                  |
          |                  v
          |              AI ANALYSIS
          |                  |
          |                  v
          |            EVENT PRIORITY
          |                  |
          |        +---------+---------+
          |        |                   |
          |        v                   v
          |     HIGH PRIORITY       NORMAL
          |        |                   |
          |        v                   v
          |     TELEGRAM            LOG DATA
          |     ALERT               TO CLOUD
          |        |
          |        v
          |     VOICE ALERT
          |
          v
      UPDATE DASHBOARD
          |
          v
      POWER ANALYSIS
          |
          v
      REPEAT LOOP
";

echo "
"; /* =========================================================== 8. ESP32 SOURCE CODE =========================================================== */ echo "

ESP32 Source Code

"; echo "
";

echo htmlspecialchars('
#include 
#include 
#include 
#include 
#include 

const char* WIFI_SSID = "YOUR_WIFI_NAME";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";

const char* N8N_WEBHOOK_URL =
"https://your-n8n-domain.com/webhook/border-surveillance";

#define PIR_PIN 27
#define TRIG_PIN 5
#define ECHO_PIN 18

Adafruit_AMG88xx thermal;

unsigned long lastSendTime = 0;

const unsigned long SEND_INTERVAL = 10000;

float readDistance()
{
    digitalWrite(TRIG_PIN, LOW);

    delayMicroseconds(2);

    digitalWrite(TRIG_PIN, HIGH);

    delayMicroseconds(10);

    digitalWrite(TRIG_PIN, LOW);

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

    float distance = duration * 0.034 / 2;

    return distance;
}

float calculateThermalAverage()
{
    float pixels[64];

    thermal.readPixels(pixels);

    float total = 0;

    for (int i = 0; i < 64; i++)
    {
        total += pixels[i];
    }

    return total / 64.0;
}

float calculateMaximumTemperature()
{
    float pixels[64];

    thermal.readPixels(pixels);

    float maximumTemperature = pixels[0];

    for (int i = 1; i < 64; i++)
    {
        if (pixels[i] > maximumTemperature)
        {
            maximumTemperature = pixels[i];
        }
    }

    return maximumTemperature;
}

void sendDataToN8N(
    float averageTemperature,
    float maximumTemperature,
    int motion,
    float distance
)
{
    if (WiFi.status() != WL_CONNECTED)
    {
        Serial.println("WiFi disconnected");

        return;
    }

    HTTPClient http;

    http.begin(N8N_WEBHOOK_URL);

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

    StaticJsonDocument<1024> json;

    json["device_id"] = "BORDER_ROBOT_001";

    json["average_temperature"] =
        averageTemperature;

    json["maximum_temperature"] =
        maximumTemperature;

    json["motion_detected"] =
        motion;

    json["distance_cm"] =
        distance;

    json["battery_voltage"] =
        11.8;

    json["battery_current"] =
        1.25;

    json["timestamp"] =
        millis();

    String payload;

    serializeJson(json, payload);

    int responseCode =
        http.POST(payload);

    Serial.print("n8n Response: ");

    Serial.println(responseCode);

    http.end();
}

void setup()
{
    Serial.begin(115200);

    pinMode(PIR_PIN, INPUT);

    pinMode(TRIG_PIN, OUTPUT);

    pinMode(ECHO_PIN, INPUT);

    Wire.begin();

    if (!thermal.begin())
    {
        Serial.println(
            "Thermal sensor not detected"
        );

        while (true)
        {
            delay(1000);
        }
    }

    WiFi.begin(
        WIFI_SSID,
        WIFI_PASSWORD
    );

    while (
        WiFi.status() != WL_CONNECTED
    )
    {
        delay(500);

        Serial.print(".");
    }

    Serial.println();

    Serial.println(
        "WiFi Connected"
    );
}

void loop()
{
    if (
        millis() - lastSendTime
        >= SEND_INTERVAL
    )
    {
        lastSendTime = millis();

        int motionDetected =
            digitalRead(PIR_PIN);

        float averageTemperature =
            calculateThermalAverage();

        float maximumTemperature =
            calculateMaximumTemperature();

        float distance =
            readDistance();

        bool thermalEvent =
            maximumTemperature > 30.0;

        bool eventDetected =
            thermalEvent &&
            motionDetected == HIGH;

        if (eventDetected)
        {
            Serial.println(
                "THERMAL MOTION EVENT DETECTED"
            );

            sendDataToN8N(
                averageTemperature,
                maximumTemperature,
                motionDetected,
                distance
            );
        }
        else
        {
            Serial.println(
                "No significant event"
            );
        }
    }
}
');

echo "
"; /* =========================================================== 9. n8n WORKFLOW =========================================================== */ echo "

n8n Workflow

"; echo "
";

echo "
ESP32
  |
  v
WEBHOOK
  |
  v
VALIDATE JSON
  |
  v
CALCULATE CONFIDENCE
  |
  v
AI AGENT
  |
  v
EVENT CLASSIFICATION
  |
  +------------------+
  |                  |
  v                  v
HIGH PRIORITY      NORMAL
  |                  |
  v                  v
TELEGRAM ALERT    GOOGLE SHEETS
  |
  v
VOICE ALERT
  |
  v
THINGSPEAK UPDATE
  |
  v
WEB DASHBOARD
";

echo "
"; /* =========================================================== 10. n8n WORKFLOW JSON =========================================================== */ echo "

n8n Workflow JSON

"; echo "
";

echo htmlspecialchars('
{
  "name": "AI Border Surveillance Robot Automation",

  "nodes": [

    {
      "name": "ESP32 Webhook",

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

      "parameters": {

        "httpMethod": "POST",

        "path":
        "border-surveillance"

      }
    },

    {
      "name": "AI Event Scoring",

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

      "parameters": {

        "jsCode":

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

        let thermalScore = 0;

        let motionScore = 0;

        if (
          data.maximum_temperature >= 35
        )
        {
          thermalScore = 90;
        }
        else if (
          data.maximum_temperature >= 30
        )
        {
          thermalScore = 60;
        }
        else
        {
          thermalScore = 20;
        }

        if (
          data.motion_detected === 1
        )
        {
          motionScore = 90;
        }
        else
        {
          motionScore = 10;
        }

        const confidence =
          (thermalScore * 0.60) +
          (motionScore * 0.40);

        return [
          {
            json:
            {
              ...data,

              thermal_score:
              thermalScore,

              motion_score:
              motionScore,

              confidence_score:
              confidence,

              priority:
              confidence >= 75
              ? 'HIGH'
              : 'LOW'
            }
          }
        ];"
      }
    },

    {
      "name": "High Priority Event",

      "type":
      "n8n-nodes-base.if",

      "parameters": {

        "conditions": {

          "string": [

            {

              "value1":
              "={{$json.priority}}",

              "operation":
              "equal",

              "value2":
              "HIGH"

            }

          ]

        }

      }

    },

    {

      "name":
      "Telegram Alert",

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

      "parameters": {

        "text":

        "HIGH PRIORITY THERMAL EVENT

        Device:
        {{$json.device_id}}

        Maximum Temperature:
        {{$json.maximum_temperature}}

        Motion:
        {{$json.motion_detected}}

        Confidence:
        {{$json.confidence_score}}%"

      }

    }

  ]

}
');

echo "
"; /* =========================================================== 11. TELEGRAM BOT SETUP =========================================================== */ echo "

Telegram Bot Setup

"; echo "
    "; echo "
  1. Open Telegram.
  2. "; echo "
  3. Search for BotFather.
  4. "; echo "
  5. Send /start.
  6. "; echo "
  7. Send /newbot.
  8. "; echo "
  9. Enter a bot name.
  10. "; echo "
  11. Enter a unique bot username.
  12. "; echo "
  13. Copy the generated Bot Token.
  14. "; echo "
  15. Configure the token in n8n Credentials.
  16. "; echo "
  17. Send a message to the bot.
  18. "; echo "
  19. Find the authorized Telegram Chat ID.
  20. "; echo "
  21. Use the Chat ID in the n8n Telegram node.
  22. "; echo "
"; /* =========================================================== 12. TELEGRAM ALERT FORMAT =========================================================== */ echo "

Telegram Alert Format

"; echo "
";

echo "
AIoT SURVEILLANCE ALERT

Device:
BORDER_ROBOT_001

Event:
Thermal and Motion Anomaly

Maximum Temperature:
36.8 Celsius

Motion:
Detected

Confidence:
87 Percent

Battery:
11.8 Volts

Location:
GPS Coordinates Available

Status:
Operator Review Required
";

echo "
"; /* =========================================================== 13. VOICE NOTIFICATION AUTOMATION =========================================================== */ echo "

Voice Notification Automation

"; echo "
";

echo "
SENSOR EVENT
      |
      v
n8n WEBHOOK
      |
      v
AI AGENT
      |
      v
GENERATE ALERT TEXT
      |
      v
TEXT-TO-SPEECH SERVICE
      |
      v
GENERATE AUDIO
      |
      v
TELEGRAM SEND AUDIO
";

echo "
"; echo "

"; echo "Example voice message: Attention. A high-confidence thermal and motion anomaly has been detected. Please review the event using the monitoring dashboard."; echo "

"; /* =========================================================== 14. GOOGLE SHEETS INTEGRATION =========================================================== */ echo "

Google Sheets Integration

"; echo "

The Google Sheet can contain the following columns:

"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
TimestampDevice IDTemperatureMotionDistanceBatteryConfidencePriority
2026-07-20BORDER_ROBOT_00136.8Detected215 cm11.8 V87%HIGH
"; /* =========================================================== 15. THINGSPEAK DASHBOARD =========================================================== */ echo "

ThingSpeak Cloud Dashboard

"; echo "
    "; echo "
  • Field 1: Maximum Temperature
  • "; echo "
  • Field 2: Average Temperature
  • "; echo "
  • Field 3: Motion Status
  • "; echo "
  • Field 4: Distance
  • "; echo "
  • Field 5: Battery Voltage
  • "; echo "
  • Field 6: Battery Current
  • "; echo "
  • Field 7: Power Consumption
  • "; echo "
  • Field 8: AI Confidence Score
  • "; echo "
"; /* =========================================================== 16. AI POWER CONSUMPTION PREDICTION =========================================================== */ echo "

AI Power Consumption Prediction

"; echo "

"; echo "The system records battery voltage, battery current, motor activity, travel time, temperature, power consumption and robot operating conditions."; echo "

"; echo "

"; echo "Power consumption is calculated using the voltage and current measurements."; echo "

"; echo "

"; echo "Power = Voltage multiplied by Current"; echo "

"; echo "

"; echo "Energy = Power multiplied by Time"; echo "

"; echo "
";

echo "
BATTERY DATA
     |
     v
VOLTAGE + CURRENT
     |
     v
POWER CALCULATION
     |
     v
HISTORICAL DATA
     |
     v
AI PREDICTION
     |
     v
BATTERY RUNTIME ESTIMATION
     |
     v
MAINTENANCE ALERT
";

echo "
"; /* =========================================================== 17. POWER PREDICTION JAVASCRIPT FOR n8n =========================================================== */ echo "

Power Prediction Logic

"; echo "
";

echo htmlspecialchars('
const voltage =
    Number($json.battery_voltage);

const current =
    Number($json.battery_current);

const power =
    voltage * current;

const batteryCapacityWh =
    120;

const estimatedRuntimeHours =
    batteryCapacityWh / power;

let status =
    "NORMAL";

if (power > 30)
{
    status =
        "HIGH POWER CONSUMPTION";
}

if (
    estimatedRuntimeHours < 2
)
{
    status =
        "LOW ESTIMATED RUNTIME";
}

return [

    {

        json:
        {

            ...$json,

            power_watts:
            power,

            estimated_runtime_hours:
            estimatedRuntimeHours,

            power_status:
            status

        }

    }

];
');

echo "
"; /* =========================================================== 18. IOT WEBPAGE DASHBOARD =========================================================== */ echo "

IoT Webpage Dashboard

"; echo "
"; echo "

AI BORDER SURVEILLANCE ROBOT

"; echo "

Robot Status: ONLINE

"; echo "

Battery: 82%

"; echo "

Wi-Fi: CONNECTED

"; echo "

Thermal Temperature: 36.8 Celsius

"; echo "

Motion: DETECTED

"; echo "

AI Confidence: 87%

"; echo "

GPS Location Available

"; echo "

Power Consumption Monitoring Active

"; echo "
"; /* =========================================================== 19. FUTURE ENHANCEMENTS =========================================================== */ echo "

Future Enhancements

"; echo "
    "; echo "
  • Higher-resolution thermal cameras.
  • "; echo "
  • Edge AI processing.
  • "; echo "
  • 4G and LTE connectivity.
  • "; echo "
  • Solar charging system.
  • "; echo "
  • GPS geofencing.
  • "; echo "
  • Multi-robot coordination.
  • "; echo "
  • Predictive maintenance.
  • "; echo "
  • Offline data storage.
  • "; echo "
  • Secure firmware updates.
  • "; echo "
  • Advanced AI thermal classification.
  • "; echo "
  • Cloud-based analytics.
  • "; echo "
  • Battery health prediction.
  • "; echo "
"; /* =========================================================== 20. DEPLOYMENT GUIDE =========================================================== */ echo "

Deployment Guide

"; echo "

Phase 1: Laboratory Prototype

"; echo "

"; echo "Connect the ESP32, thermal sensor, PIR sensor, ultrasonic sensor, motor driver and battery monitoring circuit. Test all sensors individually."; echo "

"; echo "

Phase 2: IoT Integration

"; echo "

"; echo "Connect the ESP32 to n8n using a secure webhook. Configure Telegram, Google Sheets and ThingSpeak integrations."; echo "

"; echo "

Phase 3: Controlled Outdoor Testing

"; echo "

"; echo "Test the system in an authorized and controlled environment. Verify thermal detection, Wi-Fi range, battery runtime and sensor reliability."; echo "

"; echo "

Phase 4: Advanced Deployment

"; echo "

"; echo "Add cellular communication, solar power, advanced thermal cameras, edge AI and secure cloud infrastructure."; echo "

"; /* =========================================================== 21. SECURITY REQUIREMENTS =========================================================== */ echo "

Security Requirements

"; echo "
    "; echo "
  • Use HTTPS communication.
  • "; echo "
  • Protect API keys.
  • "; echo "
  • Use secure n8n credentials.
  • "; echo "
  • Use strong Wi-Fi passwords.
  • "; echo "
  • Restrict Telegram bot access.
  • "; echo "
  • Use authentication for the dashboard.
  • "; echo "
  • Use encrypted communication.
  • "; echo "
  • Maintain audit logs.
  • "; echo "
  • Use secure firmware update mechanisms.
  • "; echo "
  • Do not store passwords or tokens in public source code.
  • "; echo "
"; /* =========================================================== 22. COMPLETE PROJECT ARCHITECTURE =========================================================== */ echo "

Complete Project Architecture

"; echo "
";

echo "
THERMAL VISION
      |
      v
ESP32 ROBOT
      |
      +-------------------------+
      |                         |
      v                         v
SENSORS                    MOTOR CONTROL
      |
      v
Wi-Fi / 4G / LoRa
      |
      v
n8n AUTOMATION SERVER
      |
      +----------------------+
      |                      |
      v                      v
AI AGENT              POWER PREDICTION
      |
      +----------+-----------+
      |          |           |
      v          v           v
TELEGRAM   GOOGLE SHEETS  THINGSPEAK
      |          |           |
      v          v           v
VOICE       EVENT LOGS    CLOUD GRAPHS
      |
      v
WEB DASHBOARD
      |
      v
AUTHORIZED OPERATOR
";

echo "
"; /* =========================================================== 23. CONCLUSION =========================================================== */ echo "

Conclusion

"; echo "

"; echo "The AI-Based Smart Border Surveillance Robot with Thermal Vision combines ESP32, thermal sensing, IoT communication, AI Agent processing, n8n automation, Telegram alerts, voice notifications, Google Sheets logging, ThingSpeak cloud monitoring and AI power prediction."; echo "

"; echo "

"; echo "The complete system provides continuous remote monitoring, thermal anomaly detection, motion detection, automated cloud data logging, real-time notifications, voice alerts, power monitoring and predictive maintenance."; echo "

"; echo "

"; echo "The system is designed for authorized monitoring and inspection applications. Human operators should remain responsible for final decisions and response actions."; echo "

"; ?>