Saturday, 30 May 2026

AI Smart Baby Monitoring System with Cry and Motion Detection

AI Smart Baby Monitoring System with Cry and Motion Detection AI-Powered ESP32 + Agentic IoT + n8n Automation + Telegram Voice Alerts + Google Sheets + ThingSpeak Cloud Dashboard
AI Smart Baby Monitoring System with Cry and Motion Detection AI-Powered ESP32 + Agentic IoT + n8n Automation + Telegram Voice Alerts + Google Sheets + ThingSpeak Cloud Dashboard 1. Project Overview This project is an intelligent baby monitoring system that continuously monitors: Baby crying sounds Baby movement/motion Room temperature and humidity Activity patterns The system uses: ESP32 for edge sensing AI logic for event detection and prediction n8n for workflow automation Telegram Bot for instant voice alerts Google Sheets for data logging ThingSpeak for IoT dashboard visualization AI Agent for decision making and prediction 2. Objectives The system should: ✅ Detect baby crying ✅ Detect baby movement ✅ Send Telegram notifications ✅ Generate voice alerts ✅ Store historical data ✅ Visualize data on dashboard ✅ Predict high-activity periods ✅ Provide remote monitoring 3. System Architecture +------------------+ | Baby Room | +------------------+ | -------------------------------- | | Sound Sensor PIR Sensor (Cry Detection) (Motion Detection) | | ---------- ESP32 -------------- | | WiFi Internet | ----------------------------------- | | | | ThingSpeak n8n Server Google Sheet AI Agent | | | | ----------------------------------- | Telegram Bot | Voice Notification | Parent 4. Components List Main Controller Component Quantity ESP32 Dev Board 1 Sensors Component Quantity KY-038 Sound Sensor 1 PIR Motion Sensor HC-SR501 1 DHT22 Temperature Sensor 1 Output Devices Component Quantity LED Indicator 1 Buzzer 1 Communication Component Quantity WiFi Router 1 Software Arduino IDE n8n Telegram Bot Google Sheets ThingSpeak OpenAI API (optional AI agent) Google TTS API 5. Working Principle Cry Detection Sound sensor measures sound intensity. Sound > Threshold If: Sound Level > 2000 then: Baby Cry Event generated. Motion Detection PIR sensor detects movement. Motion = HIGH means baby movement detected. AI Decision Layer If: Cry + Motion occur together: Severity = HIGH If: Cry only Severity = MEDIUM If: Motion only Severity = LOW 6. Circuit Schematic Diagram ESP32 -------------------- GPIO34 <-- Sound Sensor AO GPIO27 <-- PIR OUT GPIO4 <-- DHT22 DATA GPIO2 --> LED GPIO15 --> Buzzer 3.3V --> DHT22 VCC 5V --> PIR VCC GND --> All GND 7. Pin Configuration ESP32 Pin Device GPIO34 Sound Sensor GPIO27 PIR Sensor GPIO4 DHT22 GPIO2 LED GPIO15 Buzzer 8. Flowchart START | Initialize ESP32 | Connect WiFi | Read Sensors | +----------------+ | Cry Detected ? | +----------------+ | YES | Send Alert | +------------------+ | Motion Detected? | +------------------+ | YES | High Priority Alert | Upload Data | Store in Sheet | Update Dashboard | AI Prediction | Repeat 9. ESP32 Source Code #include #include #include #define SOUND_PIN 34 #define PIR_PIN 27 #define DHTPIN 4 #define DHTTYPE DHT22 #define LED_PIN 2 #define BUZZER_PIN 15 const char* ssid = "YOUR_WIFI"; const char* password = "YOUR_PASSWORD"; String webhookURL = "https://your-n8n-server/webhook/baby-monitor"; DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(115200); pinMode(PIR_PIN, INPUT); pinMode(LED_PIN, OUTPUT); pinMode(BUZZER_PIN, OUTPUT); WiFi.begin(ssid,password); while(WiFi.status()!=WL_CONNECTED) { delay(500); } dht.begin(); } void loop() { int soundLevel = analogRead(SOUND_PIN); int motion = digitalRead(PIR_PIN); float temp = dht.readTemperature(); float hum = dht.readHumidity(); String eventType="NORMAL"; if(soundLevel > 2000) { eventType="CRY"; } if(motion==HIGH) { eventType="MOTION"; } if(soundLevel > 2000 && motion==HIGH) { eventType="CRY_MOTION"; } if(eventType!="NORMAL") { digitalWrite(LED_PIN,HIGH); tone(BUZZER_PIN,1000); sendData(eventType,soundLevel,motion,temp,hum); delay(5000); } digitalWrite(LED_PIN,LOW); delay(1000); } void sendData(String eventType, int sound, int motion, float temp, float hum) { if(WiFi.status()==WL_CONNECTED) { HTTPClient http; http.begin(webhookURL); http.addHeader( "Content-Type", "application/json"); String payload = "{"; payload += "\"event\":\""+eventType+"\","; payload += "\"sound\":"+String(sound)+","; payload += "\"motion\":"+String(motion)+","; payload += "\"temp\":"+String(temp)+","; payload += "\"humidity\":"+String(hum); payload += "}"; http.POST(payload); http.end(); } } 10. Telegram Bot Setup Step 1 Open Telegram Search: @BotFather Create Bot: /newbot Example: BabyMonitorBot Get: BOT TOKEN Save token. Step 2 Get Chat ID Send message to bot. Visit: https://api.telegram.org/botTOKEN/getUpdates Copy: chat_id 11. n8n Workflow Design Workflow: Webhook | Function | IF Node | Telegram | Google Sheets | ThingSpeak | AI Agent 12. n8n Step-by-Step Node 1: Webhook Method: POST Path: baby-monitor Receives ESP32 data. Node 2: Function Node return [{ json:{ event:$json.event, severity: $json.event=="CRY_MOTION"? "HIGH": "MEDIUM" } }] Node 3: IF Node Condition: severity = HIGH Node 4: Telegram Node Message: 🚨 Baby Crying and Moving! Immediate attention required. 13. Voice Notification Automation Method 1 Google Text-To-Speech API Generate: Attention. Baby is crying and moving. Please check immediately. MP3 generated. n8n Telegram Send Audio Node: Telegram → Send Audio Audio File: generated_voice.mp3 Parent receives voice alert. 14. Google Sheets Integration Create Sheet: Baby Monitoring Logs Columns: | Timestamp | | Event | | Sound | | Motion | | Temp | | Humidity | | Severity | Google Sheets Node Operation: Append Row Mapping: Date Event Sound Motion Temp Humidity Severity 15. ThingSpeak Setup Create account: ThingSpeak Official Website Create Channel Fields: Field1 = Sound Field2 = Motion Field3 = Temperature Field4 = Humidity Get: WRITE API KEY Upload Example https://api.thingspeak.com/update? api_key=XXXX &field1=1500 &field2=1 &field3=30 &field4=60 16. AI Power Consumption Prediction Logic Purpose: Estimate future power usage. Features: Sensor Activity Count WiFi Usage Alert Frequency Operating Hours Dataset Example Activity Alerts Power 10 2 0.5Wh 50 10 1.2Wh 100 20 2.5Wh AI Formula Linear Regression: y=a+bx a b Where: y = Predicted Power x = Activity Count Prediction Example: Current Activity = 80 Predicted: 2.0 Wh 17. AI Agentic Layer The AI agent receives: { "event":"CRY_MOTION", "sound":2450, "motion":1, "temp":31, "humidity":58 } AI analyzes: Severity Frequency Trend Repeated crying pattern Response: Baby has cried 5 times in the last hour. Activity level is increasing. Recommend immediate check. 18. Advanced AI Features Pattern Analysis Detect: Frequent Crying Night Disturbances Abnormal Activity Predictive Alerts Example: Baby usually cries around 2 AM. AI sends early warning. Anomaly Detection If: No motion for long time or Continuous crying Generate emergency notification. 19. Complete n8n Workflow JSON Structure { "nodes":[ { "name":"Webhook" }, { "name":"Function" }, { "name":"Telegram" }, { "name":"GoogleSheets" }, { "name":"ThingSpeak" } ] } In a real deployment, export the workflow from n8n after configuring credentials and node IDs. 20. Testing Procedure Test 1 Clap near microphone. Expected: Cry Alert Test 2 Move in front of PIR. Expected: Motion Alert Test 3 Cry + Motion Expected: High Priority Alert Voice Notification 21. Future Enhancements Computer Vision Add: ESP32-CAM Face Detection Sleep Monitoring Edge AI Use: TinyML TensorFlow Lite Micro For actual cry classification instead of simple sound threshold detection. Health Monitoring Add: Heart rate sensor Oxygen sensor Breathing sensor Mobile App Develop: Flutter App Android App iOS App 22. Deployment Guide Hardware Deployment Mount sensors near crib (not within baby's reach). Place microphone 1–2 meters away. Install PIR sensor with full crib coverage. Use a stable 5V/2A power supply. Connect ESP32 to a reliable Wi-Fi network. Software Deployment Upload ESP32 firmware. Configure Telegram Bot token. Configure n8n webhook URL. Connect Google Sheets credentials. Configure ThingSpeak API key. Test all alert paths. Enable automatic backups of logs. 23. Expected Outputs Telegram Alert 🚨 HIGH PRIORITY Baby Crying Detected Motion Detected Temperature: 30°C Humidity: 60% Please check immediately. Voice Alert Attention. Baby is crying and moving. Please check the baby immediately. Dashboard Live sound level graph Motion activity graph Temperature trend Humidity trend Alert history AI prediction chart 24. Project Outcomes This solution combines: ESP32 IoT Edge Computing Cry Detection Motion Detection Agentic AI Decision Making n8n Automation Telegram Voice Notifications Google Sheets Logging ThingSpeak Analytics Predictive AI Monitoring The result is a low-cost, scalable, cloud-connected smart baby monitoring platform suitable for homes, daycare centers, hospitals, and research environments.

No comments:

Post a Comment

AI Smart Refrigerator Monitoring and Food Expiry Detection

AI Smart Refrigerator Monitoring & Food Expiry Detection System ESP32 + Agentic AI + n8n Automation + Telegram Voice Alerts + Google She...