Sunday, 16 August 2026

AI Based Accident Prevention System using NVIDIA Jetson Nano

Absolutely. Below is a complete final-year/major-project style design and documentation for:

AI-Based Accident Prevention and Intelligent IoT Alert System Using NVIDIA Jetson Nano, ESP32, AI Agent, n8n, Telegram, Google Sheets and ThingSpeak

The design combines edge AI + ESP32 sensors + IoT + an n8n agentic workflow + cloud dashboard + Telegram voice alerts.

Important design point: ESP32 does not need to run a large language model itself. In this architecture, the ESP32 is the sensing/actuation device, while the AI Agent runs in n8n/cloud or on an available AI server. The Jetson Nano performs the computer-vision inference locally.

The NVIDIA Jetson Nano has a 128-core Maxwell GPU and supports CUDA, TensorRT and computer-vision/deep-learning workloads. For the Nano specifically, JetPack 4.6.6 is the final JetPack 4 release and supports Jetson Nano.


1. Project title

AI-Based Accident Prevention and Intelligent IoT Alert System Using NVIDIA Jetson Nano, ESP32, Agentic AI, n8n Automation and Telegram Voice Notifications

Short title

AI Accident Prevention & Agentic IoT System

Technologies

  • NVIDIA Jetson Nano
  • ESP32
  • USB/CSI camera
  • MPU6050 accelerometer/gyroscope
  • Ultrasonic sensor
  • GPS module, optional
  • Buzzer
  • LEDs
  • Relay/motor-control output, optional
  • Wi-Fi
  • Computer Vision
  • YOLO object detection
  • Python
  • OpenCV
  • TensorRT
  • MQTT/HTTP
  • n8n
  • AI Agent
  • Telegram Bot
  • Telegram voice notifications
  • Google Sheets
  • ThingSpeak
  • HTML/CSS/JavaScript
  • REST APIs

2. Abstract

The proposed system is an AI-powered accident prevention and emergency notification platform designed for vehicles, robots, industrial equipment or smart transportation applications.

The system combines an NVIDIA Jetson Nano for real-time camera-based AI analysis with an ESP32 for collecting physical sensor information such as acceleration, vibration, distance and optional GPS data.

The Jetson Nano processes the camera stream using an object-detection model. The ESP32 continuously measures sensor parameters. These two data sources are combined into a risk/fusion engine.

For example:

Vehicle detected
+
Vehicle approaching obstacle
+
High acceleration/deceleration
+
Abnormal vibration
+
Unsafe distance
AI Risk Engine
LOW / MEDIUM / HIGH / CRITICAL

When a dangerous situation is detected, the system sends the event to an n8n automation workflow.

n8n then acts as the orchestration layer:

Jetson/ESP32
n8n Webhook
Data Validation
AI Agent
Risk Interpretation
┌───┼────────┬───────────┐
↓ ↓ ↓ ↓
Telegram Google ThingSpeak Dashboard
Voice Sheets
Alert

n8n's Webhook node can expose an HTTP endpoint for external devices and applications, while its Google Sheets and Telegram integrations can automate data logging and notifications.

ThingSpeak provides REST/MQTT interfaces for storing and visualizing IoT channel data.


3. Main objective

The primary objective is:

To develop an intelligent accident-prevention system capable of detecting dangerous situations using computer vision and physical sensors, locally assessing risk, and automatically notifying users through an AI-powered IoT automation system.


4. Secondary objectives

  1. Detect vehicles, people and obstacles using AI.
  2. Measure acceleration and vibration.
  3. Measure distance from obstacles.
  4. Detect sudden impact/deceleration.
  5. Calculate an accident-risk score.
  6. Prevent an accident when possible by giving an early warning.
  7. Generate an emergency event when an accident is suspected.
  8. Send sensor data to the cloud.
  9. Store accident records in Google Sheets.
  10. Display IoT data using ThingSpeak.
  11. Generate intelligent explanations using an AI Agent.
  12. Send Telegram notifications.
  13. Send Telegram voice alerts for critical events.
  14. Maintain an event history.
  15. Provide a web dashboard.

5. Proposed system architecture

High-level architecture

┌─────────────────────────┐
│ CAMERA │
│ USB / CSI Camera │
└────────────┬────────────┘
┌─────────────────────────┐
│ NVIDIA JETSON NANO │
│ │
│ OpenCV │
│ YOLO Object Detection │
│ TensorRT │
│ Risk Detection │
└────────────┬────────────┘
│ HTTP/JSON
┌─────────────────┐ ┌──────────────────────┐
│ ESP32 │ │ n8n AUTOMATION │
│ │ Wi-Fi │ │
│ MPU6050 ├─────────►│ Webhook │
│ Ultrasonic │ │ Data Processing │
│ GPS │ │ AI Agent │
│ Buzzer │ │ Decision Engine │
│ LED │ │ │
└───────┬─────────┘ └──────┬───────┬───────┘
│ │ │
│ │ │
▼ ▼ ▼
Local Warning Telegram Google
Buzzer/LED Voice Sheets
Alert
User/Admin
┌───────────┐
│ ThingSpeak│
│ Dashboard │
└───────────┘

6. Detailed block diagram

┌─────────────────────────┐
│ VEHICLE │
│ / ROBOT / TEST PLATFORM │
└───────────┬─────────────┘
┌───────────────┴────────────────┐
│ │
▼ ▼
┌─────────────┐ ┌──────────────┐
│ CAMERA │ │ ESP32 │
└──────┬──────┘ └──────┬───────┘
│ │
▼ │
┌─────────────┐ │
│ Jetson Nano │◄────────────────────────┘
│ │ Sensor Data
│ YOLO │
│ OpenCV │
│ TensorRT │
└──────┬──────┘
┌─────────────┐
│ Risk Fusion │
│ Engine │
└──────┬──────┘
┌─────┴──────┐
│ │
▼ ▼
SAFE/WARNING ACCIDENT
│ │
└─────┬──────┘
┌─────────────┐
│ n8n Webhook │
└──────┬──────┘
┌─────────────┐
│ AI Agent │
└──────┬──────┘
┌──────┼───────────┬────────────┐
▼ ▼ ▼ ▼
Telegram Google ThingSpeak Web Dashboard
Voice Sheets

7. Hardware requirements

Required hardware

Component Quantity Purpose
NVIDIA Jetson Nano 1 AI processing
ESP32 DevKit 1 Sensor/IoT controller
Camera 1 Accident/obstacle vision
MPU6050 1 Acceleration + gyroscope
HC-SR04 1 Distance detection
Buzzer 1 Local warning
LED 2–3 Status indication
220 Ω resistor 2–3 LED protection
Breadboard 1 Prototyping
Jumper wires As required Connections
Wi-Fi 1 Internet communication
GPS NEO-6M Optional Location
Power supply As required Power

8. Optional hardware

For a more advanced version:

  • ESP32-CAM
  • GPS
  • OLED display
  • GSM/LTE module
  • Motor driver
  • Relay
  • Emergency button
  • Alcohol sensor
  • Temperature sensor
  • Heart-rate sensor
  • Steering sensor
  • Wheel-speed sensor

9. ESP32 sensor subsystem

The ESP32 collects:

MPU6050

  • Acceleration X
  • Acceleration Y
  • Acceleration Z
  • Gyroscope X
  • Gyroscope Y
  • Gyroscope Z

Ultrasonic

  • Distance to obstacle

GPS

  • Latitude
  • Longitude
  • Speed

Local warning

  • Buzzer
  • Red LED
  • Green LED

10. ESP32 schematic

A practical connection is:

ESP32
┌────────────────────┐
│ │
│ GPIO 21 ──────────┼──── SDA
│ GPIO 22 ──────────┼──── SCL
│ │
│ GPIO 5 ───────────┼──── HC-SR04 TRIG
│ GPIO 18 ◄─────────┼──── HC-SR04 ECHO
│ │
│ GPIO 25 ──────────┼──── BUZZER
│ GPIO 26 ──────────┼──── GREEN LED
│ GPIO 27 ──────────┼──── RED LED
│ │
└────────────────────┘
│ I2C
┌────────────┐
│ MPU6050 │
│ │
│ VCC │
│ GND │
│ SDA │
│ SCL │
└────────────┘

Important HC-SR04 note

Do not directly connect a 5 V HC-SR04 ECHO output to an ESP32 GPIO. Use a voltage divider/level shifter so that the ESP32 receives a safe logic voltage.


11. Recommended ESP32 pin table

Device ESP32 pin
MPU6050 SDA GPIO 21
MPU6050 SCL GPIO 22
HC-SR04 TRIG GPIO 5
HC-SR04 ECHO GPIO 18 through level shifting
Buzzer GPIO 25
Green LED GPIO 26
Red LED GPIO 27
GPS RX GPIO 16
GPS TX GPIO 17

Pins can be changed in software.


12. Accident prevention concept

The system should not simply ask:

"Did an accident happen?"

It should ask:

"Is the current situation becoming dangerous?"

Therefore the system has four levels.

Level 0 — SAFE

Risk = 0–29

No action.

Level 1 — WARNING

Risk = 30–49

Local buzzer/LED warning.

Level 2 — HIGH RISK

Risk = 50–74

n8n receives event.

Telegram warning can be generated.

Level 3 — CRITICAL

Risk = 75–100

Emergency workflow.

Telegram text
+
Telegram voice
+
Google Sheets
+
ThingSpeak
+
Dashboard

13. Risk calculation

A simple explainable model is better for a college project than claiming that a random AI model directly "predicts accidents."

For example:

Risk Score =
0.30 × Vision Risk
+ 0.25 × Acceleration Risk
+ 0.20 × Distance Risk
+ 0.15 × Speed Risk
+ 0.10 × Vibration Risk

Each component is normalized from 0–100.

Example:

Vision risk = 80
Acceleration = 70
Distance risk = 90
Speed risk = 60
Vibration = 40
Risk =
0.30(80)
+0.25(70)
+0.20(90)
+0.15(60)
+0.10(40)
= 24 + 17.5 + 18 + 9 + 4
= 72.5

Therefore:

72.5 → HIGH RISK

14. Computer vision subsystem

The camera is connected to Jetson Nano.

The processing pipeline is:

Camera
Frame Capture
Resize
YOLO inference
Object Detection
Vehicle/person detection
Distance estimation
Time-to-collision estimation
Vision Risk

YOLO can detect classes such as:

person
car
motorcycle
bus
truck
bicycle
traffic light

15. Why Jetson Nano?

The Jetson Nano is suitable for edge AI because it provides GPU acceleration and interfaces including camera, GPIO, I²C, SPI and UART.

The recommended Nano software baseline is:

Jetson Nano
JetPack 4.6.6
Jetson Linux R32.7.6
Ubuntu 18.04-based environment
CUDA / cuDNN / TensorRT
Python + OpenCV

JetPack 4.6.6 is the final JetPack 4 release, so this is an important consideration for a new project: the Nano is excellent for a prototype/academic project, but a new production design should consider a newer Jetson platform.


16. Jetson software installation

After setting up Jetson Nano:

sudo apt update
sudo apt upgrade

Install basic packages:

sudo apt install -y \
python3-pip \
python3-opencv \
git \
curl \
wget \
ffmpeg \
libopenblas-dev

Install Python packages:

pip3 install numpy
pip3 install flask
pip3 install requests
pip3 install paho-mqtt

Check Jetson:

sudo jetson_clocks

Check CUDA:

nvcc --version

Check GPU:

tegrastats

17. Project directory

Create:

accident-ai/
├── jetson/
│ ├── camera.py
│ ├── detector.py
│ ├── risk_engine.py
│ ├── sensor_client.py
│ ├── server.py
│ ├── config.py
│ └── main.py
├── esp32/
│ └── accident_sensor.ino
├── dashboard/
│ ├── index.html
│ ├── style.css
│ └── app.js
├── n8n/
│ ├── workflow-description.md
│ └── sample-payload.json
├── models/
│ └── model.onnx
└── README.md

18. ESP32 software

Below is a complete prototype ESP32 program.

It:

  • connects to Wi-Fi
  • reads MPU6050
  • reads ultrasonic distance
  • calculates acceleration magnitude
  • activates local warning
  • sends JSON to the n8n webhook
#include <WiFi.h>
#include <HTTPClient.h>
#include <Wire.h>
#include <MPU6050.h>
#include <ArduinoJson.h>
const char* WIFI_SSID = "YOUR_WIFI";
const char* WIFI_PASSWORD = "YOUR_PASSWORD";
const char* N8N_URL =
"https://YOUR-N8N-DOMAIN/webhook/accident-sensor";
#define TRIG_PIN 5
#define ECHO_PIN 18
#define BUZZER_PIN 25
#define GREEN_LED 26
#define RED_LED 27
MPU6050 mpu;
unsigned long lastSend = 0;
const unsigned long SEND_INTERVAL = 5000;
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);
if (duration == 0)
return 999.0;
return duration * 0.0343 / 2.0;
}
void connectWiFi()
{
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("WiFi connected");
Serial.println(WiFi.localIP());
}
void localWarning(float acceleration, float distance)
{
bool dangerous = false;
if (acceleration > 2.5)
dangerous = true;
if (distance < 100)
dangerous = true;
if (dangerous)
{
digitalWrite(RED_LED, HIGH);
digitalWrite(GREEN_LED, LOW);
digitalWrite(BUZZER_PIN, HIGH);
}
else
{
digitalWrite(RED_LED, LOW);
digitalWrite(GREEN_LED, HIGH);
digitalWrite(BUZZER_PIN, LOW);
}
}

Install these Arduino libraries:

MPU6050
ArduinoJson
WiFi
HTTPClient
Wire

19. Example ESP32 JSON

The ESP32 sends:

{
"device_id": "ESP32-ACCIDENT-01",
"timestamp": 123456,
"imu": {
"ax": 0.12,
"ay": -0.08,
"az": 1.02,
"gx": 2.1,
"gy": 1.2,
"gz": 0.8
},
"distance_cm": 75.2,
"acceleration_g": 1.03
}

20. Jetson accident detection

The Jetson receives:

Camera data
+
ESP32 sensor data

Then performs:

AI Detection
Object tracking
Obstacle analysis
Sensor fusion
Risk score

21. Risk-engine Python code

Create:

jetson/risk_engine.py
import math
def clamp(value, minimum=0, maximum=100):
return max(minimum, min(maximum, value))
def acceleration_risk(acceleration_g):
"""
Approximate risk based on acceleration magnitude.
This is a prototype threshold model, not a certified
automotive safety algorithm.
"""
if acceleration_g < 1.5:
return 0
if acceleration_g < 2.0:
return 25
if acceleration_g < 2.5:
return 50
if acceleration_g < 3.0:
return 75
return 100
def distance_risk(distance_cm):
if distance_cm > 300:
return 0
if distance_cm > 200:
return 20
if distance_cm > 120:
return 40
if distance_cm > 70:
return 70
return 100
def vision_risk(
object_detected,
estimated_distance,
closing_speed
):
if not object_detected:
return 0
risk = 20
if estimated_distance < 200:
risk += 20
if estimated_distance < 100:
risk += 30
if estimated_distance < 50:
risk += 30
if closing_speed > 10:
risk += 20
return clamp(risk)
def calculate_risk(
acceleration,

22. Jetson camera program

For the first prototype, structure your camera application like this:

import cv2
camera = cv2.VideoCapture(0)
if not camera.isOpened():
raise RuntimeError("Camera could not be opened")
while True:
ret, frame = camera.read()
if not ret:
break
# AI inference goes here
# detections = detector(frame)
cv2.imshow(
"Accident Prevention AI",
frame
)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
camera.release()
cv2.destroyAllWindows()

For the final implementation, replace the comment with your selected YOLO/TensorRT detector.


23. YOLO detection concept

The output can look like:

detections = [
{
"class": "car",
"confidence": 0.91,
"x1": 200,
"y1": 150,
"x2": 500,
"y2": 400
},
{
"class": "person",
"confidence": 0.87,
"x1": 600,
"y1": 200,
"x2": 680,
"y2": 410
}
]

Then:

Bounding box
Object size
Approximate distance
Object movement
Collision probability

24. Time-to-collision concept

If:

D = current distance
V = closing velocity

then:

TTC = D / V

For example:

Distance = 20 m
Closing speed = 10 m/s
TTC = 20 / 10
= 2 seconds

A low TTC is dangerous.

A simple model:

def calculate_ttc(distance_m, closing_speed_mps):
if closing_speed_mps <= 0:
return float("inf")
return distance_m / closing_speed_mps

Then:

ttc = calculate_ttc(
distance_m,
closing_speed
)
if ttc < 1.0:
risk = 100
elif ttc < 2.0:
risk = 80
elif ttc < 3.0:
risk = 60
else:
risk = 20

This should be presented as a prototype estimation, not a certified automotive collision-warning algorithm.


25. Sensor fusion

The strongest feature of the project is sensor fusion.

Instead of:

Camera → Accident

use:

Camera
+
Accelerometer
+
Gyroscope
+
Distance
+
GPS
+
Vehicle speed
Sensor Fusion
Risk Engine

Example:

Camera:
Car approaching
Distance:
45 cm
Acceleration:
2.7 g
Gyroscope:
abnormal rotation
AI Risk Engine
Risk = 91%
CRITICAL

26. Accident confirmation logic

To prevent false alarms, don't trigger an emergency from one sensor alone.

Use multiple conditions.

For example:

def accident_confirmed(
acceleration_g,
distance_cm,
camera_collision,
sudden_rotation
):
impact = acceleration_g > 3.0
obstacle = distance_cm < 40
evidence = 0
if impact:
evidence += 1
if obstacle:
evidence += 1
if camera_collision:
evidence += 1
if sudden_rotation:
evidence += 1
return evidence >= 2

This gives a simple explainable multi-sensor confirmation mechanism.


27. n8n architecture

n8n is the central automation/orchestration layer.

The Webhook node receives external HTTP events and can start an n8n workflow. n8n provides separate test and production webhook URLs, which is useful when developing this project.

Create workflow:

┌───────────────┐
│ n8n Webhook │
└───────┬───────┘
┌───────────────┐
│ Validate JSON │
└───────┬───────┘
┌───────────────┐
│ Risk Analysis │
└───────┬───────┘
┌───────────────┐
│ AI Agent │
└───────┬───────┘
┌───────────────┐
│ IF CRITICAL? │
└───┬───────┬───┘
│ │
YES NO
│ │
▼ ▼
Emergency Logging
Workflow Workflow

28. n8n workflow

Recommended complete workflow:

Webhook
Set / Code
Validate Device
Calculate / Normalize Risk
AI Agent
Switch Risk Level
├── SAFE
│ ↓
│ Google Sheets
│ ↓
│ ThingSpeak
├── WARNING
│ ↓
│ Telegram Text
│ ↓
│ Google Sheets
│ ↓
│ ThingSpeak
├── HIGH
│ ↓
│ AI-generated message
│ ↓
│ Telegram
│ ↓
│ Google Sheets
│ ↓
│ ThingSpeak
└── CRITICAL
AI Agent
Generate alert
Text-to-Speech
Telegram Voice
Telegram Text
Google Sheets
ThingSpeak

29. n8n node list

Create these nodes:

Node 1

Webhook

Method:

POST

Path:

accident-event

Authentication:

Header Auth

or JWT/basic authentication.

n8n supports webhook authentication options such as Basic Auth, Header Auth and JWT.


Node 2

Code

Validate the incoming payload.

Example:

const data = $json;
if (!data.device_id) {
throw new Error("Missing device_id");
}
if (typeof data.risk_score !== "number") {
throw new Error("Missing risk_score");
}
return [
{
json: {
...data,
received_at: new Date().toISOString()
}
}
];

30. AI Agent

Configure an n8n AI Agent with instructions such as:

You are an accident-prevention IoT monitoring agent.
Analyze the incoming vehicle safety event.
Input contains:
- device ID
- risk score
- risk level
- acceleration
- distance
- camera detection
- GPS location
- timestamp
Your responsibilities:
1. Interpret the event.
2. Determine whether it is SAFE, WARNING, HIGH or CRITICAL.
3. Explain the reason briefly.
4. Recommend the appropriate action.
5. If CRITICAL, create a concise emergency alert.
6. Never invent sensor measurements.
7. Never claim that an accident is confirmed unless the
supplied evidence supports it.
Return JSON:
{
"severity": "...",
"summary": "...",
"recommended_action": "...",
"telegram_message": "...",
"voice_message": "..."
}

This makes the AI agent decision-support software, while the deterministic risk engine remains responsible for the primary thresholding.

That separation is important:

Safety logic
Deterministic rules
AI Agent
Interpretation + explanation + orchestration

rather than allowing an LLM to arbitrarily control safety-critical decisions.


31. Example AI Agent input

{
"device_id": "VEHICLE-001",
"risk_score": 89,
"risk_level": "CRITICAL",
"acceleration_g": 3.6,
"distance_cm": 35,
"camera_collision": true,
"latitude": 16.50,
"longitude": 80.64
}

32. Example AI Agent output

{
"severity": "CRITICAL",
"summary": "Possible collision detected from combined camera, acceleration and distance evidence.",
"recommended_action": "Stop the vehicle if safe and verify the occupants.",
"telegram_message": "🚨 CRITICAL: Possible collision detected. Risk 89%. Acceleration 3.6g and obstacle distance 35 cm.",
"voice_message": "Critical safety alert. A possible collision has been detected. Please check the vehicle and occupants immediately."
}

33. Telegram text alert

Telegram's Bot API provides sendVoice for sending playable voice messages; Telegram documents support for OGG/Opus, MP3 and M4A voice uploads, with the current documented size limit of 50 MB.

Example text:

🚨 ACCIDENT PREVENTION ALERT
Vehicle: VEHICLE-001
Risk: 89%
Status: CRITICAL
Acceleration: 3.6 g
Obstacle: 35 cm
Camera: Possible collision
Recommended action:
Stop safely and check the occupants.
Location:
16.5000, 80.6400

34. Telegram voice workflow

The voice pipeline is:

AI Agent
voice_message
Text-to-Speech API
MP3/M4A/OGG
n8n binary data
Telegram Bot API
User receives voice message

You can use an external TTS provider or your own local TTS service.


35. Telegram Bot setup

In Telegram:

BotFather
/newbot
Create bot
Copy Bot Token

Then send a message to your bot.

Obtain your chat ID using the Telegram Bot API.

Store the bot token in n8n credentials rather than putting it directly into source code. n8n's Telegram credential uses a bot API access token.


36. Google Sheets database

Create:

Accident_Log

Columns:

Timestamp
Device_ID
Risk_Score
Risk_Level
Acceleration
Distance
Camera_Status
Latitude
Longitude
AI_Summary
Recommended_Action
Telegram_Status
Voice_Status

Example:

Timestamp Device Risk Level Accel Distance AI Summary
16:05 VEH001 89 CRITICAL 3.6g 35cm Possible collision
16:06 VEH001 42 WARNING 1.8g 90cm Unsafe distance
16:07 VEH001 10 SAFE 1.1g 250cm Normal

n8n's Google Sheets node supports operations including appending and updating spreadsheet rows.


37. ThingSpeak configuration

Create a channel:

AI Accident Prevention System

Use fields:

Field 1 = Risk Score
Field 2 = Acceleration
Field 3 = Distance
Field 4 = Speed
Field 5 = Vision Risk
Field 6 = Accident Status
Field 7 = Latitude
Field 8 = Longitude

ThingSpeak channels can have up to eight fields.


38. ThingSpeak HTTP request

The documented ThingSpeak write endpoint is:

https://api.thingspeak.com/update.json

with a channel Write API Key and fields in the request.

n8n HTTP Request:

Method:
POST
URL:
https://api.thingspeak.com/update.json

Body:

{
"api_key": "YOUR_WRITE_API_KEY",
"field1": "89",
"field2": "3.6",
"field3": "35",
"field4": "42",
"field5": "90",
"field6": "CRITICAL",
"field7": "16.5000",
"field8": "80.6400"
}

The Write API Key should be kept secret; ThingSpeak documents separate read/write permissions and channel API keys.


39. Web dashboard

The dashboard can show:

┌──────────────────────────────────────────┐
│ AI ACCIDENT PREVENTION SYSTEM │
├──────────────────────────────────────────┤
│ │
│ STATUS CRITICAL │
│ │
│ RISK SCORE 89% │
│ │
│ ACCELERATION 3.6 g │
│ │
│ DISTANCE 35 cm │
│ │
│ CAMERA COLLISION SUSPECTED │
│ │
│ LOCATION 16.5000, 80.6400 │
│ │
├──────────────────────────────────────────┤
│ LIVE SENSOR GRAPH │
│ │
│ /\ │
│ / \ /\ │
│___/ \_____/ \________ │
│ │
└──────────────────────────────────────────┘

40. HTML dashboard

Create:

dashboard/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>
AI Accident Prevention Dashboard
</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
background: #101820;
color: white;
}
header {
padding: 20px;
background: #17232c;
text-align: center;
}
.container {
display: grid;
grid-template-columns:
repeat(auto-fit, minmax(220px, 1fr));
gap: 20px;
padding: 30px;
}
.card {
background: #1c2b36;
padding: 25px;
border-radius: 15px;
box-shadow:
0 5px 15px rgba(0,0,0,0.3);
}
.value {
font-size: 35px;
font-weight: bold;
}
.critical {
color: #ff3333;
}
.safe {
color: #00ff88;
}
.warning {
color: #ffc107;
}
</style>
</head>
<body>
<header>
<h1>
AI Accident Prevention Dashboard
</h1>
<p>
Jetson Nano + ESP32 + n8n
</p>
</header>
<div class="container">

41. Flask dashboard server

Create:

jetson/server.py
from flask import Flask, jsonify, send_from_directory
app = Flask(__name__)
latest_data = {
"risk_score": 0,
"risk_level": "SAFE",
"acceleration": 0,
"distance": 999
}
@app.route("/")
def index():
return send_from_directory(
"../dashboard",
"index.html"
)
@app.route("/api/status")
def status():
return jsonify(latest_data)
@app.route("/api/update", methods=["POST"])
def update():
from flask import request
data = request.get_json()
latest_data.update(data)
return jsonify({
"success": True
})
if __name__ == "__main__":
app.run(
host="0.0.0.0",
port=5000,
debug=False
)

Open:

http://JETSON-IP:5000

42. Complete end-to-end flow

This is the most important flow diagram for your project report.

START
Initialize System
┌───────────┴───────────┐
│ │
▼ ▼
ESP32 Jetson Nano
│ │
▼ ▼
Read Sensors Read Camera
│ │
▼ ▼
MPU6050/Distance YOLO AI
│ │
└──────────┬────────────┘
Data Fusion
Risk Engine
┌───────┴────────┐
│ │
▼ ▼
SAFE DANGER
│ │
│ ▼
│ Local Warning
│ │
│ ▼
│ n8n Webhook
│ │
│ ▼
│ AI Agent
│ │
│ ┌────────┼────────┐
│ │ │ │
│ ▼ ▼ ▼
│ Telegram Sheets ThingSpeak
│ │
│ ▼
│ Voice Alert
Dashboard

43. Critical-event flow

Collision suspected
Acceleration > threshold?
Distance dangerous?
Camera collision detected?
Evidence count ≥ 2?
YES
CRITICAL EVENT
Send JSON
n8n
AI Agent
Generate emergency message
Generate voice text
TTS
Telegram Voice
+
Telegram Text
+
Google Sheets
+
ThingSpeak
+
Web Dashboard

44. Example n8n data

{
"device_id": "VEHICLE-001",
"timestamp": "2026-08-16T16:10:00+05:30",
"risk_score": 91,
"risk_level": "CRITICAL",
"sensors": {
"acceleration_g": 3.7,
"distance_cm": 31,
"gyro_x": 48.2,
"gyro_y": 12.4,
"gyro_z": 35.1
},
"vision": {
"vehicle_detected": true,
"collision_probability": 0.91,
"estimated_distance_m": 0.31
},
"gps": {
"latitude": 16.5000,
"longitude": 80.6400
}
}

45. n8n decision tree

Risk Score
┌──────────┼──────────┐
│ │ │
<30 30-49 50-74 ≥75
│ │ │ │
SAFE WARNING HIGH CRITICAL
│ │ │ │
Log only Telegram Telegram Telegram
│ │ │
│ │ Voice Alert
│ │ │
└──────────┴───────────┤
Google Sheets
ThingSpeak

46. Agentic IoT concept

The phrase Agentic IoT in your project can be explained as:

An IoT system in which sensor events are not merely transmitted to a dashboard, but are interpreted by an AI agent that selects and coordinates subsequent digital actions.

Traditional IoT:

Sensor
Cloud
Dashboard

Your proposed Agentic IoT:

Sensor
Edge AI
Event
AI Agent
Reason
Choose action
├── Log
├── Notify
├── Voice alert
├── Update cloud
└── Escalate

47. Why n8n is important

Without n8n:

Jetson → Telegram
Jetson → Sheets
Jetson → ThingSpeak
Jetson → TTS

The Jetson would need to implement all integrations.

With n8n:

Jetson
ONE WEBHOOK
n8n
┌─┼───────────────┐
↓ ↓ ↓
AI Telegram Google
↓ Sheets
Voice
ThingSpeak

This makes the system modular.

n8n's Webhook node is specifically intended to receive events from external applications and start workflows.


48. Telegram alert levels

SAFE

No Telegram alert.

WARNING

⚠️ WARNING
Vehicle approaching an obstacle.
Risk: 38%
Distance: 95 cm
Please reduce speed.

HIGH

⚠️ HIGH RISK
Unsafe driving condition detected.
Risk: 67%
Distance: 54 cm
Acceleration: 2.4 g
Immediate attention recommended.

CRITICAL

🚨 CRITICAL ACCIDENT ALERT
Possible collision detected.
Risk: 91%
Acceleration: 3.7 g
Obstacle distance: 31 cm
Vision collision probability: 91%
Please check the vehicle and occupants immediately.

49. Voice alert

Example:

"Critical safety alert. A possible collision has been detected. Please stop safely and check the vehicle and occupants immediately."

This is preferable to sending a long paragraph as voice.


50. Google Sheets flow

Event
n8n
AI Agent
Prepare Row
Google Sheets
Append Row

Example row:

2026-08-16 16:10
VEHICLE-001
91
CRITICAL
3.7
31
0.91
16.5000
80.6400
Possible collision
Check occupants
SENT
SENT

51. ThingSpeak flow

ESP32/Jetson
n8n
HTTP Request
ThingSpeak REST API
Channel
Graph

ThingSpeak supports HTTP REST calls for updating channel data, as well as MQTT for IoT applications.


52. Dashboard architecture

ThingSpeak
Cloud Graphs
Web User
Jetson
Flask Server
HTML/CSS/JS
Live Dashboard

You can therefore have two dashboard levels:

Local dashboard

Hosted by Jetson.

Cloud dashboard

ThingSpeak.


53. Communication protocols

Connection Protocol
ESP32 → n8n HTTP POST
ESP32 → Jetson HTTP/MQTT optional
Camera → Jetson USB/CSI
Jetson → n8n HTTP POST
n8n → Telegram Bot API
n8n → Sheets Google API
n8n → ThingSpeak REST API
Dashboard → Jetson HTTP
ESP32 → Wi-Fi TCP/IP

54. Recommended security

Do not expose an unauthenticated webhook to the public Internet.

Use:

HTTPS
+
Header authentication
+
Random webhook path
+
Secret API key

For example:

X-DEVICE-TOKEN: YOUR_SECRET_TOKEN

n8n supports authentication mechanisms on Webhooks, including header authentication.


55. Do not put secrets in source code

Bad:

const char* TELEGRAM_TOKEN =
"123456:ABCDEF...";

Better:

ESP32
n8n authenticated webhook
n8n credentials
├── Telegram token
├── Google credentials
├── AI credentials
├── TTS credentials
└── ThingSpeak key

This architecture keeps most cloud secrets out of the ESP32.


56. Error-handling architecture

Your system should continue working if one cloud service fails.

Critical Event
n8n
┌───────────┼───────────┐
│ │ │
Telegram Sheets ThingSpeak
│ │ │
FAIL OK OK
Retry / fallback
Local Jetson log

Always retain a local emergency event record.


57. Offline operation

This is a major feature you can mention in the project report.

If Internet fails:

Camera
Jetson AI
Risk Engine
LOCAL BUZZER
LOCAL LOG

When Internet returns:

Local events
Upload queue
n8n
Cloud services

Therefore accident prevention doesn't completely depend on cloud connectivity.


58. Local fail-safe

For a critical system:

Cloud AI unavailable
Use deterministic local rules
Continue warning

Do not design the vehicle safety function so that:

Internet failure = no safety

59. State machine

The entire system can be represented as:

┌──────────┐
│ SAFE │
└────┬─────┘
risk > 30
┌──────────┐
│ WARNING │
└────┬─────┘
risk > 50
┌──────────┐
│ HIGH │
└────┬─────┘
risk > 75
┌──────────┐
│ CRITICAL │
└────┬─────┘
event resolved
SAFE

60. Project sequence

Build it in stages.

Stage 1 — ESP32

First make:

ESP32
MPU6050
Serial Monitor

Verify acceleration.

Then:

ESP32
Ultrasonic

Then:

ESP32
Wi-Fi
HTTP

Stage 2 — n8n

Create:

Webhook
Respond

Send test request:

curl -X POST \
https://YOUR-N8N/webhook/accident-sensor \
-H "Content-Type: application/json" \
-d '{
"device_id":"TEST",
"risk_score":80,
"risk_level":"CRITICAL"
}'

n8n documents using HTTP requests/curl to trigger Webhooks during testing.


61. Stage 3 — Telegram

Test:

Webhook
Telegram

Expected:

🚨 Test accident alert

Only after this works should you add AI.


62. Stage 4 — Google Sheets

Build:

Webhook
Google Sheets

Check that every event creates a row.


63. Stage 5 — ThingSpeak

Build:

Webhook
HTTP Request
ThingSpeak

Check the channel graph.


64. Stage 6 — AI Agent

Then:

Webhook
AI Agent
Telegram

Test several cases:

Risk = 10
Risk = 40
Risk = 60
Risk = 90

65. Stage 7 — Jetson

Connect camera.

Run:

Camera
Object detector
Display bounding boxes

Do not immediately connect emergency alerts.

First verify detection.


66. Stage 8 — Sensor fusion

Finally:

Jetson camera
+
ESP32
Risk engine
n8n

67. Testing cases

Your project report should include a test table.

Test Camera Accel Distance Expected
Normal Clear 1.0g 300cm SAFE
Obstacle Vehicle 1.2g 100cm WARNING
Rapid approach Vehicle 1.8g 70cm HIGH
Hard impact Collision 3.5g 30cm CRITICAL
Camera false positive Object 1.0g 300cm SAFE
Sensor false positive Clear 3.5g 300cm Verify
Network failure Critical 3.5g 30cm Local alert

68. Performance metrics

Measure:

Detection accuracy

Accuracy =
Correct detections /
Total detections

Precision

Precision =
TP / (TP + FP)

Recall

Recall =
TP / (TP + FN)

F1 score

F1 =
2 × Precision × Recall /
(Precision + Recall)

Alert latency

Measure:

Sensor event
Detection timestamp
n8n received
Telegram sent

Then:

Latency =
Telegram timestamp -
Sensor event timestamp

69. Suggested performance table

Fill this using your actual experimental results:

Parameter Target
Camera FPS 10–20 FPS
Sensor interval 100–500 ms
Cloud telemetry 5–15 sec
Critical alert <5 sec target
False alarm rate Minimize
Object detection >80% test accuracy
Dashboard update <5–10 sec

Do not claim these numbers as achieved until you measure them.


70. Advantages

1. Edge AI

Computer vision runs locally.

2. Sensor fusion

Combines camera and physical sensors.

3. Early warning

Attempts to detect risk before an accident.

4. Cloud logging

Events are permanently recorded.

5. AI explanation

The AI agent converts raw sensor data into human-readable reasoning.

6. Telegram voice

Users can receive an audible emergency notification.

7. Automation

n8n connects all services.

8. Modular architecture

Individual components can be replaced.


71. Limitations

This is extremely important in your documentation.

The system is a prototype/research/educational safety system, not a certified automotive safety product.

Limitations include:

  • Camera lighting affects detection.
  • Rain/fog can reduce vision accuracy.
  • Object detection can generate false positives.
  • Ultrasonic sensors have limited range.
  • GPS may be unavailable indoors.
  • ESP32 Wi-Fi depends on network availability.
  • AI-agent output should not directly control safety-critical systems.
  • Risk thresholds require calibration.
  • A single camera cannot reliably determine real-world distance in all conditions.
  • Jetson Nano has limited computational resources.
  • JetPack 4 is end-of-life for the Nano.

72. Important safety architecture

For your final project, I strongly recommend this separation:

AI Agent
Explanation only
Notification

while:

Camera
+
Sensors
Deterministic Risk Engine
Local Safety Warning

In other words:

Never let an LLM be the sole authority for emergency braking or another safety-critical physical action.

The AI Agent should interpret, summarize, log and notify.


73. Complete project workflow

START
Power ON
├─────────────┐
│ │
▼ ▼
ESP32 Jetson
│ │
▼ ▼
Sensors Camera
│ │
▼ ▼
Sensor JSON YOLO
│ │
└──────┬──────┘
Sensor Fusion
Risk Calculation
┌───────┼─────────┐
│ │ │
▼ ▼ ▼
SAFE WARNING CRITICAL
│ │ │
│ ▼ ▼
│ Local Local
│ warning warning
│ │ │
└───────┴────┬────┘
n8n Webhook
AI Agent
┌──────┼────────┐
▼ ▼ ▼
Telegram Sheets ThingSpeak
Voice Alert
User

74. Recommended final hardware architecture

For the demonstration model:

CAMERA
┌─────────────────┐
│ NVIDIA JETSON │
│ NANO │
│ │
│ YOLO + OpenCV │
│ Risk Engine │
│ Flask Dashboard │
└────────┬────────┘
Wi-Fi
┌─────────────────┐
│ n8n │
│ │
│ Webhook │
│ AI Agent │
│ Automation │
└───┬────┬────┬───┘
│ │ │
▼ ▼ ▼
Telegram Sheets ThingSpeak
Voice Alert
ESP32 SENSOR UNIT
┌─────────────────┐
│ ESP32 │
├─────────────────┤
│ MPU6050 │
│ Ultrasonic │
│ GPS │
│ Buzzer │
│ LEDs │
└─────────────────┘

75. Suggested project presentation

For your viva/demo, demonstrate in this order:

Demo 1

Normal condition:

Risk = 10%
Status = SAFE

Demo 2

Place obstacle close to ultrasonic sensor:

Distance = 50 cm
Risk = WARNING
Buzzer = ON

Demo 3

Simulate sudden movement using MPU6050:

Acceleration = 3g+
Risk = HIGH/CRITICAL

Demo 4

Camera sees obstacle/vehicle:

YOLO → Object detected

Demo 5

Combine the conditions:

Object detected
+
Low distance
+
High acceleration

Then:

CRITICAL
n8n
AI Agent
Telegram
Voice alert
Google Sheets
ThingSpeak

This makes the complete system visually impressive.


76. What to show in the final demonstration

Have these five screens open simultaneously:

Screen 1

Jetson camera:

[Camera]
Car 91%
Person 87%
Distance warning

Screen 2

Terminal:

Risk Score: 89
Risk Level: CRITICAL

Screen 3

n8n:

Webhook
→ AI Agent
→ Telegram
→ Google Sheets
→ ThingSpeak

Screen 4

Google Sheets:

Timestamp | Risk | Acceleration | Distance

Screen 5

Telegram:

🚨 CRITICAL ALERT
Possible collision detected...

and:

🔊 Voice message

77. Project modules for your report

You can divide the project into these modules:

Module 1 — ESP32 IoT Sensor Module

Collects:

Acceleration
Gyroscope
Distance
GPS

Module 2 — Edge AI Module

Runs:

Camera
YOLO
Object detection
Tracking

Module 3 — Risk Analysis Module

Performs:

Sensor fusion
Risk scoring
Accident confirmation

Module 4 — IoT Communication Module

Uses:

HTTP
Wi-Fi
JSON
REST

Module 5 — Agentic AI Module

Uses:

n8n
AI Agent
Reasoning
Action selection

Module 6 — Notification Module

Uses:

Telegram
Text
Voice

Module 7 — Cloud Logging

Uses:

Google Sheets
ThingSpeak

Module 8 — Web Dashboard

Uses:

HTML
CSS
JavaScript
Flask

78. Expected output

The final system should produce:

LIVE CAMERA
+
LIVE SENSOR DATA
+
AI DETECTION
+
RISK SCORE
ACCIDENT PREVENTION
AUTOMATED RESPONSE

Example final output:

=========================================
AI ACCIDENT PREVENTION SYSTEM
=========================================
Device : VEHICLE-001
Status : CRITICAL
Risk Score : 91%
Acceleration : 3.7 g
Distance : 31 cm
Camera : Collision suspected
GPS : 16.5000, 80.6400
AI Analysis:
Possible collision detected from
combined sensor and vision evidence.
Action:
Check vehicle and occupants.
Telegram : SENT
Voice Alert : SENT
Google Sheet : LOGGED
ThingSpeak : UPDATED
=========================================

79. Future enhancements

For a stronger version 2:

Computer vision

  • YOLOv8/YOLO11 or a Nano-compatible optimized detector
  • DeepSORT/ByteTrack
  • Monocular depth estimation
  • Lane detection
  • Driver drowsiness detection
  • Traffic-sign detection

Sensors

  • mmWave radar
  • LiDAR
  • wheel-speed sensor
  • steering angle
  • CAN bus

AI

  • Temporal accident classifier
  • LSTM
  • Transformer-based video model
  • Predictive risk model
  • RAG-based incident assistant

IoT

  • MQTT
  • AWS/Azure
  • Firebase
  • InfluxDB
  • Grafana

Communication

  • GSM
  • LTE
  • NB-IoT
  • LoRaWAN

Emergency system

Accident
GPS
Telegram
Emergency contact
Hospital/police integration

80. Recommended project name for your certificate/report

“Design and Implementation of an AI-Based Accident Prevention and Agentic IoT Alert System Using NVIDIA Jetson Nano and ESP32”

Alternative:

“AI-Powered Accident Detection and Prevention Using Edge Computer Vision, ESP32 IoT and n8n Agentic Automation”

Or a shorter title:

“Agentic AI-Based Accident Prevention and IoT Alert System”


81. Official documentation/resources

For the Jetson setup, use NVIDIA's official Jetson Nano documentation and JetPack archive. NVIDIA's current documentation identifies JetPack 4.6.6 as the final JetPack 4 release supporting Nano.

NVIDIA Jetson Nano Developer Documentation

NVIDIA JetPack Archive

For n8n:

n8n Webhook documentation

n8n Google Sheets documentation

n8n Telegram documentation

For ThingSpeak:

ThingSpeak REST API documentation

ThingSpeak Write Data documentation

For Telegram voice:

Telegram Bot API


Final architecture in one line

ESP32 Sensors + Camera
NVIDIA Jetson Nano Edge AI
Sensor Fusion + Accident Risk Engine
Secure n8n Webhook
AI Agent
Telegram Text + TTS Voice Alert
+
Google Sheets Logging
+
ThingSpeak Cloud Dashboard
+
Jetson Web Dashboard

This gives you a complete, defensible final-year project architecture: the Jetson performs edge AI, ESP32 provides physical IoT sensing, deterministic logic performs safety/risk decisions, and the n8n AI Agent handles interpretation and multi-service automation. It also avoids making an LLM the sole controller of a safety-critical function.

No comments:

Post a Comment