AI-Based Railway Track Fault Prediction and Autonomous Alert System Using Raspberry Pi Pico, GPS and Computer Vision
AI-Based Railway Track Fault Prediction and Autonomous Alert System
Using Raspberry Pi Pico, ESP32, GPS, Computer Vision, AI Agent, n8n, Telegram Voice Alerts, Google Sheets & ThingSpeak
1. Project Overview
This project provides an intelligent railway monitoring system capable of detecting track cracks, obstacles, abnormal vibrations, and rail misalignment using sensors, computer vision, GPS tracking, cloud computing, and artificial intelligence.
The collected data is transmitted through ESP32 to cloud platforms where AI models predict risk levels and automatically generate alerts through Telegram voice notifications.
2. Objectives
- Detect railway track cracks automatically.
- Monitor vibration and temperature continuously.
- Track exact GPS location of faults.
- Predict maintenance requirements using AI.
- Send automatic Telegram alerts.
- Store data in Google Sheets and ThingSpeak.
- Provide real-time cloud dashboard monitoring.
3. Components Required
| Component | Quantity | Purpose |
|---|---|---|
| Raspberry Pi Pico W | 1 | Data Processing |
| ESP32 | 1 | WiFi Communication |
| NEO-6M GPS | 1 | Location Tracking |
| MPU6050 | 1 | Vibration Detection |
| DHT22 | 1 | Temperature Monitoring |
| HC-SR04 | 1 | Obstacle Detection |
| ESP32-CAM | 1 | Computer Vision |
| 18650 Battery | 1 | Power Supply |
4. System Architecture
Railway Track
|
V
Sensors + Camera
|
V
Raspberry Pi Pico
|
V
ESP32 Gateway
|
V
ThingSpeak Cloud
Google Sheets
|
V
n8n Automation
|
V
AI Agent
|
V
Telegram Voice Alert
|
V
Control Room
5. Working Principle
- Initialize all sensors and modules.
- Collect vibration data from MPU6050.
- Read temperature using DHT22.
- Detect obstacles using ultrasonic sensor.
- Capture railway track images.
- Perform AI image analysis.
- Detect cracks and faults.
- Read GPS coordinates.
- Calculate risk score.
- Upload information to cloud.
- Store records in Google Sheets.
- Generate Telegram notifications.
- Send voice alerts to railway officials.
6. Circuit Connections
MPU6050 VCC -> 3.3V GND -> GND SDA -> GPIO21 SCL -> GPIO22 GPS NEO-6M VCC -> 3.3V GND -> GND TX -> GPIO16 RX -> GPIO17 DHT22 DATA -> GPIO4 VCC -> 3.3V GND -> GND HC-SR04 TRIG -> GPIO5 ECHO -> GPIO18 IR Sensor OUT -> GPIO15 VCC -> 3.3V GND -> GND
7. Flowchart
START ↓ Initialize System ↓ Collect Sensor Data ↓ Capture Image ↓ AI Detection ↓ Fault Found? YES ------------------- NO | | V | Get GPS | | | V | Upload Cloud | | | V | AI Risk Prediction | | | V | Telegram Alert | | | V | Voice Notification | | | V | END <--------------------
8. Computer Vision Module
YOLOv8 Nano model is used for crack detection and obstacle identification.
pip install ultralytics yolo detect train \ data=rail.yaml \ model=yolov8n.pt \ epochs=100
Output Model: best.pt
9. ESP32 Source Code
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid="WiFi_Name";
const char* password="WiFi_Password";
void setup()
{
Serial.begin(115200);
WiFi.begin(ssid,password);
while(WiFi.status()!=WL_CONNECTED)
{
delay(1000);
}
}
void loop()
{
HTTPClient http;
http.begin("https://api.thingspeak.com/update");
http.GET();
http.end();
delay(15000);
}
10. ThingSpeak Setup
- Create ThingSpeak account.
- Create channel.
- Add fields:
- Temperature
- Vibration
- Crack Status
- GPS Latitude
- GPS Longitude
- Risk Score
- Copy API Key.
- Use API key in ESP32 code.
11. Google Sheets Integration
| Timestamp | Temperature | Vibration | Risk Score |
|---|---|---|---|
| 10:00 | 40°C | 8.2 | 92% |
12. Telegram Bot Setup
- Open Telegram.
- Search BotFather.
- Create new bot.
- Get Bot Token.
- Configure Telegram API.
- Connect n8n workflow.
13. n8n Workflow
Webhook ↓ ThingSpeak Data ↓ AI Agent ↓ Risk > 70 ? ↓ Telegram Alert ↓ Voice Generator ↓ Google Sheets Update ↓ Dashboard Update
14. AI Risk Prediction Logic
Risk Score = 0.4 × Crack + 0.3 × Vibration + 0.2 × Temperature + 0.1 × Alignment
| Risk Score | Status |
|---|---|
| 0 - 30 | Safe |
| 31 - 60 | Warning |
| 61 - 80 | High Risk |
| 81 - 100 | Critical |
15. Telegram Voice Alert
WARNING! Railway Track Crack Detected Latitude : 17.3850 Longitude: 78.4867 Risk Score: 92% Immediate Inspection Required
16. Future Enhancements
- Edge AI Deployment
- LoRa Communication
- 4G/5G Backup Network
- Digital Twin Dashboard
- Automatic Signal Control
- Predictive Maintenance Analytics
- Railway Control Center Integration
17. Deployment Guide
Prototype Stage
- Single Track Section
- One ESP32 Node
- One Camera Module
Pilot Deployment
- 1-5 km Railway Section
- Solar Powered Sensor Nodes
- Cloud Monitoring
Production Deployment
- Sensor Nodes Every 500 m
- Central AI Server
- 24/7 Monitoring Dashboard
18. Conclusion
The AI-Based Railway Track Fault Prediction and Autonomous Alert System provides intelligent monitoring, real-time fault detection, predictive maintenance, cloud analytics, GPS tracking, and automated Telegram voice alerts. The solution enhances railway safety and minimizes accident risks through continuous monitoring and AI-driven decision-making.

Comments
Post a Comment