Friday, 29 May 2026

AI Smart Anti-Sleep Alarm System for Drivers Using CNN

AI Smart Anti-Sleep Alarm System for Drivers Using CNN + ESP32 + Agentic IoT + n8n + Telegram Voice Alerts + Google Sheets + ThingSpeak
<?php echo $title; ?>

AI Smart Anti-Sleep Alarm System for Drivers

CNN + ESP32 + n8n + Telegram + Google Sheets + ThingSpeak

1. Project Description

This project detects driver drowsiness using a CNN-based AI model. When drowsiness is detected, ESP32 activates a buzzer and sends data to an n8n workflow. n8n automatically triggers Telegram alerts, voice notifications, Google Sheets logging, and ThingSpeak dashboard updates.

2. Components List

Component Quantity
ESP32 Dev Board1
ESP32-CAM1
OV2640 Camera1
OLED SSD13061
Active Buzzer1
LED2
Push Button1
Battery Pack1
Jumper WiresAs Required

3. System Architecture

Camera
   |
CNN Drowsiness Detection
   |
ESP32 Controller
   |
   +--> Buzzer
   +--> OLED Display
   +--> n8n Webhook
   +--> Telegram
   +--> Google Sheets
   +--> ThingSpeak

4. Circuit Connections

OLED SSD1306

VCC -> 3.3V
GND -> GND
SCL -> GPIO22
SDA -> GPIO21

Buzzer

+ -> GPIO15
- -> GND

LED

+ -> GPIO2
- -> 220 Ohm -> GND

Button

GPIO4

5. Flowchart

START
 |
Initialize ESP32
 |
Connect WiFi
 |
Capture Face
 |
CNN Detection
 |
Drowsy?
 |
 +----NO----> Continue Monitoring
 |
 YES
 |
Activate Alarm
 |
Send Data to n8n
 |
Telegram Alert
 |
Google Sheets
 |
ThingSpeak
 |
END

6. ESP32 Source Code

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

const char* ssid="YOUR_WIFI";
const char* password="PASSWORD";

String webhookURL =
"https://your-n8n-server/webhook/drowsy";

int buzzer = 15;
int led = 2;

void setup()
{
 pinMode(buzzer,OUTPUT);
 pinMode(led,OUTPUT);

 WiFi.begin(ssid,password);

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

void loop()
{
 int drowsyFlag = 1;

 if(drowsyFlag)
 {
   digitalWrite(buzzer,HIGH);
   digitalWrite(led,HIGH);

   sendToN8N();
 }

 delay(5000);
}

7. CNN Training Code (Python)

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import Flatten

model = Sequential()

model.add(Conv2D(32,(3,3),
activation='relu',
input_shape=(64,64,3)))

model.add(Flatten())

model.add(Dense(128,
activation='relu'))

model.add(Dense(1,
activation='sigmoid'))

model.compile(
optimizer='adam',
loss='binary_crossentropy',
metrics=['accuracy'])

model.save("drowsiness_model.h5")

8. n8n Workflow

Webhook
   |
AI Agent
   |
   +--> Telegram Alert
   +--> Voice Notification
   +--> Google Sheets
   +--> ThingSpeak

9. Telegram Bot Setup

  1. Open Telegram
  2. Search @BotFather
  3. Create new bot using /newbot
  4. Copy API Token
  5. Add token in n8n Telegram node

10. Google Sheets Integration

Date Time Driver Status Battery
12-06-2026 10:30 AM John Drowsy 78%

11. ThingSpeak Dashboard

Field1 = Drowsiness
Field2 = Battery
Field3 = Eye Score
Field4 = Alert Count

12. AI Power Consumption Prediction

Inputs

Battery Voltage
WiFi Usage
Camera Runtime
Alert Frequency

Output

Remaining Battery Life
Power Consumption Forecast

13. Voice Notification Automation

Webhook
   |
Text To Speech
   |
Generate MP3
   |
Telegram Send Audio

Voice Message:

Warning!
Driver drowsiness detected.
Please stop and rest.

14. Future Enhancements

  • YOLOv8 Face Detection
  • TinyML on ESP32
  • GPS Tracking
  • Emergency SMS
  • Accident Detection
  • Fleet Monitoring Dashboard
  • Predictive Fatigue Analytics

15. Deployment Steps

  1. Train CNN model
  2. Deploy model on PC/Raspberry Pi
  3. Connect ESP32
  4. Configure WiFi
  5. Setup n8n workflow
  6. Create Telegram Bot
  7. Connect Google Sheets
  8. Create ThingSpeak Dashboard
  9. Perform testing
  10. Deploy in vehicle
Project Folder Structure AI_Driver_Drowsiness_System/ │ ├── index.php ├── assets/ │ ├── css/ │ ├── images/ │ └── js/ │ ├── esp32/ │ └── esp32_code.ino │ ├── ai_model/ │ ├── train.py │ └── drowsiness_model.h5 │ ├── n8n/ │ └── workflow.json │ └── docs/ └── project_report.pdf This gives you a complete PHP-based project documentation webpage. For a final-year project, I would recommend expanding it into a multi-page professional PHP website with: Home About Project Architecture Diagram Components Circuit Diagram ESP32 Code CNN Model n8n Workflow Telegram Integration Google Sheets Dashboard ThingSpeak Analytics AI Agent Module Power Prediction Module Future Enhancements Download Report (PDF) which looks suitable for project submission and viva presentation. This architecture is suitable for a final-year B.Tech/M.Tech engineering project, research prototype, startup MVP, or commercial fleet-monitoring system, and can be extended with GPS, GSM, TinyML, and advanced Agentic AI workflows.

No comments:

Post a Comment