AI Powered IoT Health Monitoring System Using ESP32
This project continuously monitors patient health parameters and sends data to cloud platforms. Artificial Intelligence analyzes health trends and predicts potential health risks. The system automatically generates Telegram alerts, voice notifications, Google Sheets records, and ThingSpeak cloud visualizations.
1. Project Objectives
- Monitor patient body temperature.
- Measure heart rate.
- Measure blood oxygen level (SpO2).
- Upload data to cloud in real-time.
- Store historical records.
- Generate AI-based predictions.
- Send emergency Telegram alerts.
- Generate voice notifications.
- Create dashboard visualization.
2. System Architecture
Patient | Sensors (MAX30102, DHT11/LM35) | ESP32 Controller | WiFi Internet | ThingSpeak Cloud | n8n Automation | AI Agent Analysis | ------------------------- | Telegram Bot Alerts | | Voice Notifications | | Google Sheets Logs | -------------------------
3. Components Required
| Component | Quantity |
|---|---|
| ESP32 Development Board | 1 |
| MAX30102 Pulse Oximeter Sensor | 1 |
| DHT11 Temperature Sensor | 1 |
| Buzzer | 1 |
| LED Indicators | 2 |
| Breadboard | 1 |
| Jumper Wires | Several |
| USB Cable | 1 |
| WiFi Network | 1 |
4. Sensor Functions
MAX30102
- Measures Heart Rate
- Measures Blood Oxygen (SpO2)
DHT11
- Measures Body Temperature
5. Circuit Connections
MAX30102 → ESP32
| MAX30102 | ESP32 |
|---|---|
| VIN | 3.3V |
| GND | GND |
| SCL | GPIO22 |
| SDA | GPIO21 |
DHT11 → ESP32
| DHT11 | ESP32 |
|---|---|
| VCC | 3.3V |
| GND | GND |
| DATA | GPIO4 |
Buzzer
| Buzzer | ESP32 |
|---|---|
| Positive | GPIO15 |
| Negative | GND |
6. Flowchart
START | Initialize ESP32 | Connect WiFi | Read Sensors | Upload Data | ThingSpeak Cloud | n8n Workflow | AI Analysis | Abnormal? | Yes -------> Telegram Alert | | | | | Voice Message | No | Store Data | Repeat
7. ESP32 Source Code
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "YOUR_WIFI";
const char* password = "YOUR_PASSWORD";
String apiKey = "THINGSPEAK_API_KEY";
void setup()
{
Serial.begin(115200);
WiFi.begin(ssid,password);
while(WiFi.status()!=WL_CONNECTED)
{
delay(1000);
}
}
void loop()
{
float temp = 36.5;
int heartRate = 78;
int spo2 = 98;
if(WiFi.status()==WL_CONNECTED)
{
HTTPClient http;
String url =
"https://api.thingspeak.com/update?api_key="
+ apiKey +
"&field1="+String(temp)+
"&field2="+String(heartRate)+
"&field3="+String(spo2);
http.begin(url);
http.GET();
http.end();
}
delay(15000);
}
8. ThingSpeak Setup
- Create ThingSpeak account.
- Create new channel.
- Add fields:
- Temperature
- Heart Rate
- SpO2
- Save Channel.
- Copy Write API Key.
- Paste into ESP32 code.
9. Telegram Bot Setup
Step 1
Open Telegram and search BotFather.
Step 2
Create new bot using /newbot command.
Step 3
Copy generated Bot Token.
Step 4
Get Chat ID.
Step 5
Use token in n8n Telegram node.
10. Google Sheets Integration
Create Sheet
| Date | Temperature | Heart Rate | SpO2 | Status |
|---|
n8n Workflow
- Receive ThingSpeak Data
- Analyze Data
- Append Row to Google Sheet
11. n8n Workflow Design
ThingSpeak Trigger
|
v
Data Processing
|
v
AI Agent
|
+-------------------+
| |
v v
Google Sheets Telegram Alert
|
v
Voice Message
12. Sample n8n Workflow JSON
{
"nodes":[
{
"name":"Webhook",
"type":"n8n-nodes-base.webhook"
},
{
"name":"AI Agent",
"type":"n8n-nodes-base.openai"
},
{
"name":"Google Sheets",
"type":"n8n-nodes-base.googleSheets"
},
{
"name":"Telegram",
"type":"n8n-nodes-base.telegram"
}
]
}
13. AI Prediction Logic
Input Parameters
- Temperature
- Heart Rate
- SpO2
- Historical Trends
Prediction Rules
IF Temperature > 38°C AND Heart Rate > 110 Risk = HIGH IF SpO2 < 92% Risk = CRITICAL ELSE Risk = NORMAL
14. Power Consumption Prediction
AI calculates average sensor power usage and predicts battery life.
Battery Capacity = 2000mAh Average Current = 120mA Battery Life = 2000 / 120 = 16.6 Hours
15. Voice Notification Automation
n8n converts alert text into speech.
Example Message
Warning! Patient Heart Rate High. Current Heart Rate: 125 BPM Please Check Immediately.
Automation Flow
AI Alert | Text To Speech | Telegram Voice Message | Doctor / Caretaker
16. Alert Conditions
| Parameter | Condition | Alert |
|---|---|---|
| Temperature | > 38°C | High Fever |
| Heart Rate | > 110 BPM | Tachycardia |
| SpO2 | < 92% | Emergency |
17. Advantages
- Low Cost
- Portable
- Real-Time Monitoring
- Cloud Storage
- Remote Healthcare
- AI Assisted Analysis
- Automatic Alerts
18. Applications
- Hospitals
- Home Care
- Elderly Monitoring
- Remote Patient Monitoring
- Smart Healthcare
19. Future Enhancements
- ECG Integration
- Blood Pressure Monitoring
- Machine Learning Disease Prediction
- Mobile App Development
- GPS Emergency Tracking
- Doctor Dashboard
- Multi Patient Monitoring
20. Deployment Guide
- Assemble hardware.
- Upload ESP32 code.
- Connect sensors.
- Configure WiFi.
- Create ThingSpeak channel.
- Create Telegram bot.
- Configure n8n workflow.
- Connect Google Sheets.
- Test alerts.
- Deploy for real-time monitoring.
21. Conclusion
This AI-Powered Health Monitoring System combines ESP32 IoT hardware, ThingSpeak cloud analytics, n8n automation, Telegram voice notifications, Google Sheets logging, and AI-based prediction techniques to provide a complete smart healthcare solution for patient monitoring and emergency alert management.

No comments:
Post a Comment