Wednesday, 7 October 2026

AI GPS Tracking System for Dementia Patients with Health Analytics

AI GPS Tracking System for Dementia Patients with Health Analytics

Below is a complete project documentation blueprint that you can use for a final-year project, prototype, dissertation, or engineering demonstration. It combines ESP32 + GPS + health sensors + AI agent + n8n + Telegram + Google Sheets + ThingSpeak + IoT web dashboard.

1. Project Title

AI-Powered GPS Tracking and Health Analytics System for Dementia Patients Using ESP32, n8n Automation, Telegram Voice Alerts, Google Sheets and ThingSpeak

Alternative short title

Agentic IoT-Based Dementia Patient Monitoring and GPS Alert System


2. Abstract

Dementia patients, particularly elderly patients with memory-related disorders, can become disoriented and wander away from their safe location. Finding the patient quickly while simultaneously monitoring basic health parameters can be difficult for caregivers.

This project proposes an AI-powered IoT monitoring system based on an ESP32 microcontroller. The ESP32 collects the patient's geographical location from a GPS module and health information from connected sensors. The collected data is transmitted to a cloud/automation layer where n8n performs workflow automation.

An AI agent analyzes incoming information and determines whether an event is normal, requires caregiver attention, or represents a potentially urgent situation. When appropriate, the system sends notifications to caregivers through Telegram, including automated voice notifications. Location and health records can also be stored in Google Sheets, while ThingSpeak can provide graphical IoT analytics.

A web dashboard provides the caregiver with the patient's latest location, health information, device status, alert status, and historical analytics.

The proposed system therefore combines:

  • IoT sensing
  • GPS tracking
  • ESP32
  • AI-based decision support
  • Agentic automation
  • n8n workflows
  • Telegram notifications
  • Telegram voice alerts
  • Google Sheets
  • ThingSpeak
  • Web dashboard
  • Health analytics

The prototype is intended as a caregiver-support and early-warning system, rather than a certified medical device.


3. Problem Statement

Dementia patients may experience:

  • wandering
  • disorientation
  • inability to communicate their location
  • accidental movement outside a predefined safe zone
  • falls or prolonged inactivity
  • abnormal physiological measurements
  • difficulty contacting caregivers during an emergency

Traditional GPS trackers may provide location but generally do not combine location with health information and intelligent automated decision-making.

The proposed system addresses this problem by creating a connected device that continuously monitors:

Patient → Location + Health + Device Status → AI Analysis → Automated Action → Caregiver


4. Proposed Solution

The system consists of five major layers.

┌─────────────────────────────────────────────┐
│              PATIENT DEVICE                 │
│                                             │
│ ESP32 + GPS + Heart Rate + SpO₂ + Temp     │
│ + Emergency Button + Buzzer                 │
└───────────────────┬─────────────────────────┘
                    │ Wi-Fi / Internet
                    ▼
┌─────────────────────────────────────────────┐
│              IoT CLOUD LAYER                │
│                                             │
│        ThingSpeak / Web API / MQTT          │
└───────────────────┬─────────────────────────┘
                    │
                    ▼
┌─────────────────────────────────────────────┐
│             AUTOMATION LAYER                │
│                                             │
│                    n8n                      │
│                                             │
│ Webhook → Validation → AI Agent → Decision │
└───────────────────┬─────────────────────────┘
                    │
          ┌─────────┼──────────┐
          ▼         ▼          ▼
     Telegram   Google Sheets  Dashboard
       Alert       Database       │
          │                       │
          ▼                       ▼
   Caregiver Phone          Health Analytics

5. Overall System Architecture

                       ┌─────────────────────┐
                       │     PATIENT         │
                       │                     │
                       │ Dementia Patient    │
                       └──────────┬──────────┘
                                  │
                                  ▼
                     ┌────────────────────────┐
                     │       ESP32            │
                     │   Main Controller      │
                     └───────────┬────────────┘
                                 │
            ┌────────────────────┼───────────────────┐
            │                    │                   │
            ▼                    ▼                   ▼
      ┌───────────┐       ┌────────────┐      ┌─────────────┐
      │ GPS       │       │ Health     │      │ Emergency   │
      │ Module    │       │ Sensors    │      │ Button      │
      └─────┬─────┘       └─────┬──────┘      └──────┬──────┘
            │                   │                    │
            └───────────────────┼────────────────────┘
                                │
                                ▼
                       ┌─────────────────┐
                       │ Wi-Fi / Internet│
                       └────────┬────────┘
                                │
              ┌─────────────────┼──────────────────┐
              │                 │                  │
              ▼                 ▼                  ▼
       ┌────────────┐     ┌─────────────┐    ┌──────────────┐
       │ ThingSpeak │     │ n8n         │    │ Web Server   │
       │ Analytics  │     │ Automation  │    │ Dashboard    │
       └────────────┘     └──────┬──────┘    └──────────────┘
                                 │
                                 ▼
                         ┌──────────────┐
                         │   AI Agent   │
                         └──────┬───────┘
                                │
                    ┌───────────┼───────────┐
                    ▼           ▼           ▼
              ┌──────────┐ ┌─────────┐ ┌─────────────┐
              │ Telegram │ │ Google  │ │ Alert       │
              │          │ │ Sheets  │ │ Database    │
              └────┬─────┘ └─────────┘ └─────────────┘
                   │
                   ▼
             ┌────────────┐
             │ Caregiver  │
             │ Smartphone │
             └────────────┘

6. Hardware Requirements

Main controller

ESP32

ESP32 is the central controller.

Responsibilities:

  • read sensors
  • obtain GPS coordinates
  • connect to Wi-Fi
  • construct JSON data
  • communicate with the cloud
  • detect emergency button presses
  • periodically transmit patient data

GPS Module

A module such as NEO-6M GPS can be used for the prototype.

Typical information:

Latitude
Longitude
Altitude
Number of satellites
GPS fix
Speed
Timestamp

Example:

Latitude  : 17.385044
Longitude : 78.486671
Satellites: 8
Speed     : 1.2 km/h

7. Health Sensors

The exact sensors can be changed depending on the project's budget.

A useful prototype configuration is:

MAX30102

Can provide:

  • heart-rate estimation
  • SpO₂ estimation

DS18B20

Can provide:

  • body/skin temperature measurement depending on physical implementation

MPU6050

Can provide:

  • acceleration
  • movement
  • orientation
  • possible fall-event detection

Emergency button

The patient can press the button when assistance is required.


8. Suggested Hardware Block

                 ┌─────────────────┐
                 │      ESP32      │
                 │                 │
                 │ GPIO / I2C /    │
                 │ UART / Wi-Fi    │
                 └───┬─┬─┬─┬──────┘
                     │ │ │ │
       ┌─────────────┘ │ │ └──────────────┐
       │               │ │                │
       ▼               ▼ ▼                ▼
   ┌────────┐     ┌────────┐        ┌────────────┐
   │ GPS    │     │MAX30102│        │ MPU6050    │
   │ NEO-6M │     │HR/SpO₂ │        │ Motion     │
   └────────┘     └────────┘        └────────────┘
                       │
                       ▼
                  ┌─────────┐
                  │DS18B20  │
                  │Temperature
                  └─────────┘

                       │
                       ▼
                ┌────────────┐
                │ Emergency  │
                │ Push Button│
                └────────────┘

9. Example ESP32 Pin Assignment

One possible configuration:

Component ESP32 connection
GPS TX GPIO 16
GPS RX GPIO 17
MAX30102 SDA GPIO 21
MAX30102 SCL GPIO 22
MPU6050 SDA GPIO 21
MPU6050 SCL GPIO 22
DS18B20 DATA GPIO 4
Emergency button GPIO 27
Buzzer GPIO 26

Important: GPIO assignments are examples. Check the exact breakout-board voltage requirements and ESP32 board variant before wiring.


10. Schematic Diagram

A simplified schematic is:

                         +------------------+
                         |      ESP32       |
                         |                  |
                   +-----| GPIO16          |
                   |     | GPIO17          |
                   |     |                  |
                   |     | GPIO21 ────────────── SDA
                   |     | GPIO22 ────────────── SCL
                   |     |                  |
                   |     | GPIO4 ─────────────── DS18B20
                   |     | GPIO27 ────────────── Emergency
                   |     | GPIO26 ────────────── Buzzer
                   |     +------------------+
                   |
                   |
          +--------+---------+
          |                  |
          ▼                  ▼
     GPS NEO-6M          Wi-Fi
     TX/RX               Internet
          |
          ▼
   Latitude/Longitude


       I2C BUS
          │
    ┌─────┴─────────────┐
    │                   │
    ▼                   ▼
 MAX30102             MPU6050
 HR/SpO₂              Movement

11. Power System

For a wearable prototype:

        Li-ion Battery
              │
              ▼
       Protection Circuit
              │
              ▼
       Voltage Regulation
              │
       ┌──────┴───────┐
       ▼              ▼
     ESP32         Sensors

The battery and regulator must be selected according to the particular ESP32 board and sensor modules. Do not connect a raw lithium cell directly to a circuit unless the board is explicitly designed for that input.


12. Software Architecture

The software has four major components:

ESP32 Firmware
      │
      ▼
Cloud/API
      │
      ▼
n8n Automation
      │
      ▼
AI Agent
      │
      ├── Telegram
      ├── Google Sheets
      ├── ThingSpeak
      └── Web Dashboard

13. Data Flow

The ESP32 periodically generates a JSON packet.

Example:

{
  "patient_id": "P001",
  "latitude": 17.385044,
  "longitude": 78.486671,
  "heart_rate": 78,
  "spo2": 97,
  "temperature": 36.7,
  "motion": 0.42,
  "battery": 82,
  "emergency": false,
  "timestamp": "2026-10-08T07:40:00"
}

This data is sent to an n8n webhook.


14. n8n Workflow

The main workflow can be designed as:

             ESP32
               │
               ▼
        ┌──────────────┐
        │ Webhook      │
        │ Trigger      │
        └──────┬───────┘
               │
               ▼
        ┌──────────────┐
        │ Validate JSON│
        └──────┬───────┘
               │
               ▼
        ┌──────────────┐
        │ Store Data   │
        └──────┬───────┘
               │
               ▼
        ┌──────────────┐
        │ AI Agent     │
        │ Analyze      │
        └──────┬───────┘
               │
               ▼
        ┌──────────────┐
        │ Decision     │
        │ Node         │
        └──────┬───────┘
               │
       ┌───────┼────────┐
       │       │        │
       ▼       ▼        ▼
     NORMAL  WARNING  EMERGENCY
       │       │        │
       ▼       ▼        ▼
    Record  Telegram  Telegram
             Alert     Voice
       │       │        │
       └───────┼────────┘
               ▼
         Google Sheets
               │
               ▼
          Dashboard

15. AI Agent Concept

The AI agent should not directly diagnose a medical condition.

Instead, it acts as an intelligent event-classification and notification agent.

For example, it can receive:

Heart rate = 115
SpO₂ = 91
Temperature = 38.1
Outside geofence = TRUE
Emergency button = FALSE

The agent can classify this as:

Priority: HIGH
Reason:
Patient is outside the safe zone and multiple
measurements require caregiver attention.

Action:
Send urgent caregiver notification.

The AI agent can return structured JSON:

{
  "severity": "HIGH",
  "event": "GEOFENCE_AND_HEALTH_WARNING",
  "notify": true,
  "voice_alert": true,
  "reason": "Patient is outside the configured safe zone."
}

16. Agentic IoT Decision Loop

The important difference between simple IoT and agentic IoT is that the system doesn't merely transmit data.

It follows:

SENSE
  ↓
UNDERSTAND
  ↓
REASON
  ↓
DECIDE
  ↓
ACT
  ↓
VERIFY

For this project:

Sensors
   ↓
ESP32
   ↓
n8n
   ↓
AI Agent
   ↓
Risk Assessment
   ↓
Action Selection
   ↓
Telegram / Voice / Dashboard
   ↓
Caregiver Response

17. Geofencing

A particularly important feature for dementia patients is a safe-zone geofence.

For example:

              SAFE ZONE

        ┌─────────────────────┐
        │                     │
        │        🏠           │
        │       HOME          │
        │                     │
        │       👴           │
        │     PATIENT         │
        │                     │
        └─────────────────────┘
                 │
                 │ Patient moves
                 ▼

               ⚠️
           OUTSIDE ZONE

        Caregiver notification

The ESP32 or backend can determine whether the patient's coordinates are inside the permitted radius.


18. Geofence Calculation

A simple prototype can use the Haversine formula.

distance = 2R × asin(
    sqrt(
      sin²((lat2-lat1)/2) +
      cos(lat1) × cos(lat2) ×
      sin²((lon2-lon1)/2)
    )
)

Where:

  • R = Earth radius
  • lat1, lon1 = safe-zone center
  • lat2, lon2 = patient's current position

Example:

Safe-zone radius = 100 m

Distance:
35 m → NORMAL
80 m → NORMAL
105 m → ALERT
250 m → HIGH PRIORITY

A production system should account for GPS uncertainty and should not treat a single noisy GPS reading as definitive evidence of wandering.


19. Telegram Alert System

Telegram can be used as the primary caregiver notification channel.

Normal event

ESP32
  │
  ▼
n8n
  │
  ▼
AI Agent
  │
  ▼
NORMAL
  │
  ▼
Google Sheets

No Telegram message is necessary.

Warning

ESP32
  │
  ▼
n8n
  │
  ▼
AI Agent
  │
  ▼
WARNING
  │
  ▼
Telegram

Example:

⚠️ PATIENT WARNING

Patient: P001

Location:
17.385044, 78.486671

Status:
Patient is approaching the safe-zone boundary.

Battery: 62%

Please check the patient's location.

20. Emergency Telegram Voice Alert

For an emergency event:

ESP32
   │
   ▼
n8n
   │
   ▼
AI Agent
   │
   ▼
EMERGENCY
   │
   ├──────────────► Telegram Text
   │
   └──────────────► Voice Generation
                         │
                         ▼
                     Telegram
                         │
                         ▼
                     Caregiver

Example text:

🚨 URGENT PATIENT ALERT

Patient P001 requires immediate caregiver attention.

Possible reasons:
• Patient outside safe zone
• Abnormal sensor reading
• Emergency button activated

Current location:
17.385044, 78.486671

The voice component can convert the alert text into an audio message before sending it to Telegram.


21. Telegram Conversation Concept

The system can also support caregiver commands.

Caregiver

/status P001

AI Agent

Patient P001 Status

Location: Safe Zone
Heart Rate: 78 BPM
SpO₂: 97%
Temperature: 36.7°C
Battery: 82%

Overall:
NORMAL

Another example:

Caregiver

Where is patient P001?

AI agent:

Patient P001 is currently within the configured
safe zone.

Latest GPS:
17.385044, 78.486671

Last update:
07:40:00

22. Google Sheets Integration

Google Sheets can be used as a simple historical database for the prototype.

Suggested columns:

Timestamp Patient ID Latitude Longitude HR SpO₂ Temp Battery Geofence Alert
07:40 P001 17.385 78.486 78 97 36.7 82 SAFE NO
07:41 P001 17.386 78.487 82 96 36.8 81 SAFE NO
07:42 P001 17.388 78.489 95 95 36.8 81 WARNING YES

This allows the project examiner to demonstrate historical analytics easily.


23. ThingSpeak Integration

ThingSpeak can be used for IoT visualization.

Example field mapping:

Field 1 = Heart Rate
Field 2 = SpO₂
Field 3 = Temperature
Field 4 = Latitude
Field 5 = Longitude
Field 6 = Battery
Field 7 = Motion

Dashboard:

┌─────────────────────────────────────────┐
│       PATIENT IoT DASHBOARD             │
├─────────────────────────────────────────┤
│ Heart Rate        78 BPM                │
│ SpO₂              97 %                  │
│ Temperature       36.7 °C               │
│ Battery           82 %                  │
│ Motion            NORMAL                │
│ Location          SAFE ZONE             │
├─────────────────────────────────────────┤
│                                         │
│          HEALTH GRAPH                   │
│                                         │
│ HR ─────╮                               │
│         ╰──╮────╮                       │
│            ╰────╰────                   │
│                                         │
└─────────────────────────────────────────┘

24. IoT Webpage

The project can have its own web interface.

Dashboard structure

================================================
       AI DEMENTIA CARE MONITOR
================================================

 Patient: P001
 Status: 🟢 SAFE

 ┌───────────┐ ┌───────────┐ ┌──────────────┐
 │ ❤️ 78 BPM │ │ SpO₂ 97%  │ │ Temp 36.7°C  │
 └───────────┘ └───────────┘ └──────────────┘

 Battery: ████████░░ 82%

 Location
 ┌────────────────────────────────────────────┐
 │                                            │
 │                 📍 PATIENT                │
 │                                            │
 │              GPS MAP AREA                  │
 │                                            │
 └────────────────────────────────────────────┘

 AI STATUS
 ┌────────────────────────────────────────────┐
 │ NORMAL                                     │
 │ No immediate caregiver action required.   │
 └────────────────────────────────────────────┘

 Recent Events
 ─────────────────────────────────────────────
 07:42  Patient within safe zone
 07:41  Normal health measurements
 07:40  Device connected

25. Webpage Technology

A simple implementation can use:

Frontend:
HTML
CSS
JavaScript

Backend/API:
Node.js / Python / n8n Webhook

Database:
Google Sheets / database

IoT:
ThingSpeak

AI:
LLM through n8n AI Agent

26. ESP32 Firmware

Below is a prototype firmware structure. The exact sensor libraries and GPS module wiring may need adjustment for the particular boards being used.

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

const char* WIFI_SSID = "YOUR_WIFI";
const char* WIFI_PASSWORD = "YOUR_PASSWORD";

const char* WEBHOOK_URL =
    "https://YOUR-N8N-SERVER/webhook/patient-data";

TinyGPSPlus gps;

HardwareSerial GPSSerial(2);

#define GPS_RX 16
#define GPS_TX 17

#define EMERGENCY_BUTTON 27
#define BUZZER 26

unsigned long lastSend = 0;

void setup() {

  Serial.begin(115200);

  pinMode(EMERGENCY_BUTTON, INPUT_PULLUP);
  pinMode(BUZZER, OUTPUT);

  GPSSerial.begin(
    9600,
    SERIAL_8N1,
    GPS_RX,
    GPS_TX
  );

  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

  Serial.print("Connecting to WiFi");

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

  Serial.println();
  Serial.println("WiFi connected");
}

void readGPS() {

  while (GPSSerial.available()) {
    gps.encode(GPSSerial.read());
  }
}

void sendData() {

  if (WiFi.status() != WL_CONNECTED) {
    return;
  }

  HTTPClient http;

  http.begin(WEBHOOK_URL);
  http.addHeader("Content-Type", "application/json");

  float latitude = 0;
  float longitude = 0;

  if (gps.location.isValid()) {
    latitude = gps.location.lat();
    longitude = gps.location.lng();
  }

  /*
     Replace these demonstration values
     with actual sensor readings.
  */

  float heartRate = 78.0;
  float spo2 = 97.0;
  float temperature = 36.7;
  float battery = 82.0;

  bool emergency =
      digitalRead(EMERGENCY_BUTTON) == LOW;

  StaticJsonDocument<512> doc;

  doc["patient_id"] = "P001";
  doc["latitude"] = latitude;
  doc["longitude"] = longitude;
  doc["heart_rate"] = heartRate;
  doc["spo2"] = spo2;
  doc["temperature"] = temperature;
  doc["battery"] = battery;
  doc["emergency"] = emergency;

  String json;

  serializeJson(doc, json);

  Serial.println(json);

  int responseCode =
      http.POST(json);

  Serial.print("HTTP response: ");
  Serial.println(responseCode);

  http.end();
}

void loop() {

  readGPS();

  if (millis() - lastSend > 30000) {

    lastSend = millis();

    sendData();
  }
}

27. Important ESP32 Security Improvement

Do not permanently expose credentials such as:

WiFi.begin("MyWiFi", "password");

in a publicly shared project repository.

For the final project, use:

  • environment/configuration storage
  • secrets management
  • HTTPS
  • authenticated webhooks
  • unique device IDs
  • API keys stored securely

28. n8n Workflow in Detail

The workflow can be constructed as:

[Webhook]
    │
    ▼
[JSON Validation]
    │
    ▼
[Data Normalization]
    │
    ▼
[Geofence Calculation]
    │
    ▼
[AI Agent]
    │
    ▼
[IF / Switch]
    │
    ├──────── NORMAL
    │             │
    │             ▼
    │       [Google Sheets]
    │
    ├──────── WARNING
    │             │
    │             ├──► [Telegram]
    │             └──► [Google Sheets]
    │
    └──────── EMERGENCY
                  │
                  ├──► [Telegram Text]
                  │
                  ├──► [Voice Generation]
                  │
                  ├──► [Telegram Voice]
                  │
                  └──► [Google Sheets]

29. AI Agent Prompt

A suitable prototype system prompt could be:

You are an IoT caregiver-support decision agent.

Your job is to analyze incoming patient-monitoring
data and classify the event as NORMAL, WARNING,
or EMERGENCY.

Consider:

1. Geofence status
2. Emergency button
3. Heart-rate reading
4. SpO2 reading
5. Temperature
6. Movement
7. Battery level
8. Data freshness

Do not diagnose diseases.

Do not claim that a sensor reading proves a medical
condition.

If a reading appears concerning, recommend caregiver
attention and escalation according to the configured
rules.

Return JSON only:

{
  "severity": "NORMAL|WARNING|EMERGENCY",
  "notify": true/false,
  "voice_alert": true/false,
  "reason": "...",
  "recommended_action": "..."
}

30. Rule-Based Safety Layer

For a health-related project, the AI should not be the only decision mechanism.

Use:

Sensor
  ↓
Hard Safety Rules
  ↓
AI Agent
  ↓
Final Decision

For example:

Emergency button = TRUE
       ↓
Immediate emergency workflow

rather than allowing an LLM to decide whether a manually activated emergency button is important.

Similarly, sensor thresholds should be configurable and validated by an appropriate professional rather than presented as universal medical thresholds.


31. AI + Rules Architecture

                 SENSOR DATA
                     │
                     ▼
             ┌───────────────┐
             │ Validation    │
             └───────┬───────┘
                     │
                     ▼
             ┌───────────────┐
             │ Safety Rules  │
             └───────┬───────┘
                     │
            ┌────────┴────────┐
            │                 │
         Critical          Normal
            │                 │
            ▼                 ▼
     Immediate Alert       AI Agent
                              │
                              ▼
                        Risk Analysis
                              │
                              ▼
                         Final Action

This architecture is considerably safer than allowing an AI model to independently control emergency decisions.


32. Example n8n Code Node

A simple data-normalization node can use JavaScript:

const data = $json;

const latitude = Number(data.latitude);
const longitude = Number(data.longitude);

const heartRate = Number(data.heart_rate);
const spo2 = Number(data.spo2);
const temperature = Number(data.temperature);
const battery = Number(data.battery);

const emergency = Boolean(data.emergency);

return [{
  json: {
    patient_id: data.patient_id || "UNKNOWN",

    location: {
      latitude,
      longitude
    },

    health: {
      heart_rate: heartRate,
      spo2,
      temperature
    },

    battery,
    emergency,

    received_at: new Date().toISOString()
  }
}];

33. Geofence Logic in n8n

Conceptually:

function distance(lat1, lon1, lat2, lon2) {

  const R = 6371000;

  const toRad = x => x * Math.PI / 180;

  const dLat = toRad(lat2 - lat1);
  const dLon = toRad(lon2 - lon1);

  const a =
    Math.sin(dLat / 2) ** 2 +
    Math.cos(toRad(lat1)) *
    Math.cos(toRad(lat2)) *
    Math.sin(dLon / 2) ** 2;

  const c =
    2 * Math.atan2(
      Math.sqrt(a),
      Math.sqrt(1 - a)
    );

  return R * c;
}

const safeLat = 17.385044;
const safeLon = 78.486671;

const patientLat = Number($json.location.latitude);
const patientLon = Number($json.location.longitude);

const distanceMeters =
  distance(
    safeLat,
    safeLon,
    patientLat,
    patientLon
  );

const safeRadius = 100;

return [{
  json: {
    ...$json,
    distance_from_home: distanceMeters,
    geofence:
      distanceMeters <= safeRadius
        ? "SAFE"
        : "OUTSIDE"
  }
}];

34. Alert Decision

A simple prototype decision system:

                 ┌──────────────┐
                 │ Emergency ?  │
                 └──────┬───────┘
                        │
                YES ────┴────► EMERGENCY
                        │
                       NO
                        │
                        ▼
              ┌─────────────────┐
              │ Outside Zone ?  │
              └───────┬─────────┘
                      │
             YES ─────┴────► WARNING
                      │
                     NO
                      │
                      ▼
              ┌─────────────────┐
              │ Health anomaly? │
              └───────┬─────────┘
                      │
                YES ──┴──► WARNING
                      │
                     NO
                      │
                      ▼
                    NORMAL

35. Voice Alert Generation

The voice pipeline is:

AI Agent
   │
   ▼
Alert Text
   │
   ▼
Text-to-Speech
   │
   ▼
Audio File
   │
   ▼
Telegram Bot
   │
   ▼
Caregiver

Example generated voice message:

"Urgent alert. Patient P001 has moved outside the configured safe zone. Please check the patient's location."

For privacy, avoid including unnecessary sensitive information in notifications.


36. Complete System Flow

START
  │
  ▼
ESP32 POWER ON
  │
  ▼
CONNECT Wi-Fi
  │
  ▼
INITIALIZE GPS
  │
  ▼
INITIALIZE HEALTH SENSORS
  │
  ▼
READ SENSORS
  │
  ▼
GET GPS LOCATION
  │
  ▼
CHECK EMERGENCY BUTTON
  │
  ▼
CREATE JSON
  │
  ▼
SEND TO n8n
  │
  ▼
VALIDATE DATA
  │
  ▼
CHECK GEOFENCE
  │
  ▼
CHECK SAFETY RULES
  │
  ▼
AI AGENT ANALYSIS
  │
  ▼
┌────────────────────────────┐
│ Determine event severity   │
└─────────────┬──────────────┘
              │
      ┌───────┼────────┐
      ▼       ▼        ▼
    NORMAL WARNING EMERGENCY
      │       │        │
      │       ▼        ▼
      │    Telegram   Telegram
      │       │       + Voice
      │       │        │
      └───────┴────────┘
              │
              ▼
        Google Sheets
              │
              ▼
        ThingSpeak
              │
              ▼
        Web Dashboard
              │
              ▼
          END/CYCLE

37. Database/Data Architecture

For a prototype:

ESP32
 │
 ├──► n8n
 │       │
 │       ├──► Google Sheets
 │       ├──► ThingSpeak
 │       └──► AI Agent
 │
 └──► Web API

For a more advanced version:

ESP32
 │
 ▼
MQTT / HTTPS
 │
 ▼
API Gateway
 │
 ▼
Database
 │
 ├── PostgreSQL
 ├── Time-series storage
 └── Event database
 │
 ▼
AI Agent
 │
 ▼
Dashboard / Telegram

38. Web Dashboard HTML Prototype

A basic frontend can look like:

<!DOCTYPE html>
<html>
<head>
    <title>AI Dementia Care Monitor</title>

    <style>

        body {
            font-family: Arial, sans-serif;
            background: #f3f6fa;
            margin: 0;
            padding: 20px;
        }

        h1 {
            color: #1f2937;
        }

        .dashboard {
            display: grid;
            grid-template-columns:
                repeat(auto-fit, minmax(200px, 1fr));
            gap: 20px;
        }

        .card {
            background: white;
            padding: 20px;
            border-radius: 12px;
            box-shadow:
                0 3px 10px rgba(0,0,0,0.1);
        }

        .value {
            font-size: 30px;
            font-weight: bold;
        }

        .safe {
            color: green;
        }

        .warning {
            color: orange;
        }

        .danger {
            color: red;
        }

    </style>
</head>

<body>

<h1>AI Dementia Care Monitor</h1>

<div class="dashboard">

    <div class="card">
        <h3>Heart Rate</h3>
        <div class="value">78 BPM</div>
    </div>

    <div class="card">
        <h3>SpO₂</h3>
        <div class="value">97%</div>
    </div>

    <div class="card">
        <h3>Temperature</h3>
        <div class="value">36.7 °C</div>
    </div>

    <div class="card">
        <h3>Battery</h3>
        <div class="value">82%</div>
    </div>

    <div class="card">
        <h3>Patient Status</h3>
        <div class="value safe">SAFE</div>
    </div>

</div>

<div class="card" style="margin-top:20px">

    <h2>Current Location</h2>

    <p>
        Latitude: 17.385044
    </p>

    <p>
        Longitude: 78.486671
    </p>

</div>

<div class="card" style="margin-top:20px">

    <h2>AI Assessment</h2>

    <p class="safe">
        No immediate caregiver action required.
    </p>

</div>

</body>
</html>

This is only the UI layer; the real-time values would be populated through an API/websocket/database.


39. Example API Response

The dashboard could request:

GET /api/patient/P001

and receive:

{
  "patient_id": "P001",
  "status": "SAFE",
  "location": {
    "latitude": 17.385044,
    "longitude": 78.486671
  },
  "health": {
    "heart_rate": 78,
    "spo2": 97,
    "temperature": 36.7
  },
  "battery": 82,
  "last_update": "2026-10-08T07:40:00Z"
}

40. Project Chat/Interaction Flow

Scenario 1 — Normal

ESP32:
Patient data received.

AI Agent:
Patient is inside safe zone.
No significant configured alert condition detected.

n8n:
Record data.

Google Sheets:
✓ Data stored.

Telegram:
No alert.

Dashboard:
🟢 SAFE

Scenario 2 — Patient Leaves Safe Zone

ESP32:
GPS = outside geofence

        ↓

n8n:
Geofence violation detected.

        ↓

AI Agent:
Potential wandering event.

        ↓

Telegram:

⚠️ PATIENT LOCATION ALERT

Patient P001 is outside the configured
safe zone.

Location:
[GPS coordinates]

Please check the patient.

41. Scenario 3 — Emergency Button

Patient
   │
   ▼
Press Emergency Button
   │
   ▼
ESP32
   │
   ▼
n8n
   │
   ▼
Safety Rule
   │
   ▼
EMERGENCY
   │
   ├───────────────► Telegram Text
   │
   ├───────────────► Voice Alert
   │
   ├───────────────► Google Sheets
   │
   └───────────────► Dashboard

42. Scenario 4 — Device Battery Low

Battery = 15%
       │
       ▼
ESP32
       │
       ▼
n8n
       │
       ▼
AI Agent
       │
       ▼
WARNING
       │
       ▼
Telegram

🔋 LOW BATTERY ALERT

Patient device battery is low.
Please recharge the device.

This is especially important because a GPS tracking system is useless if the wearable shuts down.


43. Health Analytics

The system can calculate:

Average heart rate

Average HR =
Σ heart-rate readings / number of readings

Minimum and maximum

Minimum HR
Maximum HR
Average HR

SpO₂ trend

Time →→→→→

98 ────────╮
           │
97 ────────┼──────╮
           │      │
96         ╰──────╰──

Temperature trend

Temperature

37.0 ─────────╮
36.8          ├──────
36.6          │
36.4 ─────────╯
       Time →

These trends can help caregivers identify changes, but should not be interpreted as medical diagnosis by the AI system.


44. Advanced Analytics

You can calculate:

  • daily average heart rate
  • heart-rate variability trends if the sensor/data quality supports it
  • average SpO₂
  • temperature trend
  • activity level
  • walking duration
  • time outside safe zone
  • number of geofence violations
  • emergency-button events
  • device uptime
  • battery consumption
  • GPS availability
  • sensor-data quality

45. AI Analytics

The AI agent can generate a daily summary such as:

DAILY CAREGIVER SUMMARY

Patient: P001

Location:
Patient remained inside the safe zone for
most of the monitoring period.

Movement:
Normal activity detected.

Health:
No configured alert condition detected.

Device:
Battery remained above the configured warning
level.

Alerts:
1 location warning
0 emergency events

Recommendation:
Continue normal monitoring.

Again, this is a monitoring summary, not a medical diagnosis.


46. System Sequence Diagram

Patient       ESP32        n8n        AI Agent     Telegram    Caregiver
  │             │           │            │             │           │
  │             │           │            │             │           │
  │             │──Data────►│            │             │           │
  │             │           │──Analyze──►│             │           │
  │             │           │            │             │           │
  │             │           │◄─Decision──│             │           │
  │             │           │──Alert─────────────────►│           │
  │             │           │            │             │──Notify──►│
  │             │           │            │             │           │

47. Complete Hardware-to-Cloud Flow

                 PATIENT
                    │
          ┌─────────┴─────────┐
          │                   │
       LOCATION            HEALTH
          │                   │
          ▼                   ▼
        GPS              MAX30102
                           DS18B20
                           MPU6050
          │                   │
          └─────────┬─────────┘
                    ▼
                 ESP32
                    │
                    ▼
               Wi-Fi / HTTPS
                    │
                    ▼
                  n8n
                    │
        ┌───────────┼────────────┐
        │           │            │
        ▼           ▼            ▼
     Rules        AI Agent    Database
        │           │            │
        └──────┬────┘            │
               ▼                 │
          Decision               │
               │                 │
       ┌───────┼────────┐        │
       ▼       ▼        ▼        │
    Normal   Warning  Emergency  │
               │        │        │
               ▼        ▼        ▼
            Telegram  Voice   Google Sheets
                        │
                        ▼
                   Caregiver
                        │
                        ▼
                   Web Dashboard

48. Project Modules

The project can be divided into 10 modules.

Module 1 — Patient wearable

ESP32 + sensors + GPS.

Module 2 — GPS tracking

Obtains latitude/longitude and calculates location.

Module 3 — Health monitoring

Reads physiological/environmental prototype measurements.

Module 4 — Communication

ESP32 communicates with the cloud through Wi-Fi.

Module 5 — n8n automation

Receives and processes device data.

Module 6 — AI Agent

Analyzes context and generates a structured event assessment.

Module 7 — Alert system

Telegram text and voice notifications.

Module 8 — Data storage

Google Sheets and/or database.

Module 9 — IoT analytics

ThingSpeak graphs and historical measurements.

Module 10 — Web dashboard

Caregiver monitoring interface.


49. Development Steps

Step 1 — Assemble ESP32

Connect:

ESP32
 ├── GPS
 ├── MAX30102
 ├── MPU6050
 ├── DS18B20
 ├── Emergency button
 └── Buzzer

Step 2 — Test GPS separately

First verify that GPS produces:

Latitude
Longitude
Satellites
GPS fix

Do not proceed until GPS works reliably outdoors.


Step 3 — Test each health sensor

Test independently:

MAX30102
MPU6050
DS18B20

Then integrate them.


Step 4 — Connect ESP32 to Wi-Fi

Verify:

ESP32
   ↓
Wi-Fi
   ↓
Internet

Step 5 — Build n8n Webhook

Create:

Webhook
   ↓
Receive JSON

Test it using sample JSON before connecting the physical ESP32.


Step 6 — Add validation

Check:

patient_id
latitude
longitude
heart_rate
spo2
temperature
battery
timestamp

Reject malformed data.


Step 7 — Add geofence

Configure:

Home Latitude
Home Longitude
Safe Radius

Step 8 — Add Google Sheets

Create a spreadsheet:

Timestamp
Patient ID
Latitude
Longitude
HR
SpO₂
Temperature
Battery
Geofence
Severity

Step 9 — Add ThingSpeak

Send selected sensor fields for graphical visualization.


Step 10 — Create Telegram Bot

Configure the bot and securely store its credentials.


Step 11 — Add AI Agent

Give the AI only the context it needs.

Use structured JSON output.


Step 12 — Add voice notification

Alert
 ↓
Text
 ↓
TTS
 ↓
Audio
 ↓
Telegram

Step 13 — Build dashboard

Display:

Patient
Location
Health
Battery
AI status
Alerts
History

Step 14 — Test complete system

Test:

GPS
↓
ESP32
↓
Wi-Fi
↓
n8n
↓
AI
↓
Telegram
↓
Caregiver

50. Testing Table

Test Expected result
ESP32 power-on Device boots
Wi-Fi test ESP32 connects
GPS test Valid coordinates
Heart-rate sensor Data received
SpO₂ sensor Data received
Temperature Reading received
Emergency button Emergency event generated
Geofence Zone correctly detected
n8n webhook JSON received
AI agent Structured decision
Telegram Message received
Voice alert Audio received
Google Sheets Record created
ThingSpeak Graph updated
Dashboard Current data displayed
Battery warning Low-battery alert

51. Failure Handling

A good project should also explain what happens when components fail.

GPS unavailable

GPS unavailable
      ↓
n8n receives GPS status
      ↓
Dashboard:
⚠️ GPS unavailable

Wi-Fi unavailable

ESP32 should buffer a small number of records or retry transmission.

Wi-Fi lost
   ↓
Store temporary data
   ↓
Retry
   ↓
Connection restored
   ↓
Upload

n8n unavailable

The device should not assume that data was delivered merely because it attempted transmission.

Use:

HTTPS response
   ↓
200 OK
   ↓
Transmission successful

Otherwise:

Retry with backoff

Low battery

Battery < configured warning level
       ↓
Telegram warning
       ↓
Dashboard warning

52. Cybersecurity

Because this system handles sensitive location and health-related information, security is extremely important.

Use:

  • HTTPS
  • authenticated APIs
  • secure Wi-Fi
  • unique device credentials
  • Telegram bot-token protection
  • n8n credential storage
  • restricted dashboard access
  • encrypted database where appropriate
  • minimal patient information in Telegram
  • regular credential rotation
  • audit logs

Never put:

Telegram Bot Token
Wi-Fi password
API secret
LLM API key

directly into public GitHub code.


53. Privacy Architecture

A better architecture is:

Patient ID
   │
   ▼
P001

rather than sending the patient's full name in every message.

The mapping:

P001 → Patient identity

can be kept in a protected caregiver database.


54. AI Safety

The AI should not be allowed to:

  • diagnose dementia
  • diagnose heart disease
  • prescribe medication
  • independently contact emergency services without predefined authorization
  • declare a person medically safe
  • override hardware safety conditions

It should instead perform:

Data interpretation
       +
Contextual event classification
       +
Caregiver notification
       +
Summary generation

55. Future Enhancements

The project can later be expanded with:

GSM/4G

For situations where Wi-Fi isn't available.

ESP32
 ↓
4G/GSM
 ↓
Cloud

Voice interaction

Caregiver:

"Where is the patient?"

AI:

"Patient P001 is currently within the safe zone."

Fall detection

Using:

MPU6050

Solar charging

For longer deployments.

Multiple patients

Caregiver
   │
   ├── P001
   ├── P002
   ├── P003
   └── P004

Mobile application

A dedicated Android/iOS application can replace or complement the web dashboard.


56. Advanced Agentic Architecture

For a stronger final-year project, you can describe the system as an Agentic IoT architecture:

                    ┌─────────────────┐
                    │     ESP32       │
                    │                 │
                    │ Sensing Agent   │
                    └────────┬────────┘
                             │
                             ▼
                    ┌─────────────────┐
                    │ Context Agent   │
                    │                 │
                    │ GPS + Health +  │
                    │ Device Status   │
                    └────────┬────────┘
                             │
                             ▼
                    ┌─────────────────┐
                    │ Reasoning Agent │
                    │                 │
                    │ AI + Rules      │
                    └────────┬────────┘
                             │
                             ▼
                    ┌─────────────────┐
                    │ Action Agent    │
                    │                 │
                    │ Telegram        │
                    │ Voice           │
                    │ Dashboard       │
                    └────────┬────────┘
                             │
                             ▼
                       CAREGIVER

57. Final Project Architecture

The complete project can therefore be represented as:

                       ┌───────────────────┐
                       │  DEMENTIA PATIENT │
                       └─────────┬─────────┘
                                 │
                                 ▼
              ┌─────────────────────────────────┐
              │          ESP32 WEARABLE         │
              │                                 │
              │ GPS + HR + SpO₂ + Temperature  │
              │ Motion + Emergency Button      │
              └───────────────┬─────────────────┘
                              │
                              ▼
                       Wi-Fi / Internet
                              │
                              ▼
                     ┌─────────────────┐
                     │   n8n Webhook   │
                     └────────┬────────┘
                              │
                ┌─────────────┼─────────────┐
                │             │             │
                ▼             ▼             ▼
           Validation      Geofence       Storage
                │             │             │
                └─────────────┼─────────────┘
                              ▼
                     ┌─────────────────┐
                     │    AI AGENT     │
                     │                 │
                     │ Context +       │
                     │ Reasoning       │
                     └────────┬────────┘
                              │
                    ┌─────────┼─────────┐
                    │         │         │
                    ▼         ▼         ▼
                 NORMAL    WARNING   EMERGENCY
                    │         │         │
                    │         ▼         ▼
                    │      Telegram   Telegram
                    │                  +
                    │                 Voice
                    │
                    └─────────┬────────────┐
                              │            │
                              ▼            ▼
                       Google Sheets   ThingSpeak
                              │            │
                              └─────┬──────┘
                                    ▼
                          ┌──────────────────┐
                          │  WEB DASHBOARD   │
                          └────────┬─────────┘
                                   │
                                   ▼
                              CAREGIVER

58. Expected Project Output

At the end of the project, you should be able to demonstrate:

✓ ESP32 wearable prototype
✓ GPS tracking
✓ Health sensor monitoring
✓ Emergency button
✓ Geofence
✓ Wi-Fi communication
✓ n8n automation
✓ AI agent
✓ Telegram notification
✓ Telegram voice notification
✓ Google Sheets logging
✓ ThingSpeak analytics
✓ Web dashboard
✓ Historical health data
✓ Location monitoring
✓ Battery monitoring
✓ Event detection

59. Suggested Project Folder Structure

AI-Dementia-IoT/
│
├── esp32/
│   ├── main.ino
│   ├── gps.cpp
│   ├── sensors.cpp
│   └── config.h
│
├── n8n/
│   ├── workflow.json
│   └── ai-agent-prompt.txt
│
├── dashboard/
│   ├── index.html
│   ├── style.css
│   └── app.js
│
├── documentation/
│   ├── architecture.md
│   ├── hardware.md
│   ├── software.md
│   ├── testing.md
│   └── security.md
│
├── diagrams/
│   ├── architecture.png
│   ├── flowchart.png
│   ├── schematic.png
│   └── sequence.png
│
└── README.md

60. Recommended Final-Year Report Chapters

You can turn the above into a formal report with this structure:

  1. Introduction
  2. Background
  3. Problem Statement
  4. Objectives
  5. Existing System
  6. Limitations of Existing System
  7. Proposed System
  8. System Architecture
  9. Hardware Requirements
  10. Software Requirements
  11. ESP32 Design
  12. GPS Tracking
  13. Health Monitoring
  14. Geofencing
  15. n8n Automation
  16. AI Agent Architecture
  17. Telegram Notification System
  18. Voice Alert System
  19. Google Sheets Integration
  20. ThingSpeak Integration
  21. Web Dashboard
  22. Data Flow
  23. Algorithms
  24. Flowcharts
  25. Circuit/Schematic
  26. Software Implementation
  27. Testing
  28. Results
  29. Security and Privacy
  30. Limitations
  31. Future Scope
  32. Conclusion
  33. References
  34. Appendix — Source Code

61. One-Line Project Explanation for Viva

“Our project is an AI-enabled agentic IoT system in which an ESP32 wearable collects a dementia patient's GPS location, health and movement information, n8n automates the data-processing workflow, an AI agent evaluates contextual events, and the system provides caregiver notifications through Telegram and voice alerts while maintaining historical analytics through Google Sheets, ThingSpeak and a web dashboard.”

62. Most Important Design Principle

The strongest version of this project is not simply “ESP32 sends data to Telegram.”

It is:

             SENSING
                ↓
             ESP32
                ↓
        CONTEXT COLLECTION
                ↓
          n8n AUTOMATION
                ↓
       SAFETY RULES + AI
                ↓
           DECISION
                ↓
        ┌───────┼────────┐
        ↓       ↓        ↓
     Dashboard Sheets  Telegram
                         │
                         ▼
                    Voice Alert
                         │
                         ▼
                     Caregiver

That architecture gives you a much stronger IoT + AI + Agentic Automation + Healthcare-support project than a basic GPS tracker.

Project Summary

AI-Powered GPS Tracking and Health Analytics System for Dementia Patients is an agentic IoT healthcare-support prototype built around an ESP32.

Core concept

Patient
   ↓
ESP32 Wearable
   ↓
GPS + Health + Motion Sensors
   ↓
Wi-Fi / Internet
   ↓
n8n Automation
   ↓
Safety Rules + AI Agent
   ↓
Decision
   ↓
Telegram / Voice Alert
   ↓
Caregiver

Main hardware

  • ESP32
  • NEO-6M GPS
  • MAX30102 — heart rate / SpO₂
  • DS18B20 — temperature
  • MPU6050 — movement/fall-event sensing
  • Emergency push button
  • Buzzer
  • Battery/power system

Main software

  • ESP32 Arduino firmware
  • n8n for workflow automation
  • AI Agent for contextual event analysis
  • Telegram Bot for caregiver notifications
  • Text-to-speech for Telegram voice alerts
  • Google Sheets for historical records
  • ThingSpeak for IoT graphs/analytics
  • HTML/CSS/JavaScript web dashboard

Main workflow

ESP32
 │
 ├── GPS location
 ├── Heart rate
 ├── SpO₂
 ├── Temperature
 ├── Motion
 ├── Battery
 └── Emergency button
        │
        ▼
      n8n
        │
        ├── Validate data
        ├── Calculate geofence
        ├── Apply safety rules
        ├── Invoke AI Agent
        └── Store data
             │
             ▼
       NORMAL / WARNING / EMERGENCY
             │
       ┌─────┼──────┐
       ▼     ▼      ▼
    Sheets ThingSpeak Telegram
                         │
                         ▼
                    Voice Alert
                         │
                         ▼
                     Caregiver

Key features

  • Real-time GPS tracking
  • Safe-zone/geofencing
  • Health-data monitoring
  • Emergency-button detection
  • Battery monitoring
  • AI-assisted event classification
  • Automated n8n workflows
  • Telegram text notifications
  • Telegram voice alerts
  • Google Sheets logging
  • ThingSpeak visualization
  • Web-based caregiver dashboard
  • Historical health/location analytics

Agentic AI concept

The system follows:

Sense → Understand → Reason → Decide → Act → Verify

The AI should provide caregiver-support and event classification, not medical diagnosis. Critical safety conditions should be handled by deterministic rules rather than relying exclusively on an LLM.

Example emergency flow

Patient presses emergency button
        ↓
ESP32 detects event
        ↓
n8n receives event
        ↓
Safety rule immediately marks EMERGENCY
        ↓
Telegram text alert
        +
Text-to-speech
        ↓
Telegram voice alert
        ↓
Caregiver receives notification
        ↓
Event saved to Google Sheets
        ↓
Dashboard updated

Final deliverables

The complete project documentation should contain:

  1. Abstract
  2. Introduction and problem statement
  3. Objectives
  4. Existing/proposed system
  5. System architecture
  6. Hardware description
  7. Circuit/schematic
  8. ESP32 firmware
  9. GPS implementation
  10. Health-sensor implementation
  11. Geofencing algorithm
  12. n8n workflow
  13. AI-agent prompt and logic
  14. Telegram bot/voice-alert system
  15. Google Sheets integration
  16. ThingSpeak integration
  17. Web dashboard
  18. Flowcharts and sequence diagrams
  19. Testing and results
  20. Security/privacy
  21. Limitations
  22. Future scope
  23. Conclusion
  24. Complete source code and appendices

In one sentence: this project turns an ESP32 wearable into an AI-assisted dementia-care IoT device that tracks location and sensor data, intelligently detects important events, and automatically communicates actionable alerts to caregivers.

No comments:

Post a Comment