Agentic AI Distance Analytics and Automated Data Logging System with Cloud Intelligence

www.svsembedded.com SVSEMBEDDED svsembedded@gmail.com, CONTACT: 9491535690, 7842358459
<?php echo $title; ?>

1. Project Overview

This project creates an AI-powered IoT monitoring platform using ESP32, HC-SR04 Ultrasonic Sensor, ThingSpeak Cloud, Google Sheets, Telegram Voice Notifications and n8n Automation.

  • Distance Measurement
  • Cloud Data Logging
  • AI Prediction Engine
  • Telegram Voice Alerts
  • Google Sheets Integration
  • ThingSpeak Dashboard

2. Components Required

Component Quantity
ESP32 Dev Board1
HC-SR04 Sensor1
Jumper WiresSeveral
Breadboard1
USB Cable1
WiFi Router1

3. Circuit Connections

HC-SR04 ESP32
VCC5V
GNDGND
TRIGGPIO5
ECHOGPIO18

4. Flowchart

START
  |
Initialize WiFi
  |
Read Distance
  |
Send to ThingSpeak
  |
Trigger n8n Webhook
  |
Store in Google Sheets
  |
AI Analysis
  |
Threshold Check
  |
Telegram Voice Alert
  |
Repeat

5. ESP32 Source Code

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

const char* ssid="YOUR_WIFI";
const char* password="YOUR_PASSWORD";

String apiKey="YOUR_THINGSPEAK_KEY";

#define TRIG 5
#define ECHO 18

void setup()
{
  Serial.begin(115200);

  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);

  WiFi.begin(ssid,password);

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

float getDistance()
{
  digitalWrite(TRIG,LOW);
  delayMicroseconds(2);

  digitalWrite(TRIG,HIGH);
  delayMicroseconds(10);

  digitalWrite(TRIG,LOW);

  long duration=pulseIn(ECHO,HIGH);

  return duration*0.034/2;
}

void loop()
{
  float distance=getDistance();

  HTTPClient http;

  String url =
  "https://api.thingspeak.com/update?api_key="
  + apiKey +
  "&field1=" + String(distance);

  http.begin(url);
  http.GET();
  http.end();

  delay(15000);
}

6. ThingSpeak Setup

  1. Create ThingSpeak Account
  2. Create New Channel
  3. Add Fields:
    • Distance
    • Prediction
    • Alert Status
  4. Copy Write API Key

7. Telegram Bot Setup

  1. Open Telegram
  2. Search BotFather
  3. Create New Bot
  4. Copy Bot Token
  5. Get Chat ID

8. Google Sheets Structure

Timestamp Distance Prediction Alert

9. n8n Workflow

Webhook
   |
Code Node
   |
Google Sheets
   |
IF Condition
   |
Telegram Alert

10. AI Prediction Logic

const current = $json.distance;

const prediction =
current + Math.random()*5;

return [{
  distance: current,
  prediction: prediction
}];

11. Telegram Voice Alert Logic

Distance Alert
      |
Generate TTS Audio
      |
Telegram Send Audio

Example Voice Message:

Warning.
Object detected at eight centimeters.
Please check immediately.

12. Power Consumption Prediction

Mode Current
WiFi Active 180mA
Processing 120mA
Deep Sleep 10µA
Battery Life =
Battery Capacity / Average Current

13. Future Enhancements

  • Multi-Sensor Integration
  • Temperature Monitoring
  • Humidity Monitoring
  • Gas Detection
  • ESP32 Camera AI Vision
  • Digital Twin Dashboard
  • Edge AI Inference

14. Deployment Architecture

ESP32
 ↓
ThingSpeak
 ↓
n8n
 ↓
Google Sheets
 ↓
Telegram

15. Expected Output

Distance = 24.6 cm

Prediction = 25.1 cm

Status = NORMAL
This PHP file can be saved as index.php, hosted on a PHP server (XAMPP, WAMP, LAMP, or Apache), and viewed as a complete project documentation webpage. For a professional final-year project, you can further split it into: index.php (dashboard) components.php circuit.php esp32_code.php n8n_workflow.php thingspeak_setup.php telegram_setup.php deployment_guide.php with Bootstrap styling, navigation menus, downloadable source code sections, and an admin dashboard layout.

Comments