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 "
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 "
Thermal Vision
"; echo "- ";
echo "
- AMG8833 Thermal Sensor "; echo "
- MLX90640 Thermal Sensor "; echo "
- Thermal Camera Module for advanced applications "; echo "
Motion Detection
"; echo "- ";
echo "
- HC-SR501 PIR Motion Sensor "; echo "
Distance Measurement
"; echo "- ";
echo "
- HC-SR04 Ultrasonic Sensor "; echo "
GPS Tracking
"; echo "- ";
echo "
- NEO-6M GPS Module "; echo "
- NEO-M8N GPS Module "; 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 "
Battery Monitoring
"; echo "- ";
echo "
- INA219 Current Sensor "; echo "
- INA226 Current Sensor "; echo "
- Voltage Divider "; echo "
- Rechargeable Battery Pack "; echo "
- Battery Management System "; 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 "
Communication
"; echo "- ";
echo "
- Wi-Fi Communication "; echo "
- 4G/LTE Communication "; echo "
- LoRa Communication "; 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 "| Device | Pin | ESP32 GPIO |
|---|---|---|
| Thermal Sensor SDA | SDA | GPIO 21 |
| Thermal Sensor SCL | SCL | GPIO 22 |
| PIR Sensor | OUT | GPIO 27 |
| Ultrasonic Trigger | TRIG | GPIO 5 |
| Ultrasonic Echo | ECHO | GPIO 18 |
| GPS RX | RX | GPIO 16 |
| GPS TX | TX | GPIO 17 |
| Motor Driver IN1 | IN1 | GPIO 25 |
| Motor Driver IN2 | IN2 | GPIO 26 |
| Motor Driver IN3 | IN3 | GPIO 32 |
| Motor Driver IN4 | IN4 | GPIO 33 |
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 "
- Open Telegram. "; echo "
- Search for BotFather. "; echo "
- Send /start. "; echo "
- Send /newbot. "; echo "
- Enter a bot name. "; echo "
- Enter a unique bot username. "; echo "
- Copy the generated Bot Token. "; echo "
- Configure the token in n8n Credentials. "; echo "
- Send a message to the bot. "; echo "
- Find the authorized Telegram Chat ID. "; echo "
- Use the Chat ID in the n8n Telegram node. "; 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 "| Timestamp | "; echo "Device ID | "; echo "Temperature | "; echo "Motion | "; echo "Distance | "; echo "Battery | "; echo "Confidence | "; echo "Priority | "; echo "
|---|---|---|---|---|---|---|---|
| 2026-07-20 | "; echo "BORDER_ROBOT_001 | "; echo "36.8 | "; echo "Detected | "; echo "215 cm | "; echo "11.8 V | "; echo "87% | "; echo "HIGH | "; 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 "
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 "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 "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 "
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 "
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 "
"; ?>
No comments:
Post a Comment