AI-Based Smart Voice Assistant for Elderly People
ESP32 + IoT + AI Agent + n8n Automation + Telegram Voice Alerts + Google Sheets + ThingSpeak Cloud Dashboard + PHP IoT Webpage
AI-Powered ESP32 Agentic IoT n8n Automation Telegram Alerts Google Sheets ThingSpeak
1. Complete Project Overview
The AI-Based Smart Voice Assistant for Elderly People is an intelligent IoT healthcare and safety system designed to assist senior citizens in their daily lives.
The system uses an ESP32 microcontroller connected to environmental sensors, motion sensors, emergency buttons, optional health sensors, microphone modules, speakers, and display modules.
Sensor information is transmitted through Wi-Fi to an IoT server and n8n automation platform. The n8n workflow uses an AI Agent to analyze the elderly person's condition and automatically generate notifications.
Main Objective
- Monitor elderly people remotely.
- Detect emergency situations.
- Provide voice-based assistance.
- Send automatic Telegram notifications.
- Generate Telegram voice alerts.
- Store data in Google Sheets.
- Display data using ThingSpeak.
- Predict abnormal power consumption.
- Detect unusual inactivity.
- Provide AI-based risk analysis.
2. Major System Features
Emergency SOS
The elderly person can press an emergency button. The ESP32 immediately sends an emergency event to the n8n AI automation system.
Voice Assistant
The system can process voice commands such as medication reminders, emergency assistance, temperature requests, and appliance control.
AI Monitoring
The AI Agent analyzes sensor data and classifies the situation as normal, low risk, medium risk, high risk, or critical.
Telegram Voice Alerts
Caregivers can receive text messages and voice notifications through Telegram.
Cloud Dashboard
Sensor values can be monitored using a PHP IoT webpage and ThingSpeak cloud dashboard.
Data Logging
All important events can be stored in Google Sheets and MySQL.
3. Components List
Hardware Components
| Component | Purpose |
|---|---|
| ESP32 DevKit | Main IoT controller |
| DHT22 / DHT11 | Temperature and humidity measurement |
| PIR Sensor | Motion and activity detection |
| Push Button | Emergency SOS button |
| OLED Display | Display sensor information |
| Buzzer | Local emergency alarm |
| Speaker | Voice notifications |
| MAX30102 | Optional pulse and heart-rate monitoring |
| LDR | Light monitoring |
| Relay Module | Appliance control |
| Microphone Module | Voice input |
4. Overall System Architecture
5. Circuit Schematic Diagram
DHT22 Connections
DHT22 VCC → ESP32 3.3V
DHT22 GND → ESP32 GND
DHT22 DATA → ESP32 GPIO 4
PIR Connections
PIR VCC → ESP32 5V
PIR GND → ESP32 GND
PIR OUT → ESP32 GPIO 27
Emergency Button
Button Pin 1 → ESP32 GPIO 26
Button Pin 2 → ESP32 GND
ESP32 Configuration:
INPUT_PULLUP
OLED Connections
OLED VCC → ESP32 3.3V
OLED GND → ESP32 GND
OLED SDA → ESP32 GPIO 21
OLED SCL → ESP32 GPIO 22
6. Complete System Flowchart
7. ESP32 Source Code
The ESP32 program connects to Wi-Fi, reads sensors, activates the emergency buzzer, sends data to n8n, sends values to ThingSpeak, and displays information on the OLED display.
#include <WiFi.h>
#include <HTTPClient.h>
#include <DHT.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define DHTPIN 4
#define DHTTYPE DHT22
#define PIR_PIN 27
#define SOS_BUTTON 26
#define BUZZER_PIN 25
#define RELAY_PIN 33
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
DHT dht(
DHTPIN,
DHTTYPE
);
Adafruit_SSD1306 display(
SCREEN_WIDTH,
SCREEN_HEIGHT,
&Wire,
-1
);
const char* ssid =
"YOUR_WIFI_NAME";
const char* password =
"YOUR_WIFI_PASSWORD";
String n8nWebhook =
"https://YOUR_N8N_DOMAIN/webhook/elderly-monitoring";
String thingSpeakURL =
"https://api.thingspeak.com/update";
String thingSpeakAPIKey =
"YOUR_THINGSPEAK_API_KEY";
unsigned long lastSendTime = 0;
const unsigned long sendInterval = 30000;
void setup() {
Serial.begin(115200);
pinMode(
PIR_PIN,
INPUT
);
pinMode(
SOS_BUTTON,
INPUT_PULLUP
);
pinMode(
BUZZER_PIN,
OUTPUT
);
pinMode(
RELAY_PIN,
OUTPUT
);
digitalWrite(
BUZZER_PIN,
LOW
);
digitalWrite(
RELAY_PIN,
LOW
);
dht.begin();
Wire.begin(
21,
22
);
if (
!display.begin(
SSD1306_SWITCHCAPVCC,
0x3C
)
) {
Serial.println(
"OLED initialization failed"
);
while (true);
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(
SSD1306_WHITE
);
display.setCursor(
0,
0
);
display.println(
"Elderly AI Assistant"
);
display.display();
WiFi.begin(
ssid,
password
);
while (
WiFi.status() != WL_CONNECTED
) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println(
"WiFi Connected"
);
Serial.println(
WiFi.localIP()
);
}
void loop() {
float temperature =
dht.readTemperature();
float humidity =
dht.readHumidity();
int motion =
digitalRead(
PIR_PIN
);
int sos =
digitalRead(
SOS_BUTTON
);
bool emergency =
(
sos == LOW
);
if (
isnan(
temperature
) ||
isnan(
humidity
)
) {
Serial.println(
"Sensor reading failed"
);
return;
}
updateDisplay(
temperature,
humidity,
motion,
emergency
);
if (
emergency
) {
digitalWrite(
BUZZER_PIN,
HIGH
);
sendEmergencyAlert(
temperature,
humidity,
motion
);
delay(5000);
digitalWrite(
BUZZER_PIN,
LOW
);
}
if (
millis()
-
lastSendTime
>
sendInterval
) {
sendSensorData(
temperature,
humidity,
motion,
emergency
);
sendThingSpeakData(
temperature,
humidity,
motion
);
lastSendTime =
millis();
}
delay(1000);
}
8. n8n Automation Workflow
n8n Workflow Nodes
- Webhook Node
- JSON Processing Node
- AI Agent Node
- Risk Decision Node
- Telegram Notification Node
- Voice Generation Node
- Google Sheets Node
- ThingSpeak HTTP Request Node
Example n8n Workflow JSON
{
"nodes": [
{
"name":
"ESP32 Webhook",
"type":
"Webhook",
"method":
"POST",
"path":
"elderly-monitoring"
},
{
"name":
"AI Analysis",
"type":
"AI Agent"
},
{
"name":
"Risk Decision",
"type":
"IF"
},
{
"name":
"Telegram Alert",
"type":
"Telegram"
},
{
"name":
"Google Sheets Log",
"type":
"Google Sheets"
},
{
"name":
"Voice Notification",
"type":
"Text to Speech"
}
]
}
9. Telegram Bot Setup
Step 1: Open Telegram
Search for BotFather.
Step 2: Create a Bot
/newbot
Step 3: Copy the Bot Token
123456789:ABCxxxxxxxxxxxxxxxx
Example Telegram Alert
🚨 CRITICAL ELDERLY ALERT 🚨
Device: ELDERLY_001
Emergency Status: ACTIVE
Temperature: 41°C
Humidity: 75%
Motion: NOT DETECTED
Risk Level: CRITICAL
AI Recommendation:
Immediately contact the elderly person's caregiver.
10. Google Sheets Integration
Google Sheets is used for historical data logging and monitoring.
| Column | Description |
|---|---|
| Timestamp | Event date and time |
| Device ID | ESP32 device identifier |
| Temperature | Temperature value |
| Humidity | Humidity value |
| Motion | Motion detection result |
| Emergency | Emergency status |
| Risk Level | AI classification |
| AI Recommendation | AI-generated response |
11. ThingSpeak Cloud Dashboard
ThingSpeak can be used to visualize sensor information using real-time graphs.
| Field | Data |
|---|---|
| Field 1 | Temperature |
| Field 2 | Humidity |
| Field 3 | Motion |
| Field 4 | Emergency Status |
| Field 5 | Power Consumption |
| Field 6 | AI Prediction |
12. AI Power Consumption Prediction
The AI system can analyze historical power consumption data from the ESP32 and identify abnormal trends.
IF power consumption increases continuously
AND sensor values remain normal
THEN
classify as:
"Possible power inefficiency"
ELSE IF power increases suddenly
THEN
classify as:
"Possible hardware fault"
ELSE
classify as:
"Normal power consumption"
Example
| Time | Power |
|---|---|
| 08:00 | 2.1 W |
| 09:00 | 2.4 W |
| 10:00 | 2.6 W |
| 11:00 | 2.9 W |
| 12:00 | 3.3 W |
13. Voice Notification Automation
"Emergency alert.
The elderly person has activated
the SOS button.
Please provide immediate assistance."
14. MySQL Database Design
CREATE DATABASE elderly_ai_system;
CREATE TABLE sensor_data (
id INT AUTO_INCREMENT PRIMARY KEY,
device_id VARCHAR(50),
temperature FLOAT,
humidity FLOAT,
motion INT,
emergency BOOLEAN,
risk_level VARCHAR(30),
ai_message TEXT,
power_consumption FLOAT,
created_at
TIMESTAMP
DEFAULT CURRENT_TIMESTAMP
);
15. PHP IoT Web Dashboard Design
Temperature
31.2 °C
Humidity
65 %
Motion
Detected
Emergency
Normal
Risk Level
LOW
AI Recommendation
Continue Monitoring
16. AI Alert Levels
| Level | Condition | Action |
|---|---|---|
| NORMAL | Normal sensor values | Store data |
| LOW RISK | Slightly unusual activity | Continue monitoring |
| MEDIUM RISK | Long inactivity or high temperature | Telegram notification |
| HIGH RISK | Dangerous environment | Telegram plus voice alert |
| CRITICAL | SOS button activated | Immediate emergency alert |
17. Elderly Inactivity Detection
The system can detect unusual periods of inactivity. For example, if no movement is detected for several hours, the AI Agent can notify the caregiver.
18. Project Folder Structure
elderly-ai-assistant/
│
├── esp32/
│ └── elderly_ai_assistant.ino
│
├── php/
│ ├── index.php
│ ├── dashboard.php
│ ├── api/
│ │ ├── sensor_data.php
│ │ ├── get_latest_data.php
│ │ └── emergency.php
│ │
│ ├── config/
│ │ └── database.php
│ │
│ └── assets/
│ ├── css/
│ └── js/
│
├── database/
│ └── elderly_ai_system.sql
│
├── n8n/
│ └── elderly_ai_workflow.json
│
└── documentation/
└── project_report.html
19. Step-by-Step Installation Procedure
- Assemble the ESP32 and sensors.
- Install the required Arduino libraries.
- Configure the Wi-Fi credentials.
- Create the ThingSpeak channel.
- Create the Telegram bot.
- Configure the n8n Webhook.
- Configure the AI Agent.
- Create the Google Sheet.
- Configure Telegram credentials.
- Upload the ESP32 source code.
- Test the sensors.
- Test the emergency button.
- Verify Telegram notifications.
- Verify Google Sheets logging.
- Verify ThingSpeak graphs.
20. Testing Table
| Test | Expected Result |
|---|---|
| Power ON | ESP32 starts |
| Wi-Fi Available | ESP32 connects |
| DHT Sensor | Temperature displayed |
| PIR Movement | Motion detected |
| SOS Pressed | Emergency alert generated |
| High Temperature | Risk classification generated |
| Telegram | Notification received |
| Google Sheets | New row created |
| ThingSpeak | Graph updated |
21. Future Enhancements
- AI-based fall detection using ESP32-CAM.
- GPS location tracking.
- Automatic emergency calling.
- Smart medication dispenser.
- Face recognition.
- Advanced health anomaly detection.
- Machine learning-based activity prediction.
- Solar-powered operation.
- Battery monitoring.
- Multi-home caregiver management.
22. Deployment Guide
Small Home Deployment
Multi-Home Deployment
Each ESP32 device should have a unique device ID.
ELDERLY_001
ELDERLY_002
ELDERLY_003
23. Complete Project Workflow
ESP32 + Sensors + AI Agent + n8n Automation + Telegram Voice Alerts + Google Sheets + ThingSpeak + PHP IoT Dashboard + MySQL
This project creates a complete intelligent Agentic IoT elderly-care ecosystem capable of monitoring sensor conditions, detecting emergencies, analyzing data using AI, predicting abnormal behavior, sending Telegram and voice alerts, and storing historical information.

No comments:
Post a Comment