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 Board | 1 |
| ESP32-CAM | 1 |
| OV2640 Camera | 1 |
| OLED SSD1306 | 1 |
| Active Buzzer | 1 |
| LED | 2 |
| Push Button | 1 |
| Battery Pack | 1 |
| Jumper Wires | As 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
- Open Telegram
- Search @BotFather
- Create new bot using /newbot
- Copy API Token
- 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
- Train CNN model
- Deploy model on PC/Raspberry Pi
- Connect ESP32
- Configure WiFi
- Setup n8n workflow
- Create Telegram Bot
- Connect Google Sheets
- Create ThingSpeak Dashboard
- Perform testing
- Deploy in vehicle


No comments:
Post a Comment