Monday, 28 September 2026

AI Smart Cradle with Baby Cry Detection & Sleep Analysis

Below is a complete reference design you can use as a final-year/academic IoT project, prototype, GitHub README, or implementation document. It combines ESP32, microphone-based baby-cry detection, sleep/activity analysis, n8n automation, an AI agent, Telegram voice alerts, Google Sheets, ThingSpeak, and a web dashboard.

AI Smart Cradle with Baby Cry Detection & Sleep Analysis

1. Project Overview

The AI Smart Cradle is an IoT-enabled intelligent baby-monitoring and automated cradle system designed to detect baby crying, monitor environmental conditions and cradle movement, estimate sleep/activity states, and automatically notify a parent or caregiver.

The system uses an ESP32 as the edge controller. Sensors collect information such as sound level, temperature, humidity, motion and cradle movement. A lightweight AI/ML model can classify audio into categories such as:

  • Baby crying

  • Baby vocalization

  • Normal/background sound

  • Other/noise

The ESP32 sends important events to an n8n automation server. n8n acts as the central workflow/orchestration layer and can:

  1. Receive sensor data from ESP32.

  2. Determine whether an event requires attention.

  3. Store measurements in Google Sheets.

  4. Send data to ThingSpeak.

  5. Invoke an AI agent for event interpretation.

  6. Send Telegram notifications.

  7. Generate or deliver a voice alert.

  8. Maintain an event history.

  9. Control the cradle according to predefined safety rules.

The system is designed as a monitoring and assistance system, not as a replacement for parental supervision or medical monitoring.


2. Main Objectives

The project has the following objectives:

Hardware objectives

  • Monitor baby crying.

  • Monitor temperature and humidity.

  • Detect cradle movement.

  • Detect whether the baby/cradle is moving.

  • Provide local indication using LEDs/buzzer/display.

  • Provide optional automatic rocking.

AI objectives

  • Detect crying from microphone/audio features.

  • Distinguish crying from ordinary environmental noise.

  • Estimate sleep/activity state using sensor history.

  • Detect repeated crying events.

  • Provide an AI-generated event summary.

IoT objectives

  • Connect ESP32 to Wi-Fi.

  • Send telemetry to the cloud.

  • Maintain historical data.

  • Provide a web dashboard.

  • Integrate ThingSpeak.

Automation objectives

  • Use n8n as the workflow engine.

  • Trigger notifications automatically.

  • Store events in Google Sheets.

  • Send Telegram alerts.

  • Generate voice notifications.

  • Provide an AI-agent interface.


3. High-Level Architecture

                    ┌─────────────────────────┐
                    │       BABY / CRADLE     │
                    └────────────┬────────────┘
                                 │
              ┌──────────────────┼──────────────────┐
              │                  │                  │
              ▼                  ▼                  ▼
        Microphone          Temperature        Motion/
        / Audio Sensor      & Humidity         Vibration
              │                  │                  │
              └──────────────────┼──────────────────┘
                                 ▼
                    ┌─────────────────────────┐
                    │          ESP32          │
                    │                         │
                    │ Sensor acquisition      │
                    │ Edge processing          │
                    │ Cry detection           │
                    │ Sleep/activity logic    │
                    │ Wi-Fi communication     │
                    └────────────┬────────────┘
                                 │
                         Wi-Fi / HTTP / MQTT
                                 │
                                 ▼
                    ┌─────────────────────────┐
                    │          n8n             │
                    │    Automation Server     │
                    │                         │
                    │ Webhook                 │
                    │ Rules                   │
                    │ AI Agent                │
                    │ Notifications           │
                    │ Data processing         │
                    └──────┬───────┬──────────┘
                           │       │
             ┌─────────────┘       └──────────────┐
             ▼                                    ▼
      ┌──────────────┐                    ┌──────────────┐
      │ Google Sheets│                    │  ThingSpeak  │
      │ Event Log    │                    │ IoT Charts   │
      └──────────────┘                    └──────────────┘
                           │
                           ▼
                    ┌───────────────┐
                    │ AI Agent      │
                    │ Event analysis│
                    └───────┬───────┘
                            │
                            ▼
                    ┌───────────────┐
                    │   Telegram    │
                    │ Text + Voice  │
                    │ Notifications │
                    └───────────────┘

4. Complete System Flow

START
  │
  ▼
ESP32 boots
  │
  ▼
Connect to Wi-Fi
  │
  ▼
Initialize sensors
  │
  ▼
Read microphone/audio
  │
  ├───────────────► Extract audio features
  │                         │
  │                         ▼
  │                   Cry classifier
  │                         │
  │                         ▼
  │                  Cry probability
  │
  ├───────────────► Temperature/Humidity
  │
  ├───────────────► Motion/Vibration
  │
  ▼
Combine sensor information
  │
  ▼
Calculate current state
  │
  ├── Normal
  ├── Sleeping
  ├── Moving
  ├── Possible crying
  └── Repeated crying
  │
  ▼
Send JSON to n8n
  │
  ▼
n8n Webhook
  │
  ▼
Validate data
  │
  ├──► Google Sheets
  │
  ├──► ThingSpeak
  │
  └──► AI Agent
           │
           ▼
      Analyze event
           │
           ▼
     Is alert required?
       /           \
     NO             YES
     │               │
     ▼               ▼
   Log only      Telegram message
                     │
                     ▼
                 Voice alert
                     │
                     ▼
                  Parent

5. Hardware Components

Required components

Component Purpose
ESP32 DevKit Main controller
Microphone/audio sensor Baby-cry detection
DHT22/SHT31 Temperature/humidity
MPU6050 Motion/tilt detection
Vibration sensor Cradle vibration/activity
OLED display Local status
LED Status indication
Buzzer Local warning
5V power supply System power
Optional motor Automatic rocking
Motor driver Motor control
Wi-Fi router Internet connectivity

For an improved audio system, an I2S MEMS microphone is preferable to a basic analog sound sensor because it provides actual audio samples suitable for feature extraction and ML classification.


6. Suggested ESP32 Hardware Architecture

                    ESP32
              ┌────────────────┐
              │                │
 I2S Mic ────►│ I2S            │
              │                │
 DHT22 ──────►│ GPIO           │
              │                │
 MPU6050 ────►│ I2C            │
              │                │
 OLED ───────►│ I2C            │
              │                │
 Vibration ──►│ GPIO           │
              │                │
 LED ◄────────│ GPIO           │
              │                │
 Buzzer ◄─────│ GPIO           │
              │                │
 Motor Driver◄│ PWM/GPIO       │
              │                │
 Wi-Fi ◄─────►│ Wi-Fi          │
              └────────────────┘

7. Example Pin Configuration

A possible ESP32 configuration is:

Device ESP32 pin
DHT22 DATA GPIO 4
MPU6050 SDA GPIO 21
MPU6050 SCL GPIO 22
Vibration sensor GPIO 27
Status LED GPIO 2
Buzzer GPIO 26
Motor driver IN1 GPIO 18
Motor driver IN2 GPIO 19
OLED SDA GPIO 21
OLED SCL GPIO 22

For an I2S microphone, choose the I2S pins according to the microphone module and firmware configuration.

Important: Do not connect a cradle motor directly to an ESP32 GPIO. Use an appropriate motor driver, separate motor power supply, flyback protection where applicable, and suitable mechanical safety limits.


8. Electrical Block Diagram

                  5V POWER SUPPLY
                        │
             ┌──────────┴──────────┐
             │                     │
             ▼                     ▼
          ESP32                 Motor Driver
             │                     │
       ┌─────┼──────┐              ▼
       │     │      │            Motor
       │     │      │
       ▼     ▼      ▼
     DHT22 MPU6050 Microphone
       │     │      │
       │     │      └──── Audio
       │     │
       │     └──── Motion
       │
       └──────── Temperature

9. Baby Cry Detection

The microphone continuously samples the surrounding sound.

A basic system can calculate:

  • RMS energy

  • Zero-crossing rate

  • Spectral centroid

  • Spectral bandwidth

  • Mel-frequency features

  • MFCC features

A machine-learning model can then classify an audio window.

Example:

Audio
  │
  ▼
Sampling
  │
  ▼
Noise filtering
  │
  ▼
Audio window
  │
  ▼
Feature extraction
  │
  ├── RMS
  ├── ZCR
  ├── MFCC
  └── Spectral features
  │
  ▼
ML classifier
  │
  ▼
Probability
  │
  ├── Cry = 0.91
  ├── Normal = 0.06
  └── Noise = 0.03
  │
  ▼
Cry detected

A threshold such as 0.80 can be used in a prototype, but it should be determined experimentally from a properly collected and labelled dataset rather than assumed to be universally accurate.


10. AI Model

A practical architecture is:

Microphone
     │
     ▼
Audio preprocessing
     │
     ▼
MFCC / Mel spectrogram
     │
     ▼
Small neural network
     │
     ▼
Classification
     │
 ┌───┼─────────────┐
 ▼   ▼             ▼
Cry  Vocalization  Noise

Possible model approaches include:

  • TensorFlow Lite Micro

  • Edge Impulse

  • Custom small neural network

  • Logistic regression/SVM for a simpler prototype

For an ESP32, the model should be kept small enough for available RAM/flash and inference time.


11. Sleep Analysis

The system should describe sleep as an estimated state, not medically diagnose sleep.

For example:

Sensor history
     │
     ├── Sound level
     ├── Cry events
     ├── Movement
     ├── Cradle activity
     └── Time
           │
           ▼
     Feature aggregation
           │
           ▼
     Sleep-state algorithm
           │
     ┌─────┼─────────────┐
     ▼     ▼             ▼
  Quiet  Light activity  Active
  sleep

Example state logic:

If movement is low
AND cry probability is low
AND sound level is low
for a continuous interval:

    estimated_state = "QUIET_SLEEP"

If movement increases:

    estimated_state = "ACTIVE"

If repeated high cry probability occurs:

    estimated_state = "CRYING"

The algorithm should use time windows rather than making a sleep-state decision from one sensor reading.


12. Example JSON Sent from ESP32

{
  "device_id": "SMART_CRADLE_01",
  "timestamp": 1750000000,
  "temperature": 27.4,
  "humidity": 61.2,
  "motion": 0.18,
  "sound_level": 54,
  "cry_probability": 0.91,
  "cry_detected": true,
  "sleep_state": "CRYING",
  "battery": 87
}

This JSON becomes the primary data structure passed to n8n.


13. n8n Architecture

n8n is the central automation layer.

ESP32
  │
  │ HTTP POST
  ▼
Webhook
  │
  ▼
Validate JSON
  │
  ▼
Normalize data
  │
  ├───────────────┐
  │               │
  ▼               ▼
Google Sheets   ThingSpeak
  │
  ▼
Decision/Routing
  │
  ▼
AI Agent
  │
  ▼
Alert decision
  │
  ▼
Telegram
  │
  ▼
Voice notification

14. n8n Workflow

Recommended nodes:

  1. Webhook

  2. Code / Set

  3. IF

  4. Google Sheets

  5. HTTP Request – ThingSpeak

  6. AI Agent

  7. Telegram

  8. HTTP Request/TTS service

  9. Telegram voice/audio

  10. Response

Example:

[Webhook]
     |
     v
[Validate JSON]
     |
     v
[Store Event]
     |
     +------> [Google Sheets]
     |
     +------> [ThingSpeak]
     |
     v
[IF Cry Probability > Threshold]
     |
   YES
     |
     v
[AI Agent]
     |
     v
[Generate Alert]
     |
     v
[Telegram Text]
     |
     v
[Text-to-Speech]
     |
     v
[Telegram Voice]

15. AI Agent

The AI agent should not directly make unrestricted hardware decisions.

A safer architecture is:

ESP32
  │
  ▼
n8n validation
  │
  ▼
Rule engine
  │
  ▼
AI Agent
  │
  ▼
Structured response
  │
  ▼
Allowed action list

Example AI input:

Temperature: 27.4 C
Humidity: 61%
Cry probability: 0.91
Motion: low
Cry duration: 18 seconds
Previous cry events: 3

Example structured response:

{
  "event": "possible_baby_cry",
  "priority": "high",
  "message": "Possible baby crying detected for approximately 18 seconds.",
  "recommended_action": "check_baby"
}

The AI agent should be prevented from issuing unsafe commands such as uncontrolled motor operation.


16. Telegram Alert

Example text alert:

🚨 Smart Cradle Alert

Possible baby crying detected.

Cry probability: 91%
Temperature: 27.4°C
Humidity: 61%
Movement: Low
Estimated state: Crying

Please check the baby.

The voice notification can communicate the same information in a concise form.

Example:

"Smart Cradle alert. Possible baby crying has been detected. Please check the baby."

17. Telegram Conversation

A useful Telegram interface can support commands such as:

Parent:
 /status

Smart Cradle:
 Temperature: 27.4°C
 Humidity: 61%
 State: Quiet Sleep
 Cry probability: 4%
 Last event: 12 minutes ago

Another example:

Parent:
 /today

Smart Cradle:
 Today's summary:

 Cry events: 7
 Estimated quiet periods: 5
 Movement events: 14
 Average temperature: 27.1°C
 Average humidity: 60.4%

AI-agent interaction:

Parent:
 Why did I receive the last alert?

AI Agent:
 The system detected a high cry probability for approximately
 18 seconds and generated an alert because the event exceeded
 the configured threshold.

18. Google Sheets Database

Create columns such as:

Timestamp Device Temperature Humidity Motion Cry Probability Cry Sleep State Alert
21:10 CRADLE01 27.2 60 0.1 0.03 No Sleep No
21:20 CRADLE01 27.3 61 0.2 0.91 Yes Crying Yes

Google Sheets is useful for:

  • Prototype logging

  • Project demonstrations

  • Data analysis

  • Generating graphs

  • Training-data collection

  • Event history

For a production-scale system, a proper time-series/database backend would generally be more appropriate.


19. ThingSpeak

ThingSpeak can be used for time-series visualization.

Possible fields:

Field 1 = Temperature
Field 2 = Humidity
Field 3 = Motion
Field 4 = Sound Level
Field 5 = Cry Probability
Field 6 = Sleep State

Example :

ESP32
  │
  ▼
n8n
  │
  ▼
HTTP Request
  │
  ▼
ThingSpeak
  │
  ▼
Charts

20. IoT Web Dashboard

The webpage can contain:

┌───────────────────────────────────────────────┐
│              AI SMART CRADLE                 │
├───────────────────────────────────────────────┤
│ Temperature       Humidity        Baby State │
│   27.4 °C           61 %           SLEEPING  │
├───────────────────────────────────────────────┤
│ Cry Probability                              │
│ ███████████░░░░░░░░  42%                    │
├───────────────────────────────────────────────┤
│              LIVE SENSOR DATA                │
│ Temperature  ────────────────                │
│ Humidity     ────────────────                │
│ Cry level    ────────────────                │
│ Movement     ────────────────                │
├───────────────────────────────────────────────┤
│ Recent Events                                │
│ 21:15 Cry detected                           │
│ 21:08 Quiet sleep                            │
│ 20:55 Movement detected                      │
└───────────────────────────────────────────────┘

The webpage can obtain data through:

ESP32 → n8n → Database/API → Webpage

or:

ESP32 → ThingSpeak → Webpage

21. ESP32 Firmware

The ESP32 firmware has five major responsibilities:

setup()
  │
  ├── Wi-Fi
  ├── sensors
  ├── display
  └── audio
       │
       ▼
loop()
  │
  ├── Read sensors
  ├── Process audio
  ├── Determine state
  ├── Send telemetry
  └── Wait

A minimal ESP32 telemetry prototype can be implemented as follows.

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

#define DHT_PIN 4
#define DHT_TYPE DHT22

#define MOTION_PIN 27
#define LED_PIN 2

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

const char* N8N_WEBHOOK =
  "https://YOUR_N8N_SERVER/webhook/smart-cradle";

DHT dht(DHT_PIN, DHT_TYPE);

unsigned long lastSend = 0;
const unsigned long SEND_INTERVAL = 10000;

float estimateCryProbability()
{
    /*
       Replace this function with the actual ML model.

       This placeholder demonstrates the software architecture.
    */

    int motion = digitalRead(MOTION_PIN);

    if (motion == HIGH)
        return 0.05;

    return 0.02;
}

String determineSleepState(float cryProbability, int motion)
{
    if (cryProbability > 0.80)
        return "CRYING";

    if (motion == HIGH)
        return "ACTIVE";

    return "QUIET_SLEEP";
}

void sendTelemetry()
{
    float temperature = dht.readTemperature();
    float humidity = dht.readHumidity();

    if (isnan(temperature) || isnan(humidity))
        return;

    int motion = digitalRead(MOTION_PIN);

    float cryProbability = estimateCryProbability();

    bool cryDetected = cryProbability >= 0.80;

    String sleepState =
        determineSleepState(cryProbability, motion);

    String json = "{";
    json += "\"device_id\":\"SMART_CRADLE_01\",";
    json += "\"temperature\":" + String(temperature, 2) + ",";
    json += "\"humidity\":" + String(humidity, 2) + ",";
    json += "\"motion\":" + String(motion) + ",";
    json += "\"cry_probability\":" +
            String(cryProbability, 3) + ",";
    json += "\"cry_detected\":" +
            String(cryDetected ? "true" : "false") + ",";
    json += "\"sleep_state\":\"" + sleepState + "\"";
    json += "}";

    HTTPClient http;

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

    int responseCode = http.POST(json);

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

    http.end();
}

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

    pinMode(MOTION_PIN, INPUT);
    pinMode(LED_PIN, OUTPUT);

    dht.begin();

    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

    Serial.print("Connecting to Wi-Fi");

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

    Serial.println();
    Serial.println("Wi-Fi connected");
    Serial.println(WiFi.localIP());
}

void loop()
{
    if (millis() - lastSend >= SEND_INTERVAL)
    {
        lastSend = millis();

        sendTelemetry();
    }
}

This is the IoT communication prototype. The estimateCryProbability() function must be replaced by an actual trained audio classifier for genuine AI-based cry detection.


22. n8n Webhook Input

The webhook receives:

{
  "device_id": "SMART_CRADLE_01",
  "temperature": 27.4,
  "humidity": 61.2,
  "motion": 0,
  "cry_probability": 0.91,
  "cry_detected": true,
  "sleep_state": "CRYING"
}

A Code node can normalize the information:

const data = $json;

const cryProbability =
    Number(data.cry_probability || 0);

const alertRequired =
    data.cry_detected === true &&
    cryProbability >= 0.80;

return [{
  json: {
    ...data,
    alert_required: alertRequired,
    received_at: new Date().toISOString()
  }
}];

23. n8n Decision Logic

cry_probability >= 0.80?
          │
      ┌───┴───┐
      │       │
     YES      NO
      │       │
      ▼       ▼
  Check      Log only
  duration
      │
      ▼
Repeated event?
   │       │
  YES      NO
   │        │
   ▼        ▼
Alert      Log

A duration requirement is useful because it can reduce false alerts caused by a short sound.


24. Example n8n AI-Agent Prompt

You are the event-analysis component of an AI smart cradle.

Analyze the supplied sensor event.

You must:
1. Describe the event using only the supplied data.
2. Never claim that the system has medically diagnosed the baby.
3. Never claim certainty when the classifier only provides a probability.
4. Recommend that a caregiver check the baby when a sustained high-probability
   crying event is detected.
5. Return concise structured JSON.

Input:

Temperature: {{$json.temperature}}
Humidity: {{$json.humidity}}
Motion: {{$json.motion}}
Cry probability: {{$json.cry_probability}}
Cry detected: {{$json.cry_detected}}
Sleep state: {{$json.sleep_state}}

Return:

{
  "event": "...",
  "priority": "...",
  "message": "...",
  "recommended_action": "..."
}

25. Telegram Bot Integration

The Telegram workflow can be:

n8n
 │
 ▼
Telegram node
 │
 ├── Text message
 │
 └── Voice/audio message

Example alert:

🚨 AI SMART CRADLE

Possible crying detected.

Cry probability: 91%
Duration: 18 seconds
Temperature: 27.4°C
Humidity: 61%

Please check the baby.

26. Voice Alert Pipeline

AI Agent
   │
   ▼
Alert text
   │
   ▼
Text-to-Speech
   │
   ▼
Audio file
   │
   ▼
Telegram
   │
   ▼
Parent's phone

The TTS provider can be selected according to project requirements. The n8n workflow only needs an HTTP/API step between the generated text and Telegram.


27. Web Dashboard API

A simple backend endpoint can return:

{
  "temperature": 27.4,
  "humidity": 61.2,
  "cry_probability": 0.04,
  "sleep_state": "QUIET_SLEEP",
  "last_alert": "2026-09-28T20:52:00",
  "device_status": "ONLINE"
}

The webpage can periodically request this endpoint.

Example JavaScript:

async function updateDashboard() {
    const response = await fetch("/api/status");
    const data = await response.json();

    document.getElementById("temperature").textContent =
        data.temperature + " °C";

    document.getElementById("humidity").textContent =
        data.humidity + " %";

    document.getElementById("state").textContent =
        data.sleep_state;

    document.getElementById("cry").textContent =
        Math.round(data.cry_probability * 100) + "%";
}

setInterval(updateDashboard, 5000);

updateDashboard();

28. Example HTML Dashboard

<!DOCTYPE html>
<html>
<head>
    <title>AI Smart Cradle</title>

    <style>
        body {
            font-family: Arial, sans-serif;
            background: #eef4ff;
            margin: 0;
            padding: 30px;
        }

        h1 {
            color: #183153;
        }

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

        .card {
            background: white;
            padding: 25px;
            border-radius: 15px;
            box-shadow: 0 4px 15px #0002;
        }

        .value {
            font-size: 32px;
            font-weight: bold;
            color: #2463eb;
        }
    </style>
</head>

<body>

<h1>AI Smart Cradle</h1>

<div class="grid">

    <div class="card">
        <h3>Temperature</h3>
        <div class="value" id="temperature">--</div>
    </div>

    <div class="card">
        <h3>Humidity</h3>
        <div class="value" id="humidity">--</div>
    </div>

    <div class="card">
        <h3>Cry Probability</h3>
        <div class="value" id="cry">--</div>
    </div>

    <div class="card">
        <h3>Baby State</h3>
        <div class="value" id="state">--</div>
    </div>

</div>

<script src="dashboard.js"></script>

</body>
</html>

29. Complete Data Flow

                 ┌──────────────┐
                 │  Microphone  │
                 └──────┬───────┘
                        │
                        ▼
                 ┌──────────────┐
                 │    ESP32     │
                 │ Edge AI      │
                 └──────┬───────┘
                        │
              JSON over Wi-Fi
                        │
                        ▼
                 ┌──────────────┐
                 │     n8n      │
                 └──────┬───────┘
                        │
          ┌─────────────┼──────────────┐
          │             │              │
          ▼             ▼              ▼
      Google        ThingSpeak      AI Agent
      Sheets             │              │
                         │              ▼
                         │          Alert decision
                         │              │
                         └──────┬───────┘
                                ▼
                           Telegram
                           /       \
                         Text     Voice
                           │         │
                           └────┬────┘
                                ▼
                              Parent

30. Project Operating Modes

Normal mode

No crying
↓
Log sensor values
↓
Update dashboard
↓
No alert

Cry detection mode

Cry probability > threshold
↓
Start event timer
↓
Confirm persistence
↓
Generate alert
↓
Telegram
↓
Voice notification

Quiet sleep mode

Low sound
+
Low movement
+
No detected crying
+
Sufficient observation time
↓
Estimated quiet sleep

Repeated crying mode

Cry event
↓
Recovery
↓
Cry event
↓
Recovery
↓
Cry event
↓
Repeated-event rule
↓
Higher-priority notification

31. False-Positive Reduction

This is an important part of the project.

Do not trigger an alert from one noisy audio sample.

Instead:

Audio detected
     │
     ▼
Classifier
     │
     ▼
Probability > threshold?
     │
    YES
     │
     ▼
Persistence timer
     │
     ▼
Still crying?
     │
    YES
     │
     ▼
Generate alert

Potential sources of false positives include:

  • Television

  • Music

  • Adult speech

  • Dogs

  • Door sounds

  • Fan noise

  • Motor noise

  • Other babies

  • Sudden environmental sounds

Training data should include these negative examples.


32. AI Training Dataset

Create a labelled dataset with categories such as:

dataset/
│
├── crying/
│   ├── cry001.wav
│   ├── cry002.wav
│   └── ...
│
├── vocalization/
│   ├── vocal001.wav
│   └── ...
│
├── background/
│   ├── fan001.wav
│   ├── tv001.wav
│   └── ...
│
└── other_noise/
    ├── door001.wav
    └── ...

Recommended process :

Collect audio
     ↓
Label audio
     ↓
Remove unusable recordings
     ↓
Split train/validation/test
     ↓
Extract features
     ↓
Train model
     ↓
Evaluate
     ↓
Quantize/compress
     ↓
Deploy to ESP32

Do not collect or upload recordings of real babies without appropriate consent, privacy safeguards, and compliance with applicable requirements.


33. AI Model Evaluation

Do not report only accuracy.

Measure:

  • Precision

  • Recall

  • F1 score

  • False-positive rate

  • False-negative rate

  • Confusion matrix

  • Inference time

  • RAM consumption

  • Flash usage

Example confusion matrix:

                  Predicted
              Cry     Noise
Actual Cry     TP       FN
Actual Noise  FP       TN

For a baby-monitoring prototype, false alarms and missed events should both be explicitly evaluated rather than hiding them behind a single accuracy number.


34 . Safety Architecture

The cradle should have hardware safety mechanisms independent of the AI agent.

                 AI Agent
                     │
                     ▼
              Suggested action
                     │
                     ▼
             Safety controller
                /          \
             ALLOW         BLOCK
               │             │
               ▼             ▼
          Limited action    Stop

Recommended safeguards:

  • Physical motor limit

  • Maximum rocking duration

  • Emergency stop

  • Independent power cutoff

  • Watchdog timer

  • Motor driver protection

  • No unrestricted AI control

  • Local manual override

  • Sensor-failure detection

  • Wi-Fi failure fallback

Most importantly, the prototype should not rely on automated rocking or software to guarantee infant safety.


35. Power Architecture

                 AC/DC Adapter
                       │
                 ┌─────┴─────┐
                 │           │
                 ▼           ▼
               ESP32       Motor
                 │
        ┌────────┼─────────┐
        ▼        ▼         ▼
      DHT22    MPU6050   Microphone

Keep motor power and logic power appropriately isolated/decoupled, and ensure the selected supply, wiring, driver and enclosure are electrically and mechanically appropriate.


36. Project Software Stack

Firmware
    └── Arduino IDE / PlatformIO
          └── ESP32 C/C++

AI
    └── TensorFlow Lite Micro /
        Edge ML framework

Automation
    └── n8n

Cloud
    ├── Google Sheets
    └── ThingSpeak

Notification
    └── Telegram

Dashboard
    ├── HTML
    ├── CSS
    └── JavaScript

Optional backend
    └── Node.js / Python / n8n API

37. Recommended Development Sequence

Phase 1 – ESP32

First make the ESP32 read:

Temperature
Humidity
Motion

Phase 2 – Wi-Fi

Confirm:

ESP32 → Wi-Fi → Internet

Phase 3 – n8n

Create:

ESP32 → n8n Webhook

Phase 4 – Google Sheets

Add:

n8n → Google Sheets

Phase 5 – ThingSpeak

Add:

n8n → ThingSpeak

Phase 6 – Telegram

Add:

n8n → Telegram

Phase 7 – Audio

Add:

Microphone → ESP32

Phase 8 – AI

Deploy:

Audio → ML model → Cry probability

Phase 9 – AI Agent

Add:

Sensor data → AI agent → structured event summary

Phase 10 – Dashboard

Add:

Cloud data → Web dashboard

Phase 11 – Testing

Test every subsystem independently before integrating the entire cradle.


38. Final Integrated Workflow

                         SMART CRADLE
                              │
         ┌────────────────────┼────────────────────┐
         │                    │                    │
         ▼                    ▼                    ▼
    Microphone             DHT22              MPU6050
         │                    │                    │
         └────────────────────┼────────────────────┘
                              ▼
                           ESP32
                              │
                    Edge processing
                              │
                    Cry probability
                              │
                              ▼
                            Wi-Fi
                              │
                              ▼
                         n8n Webhook
                              │
             ┌────────────────┼────────────────┐
             │                │                │
             ▼                ▼                ▼
       Google Sheets      ThingSpeak        AI Agent
             │                │                │
             │                │                ▼
             │                │          Event interpretation
             │                │                │
             └────────────────┼────────────────┘
                              │
                              ▼
                       Alert decision
                              │
                              ▼
                         Telegram
                         /       \
                       Text      Voice
                         │         │
                         └────┬────┘
                              ▼
                           Parent

                              │
                              ▼
                       Web Dashboard

39. Expected Final Demonstration

A project demonstration can follow this sequence:

  1. Power on the smart cradle.

  2. ESP32 connects to Wi-Fi.

  3. Dashboard shows ONLINE.

  4. Temperature and humidity appear.

  5. Motion sensor reports cradle activity.

  6. Audio is processed.

  7. Cry classifier produces a probability.

  8. A sustained crying event is detected.

  9. ESP32 sends JSON to n8n.

  10. n8n stores the event in Google Sheets.

  11. n8n updates ThingSpeak.

  12. AI agent interprets the event.

  13. n8n sends Telegram text notification.

  14. n8n generates a voice notification.

  15. Parent receives the alert.

  16. Dashboard changes to the current state.

  17. Event remains available in the history.

40. Final Project Title

A suitable formal project title is:

“AI Smart Cradle with Baby Cry Detection, Sleep-State Analysis and Agentic IoT Automation Using ESP32, n8n, Telegram, Google Sheets and ThingSpeak.”

Alternative shorter title:

“AI-Powered Smart Cradle with ESP32 and Agentic IoT Automation.”

41. Key Innovation

The main innovation is not simply detecting sound. It is the integration of:

EDGE AI
   +
IoT SENSORS
   +
ESP32
   +
n8n AUTOMATION
   +
AI AGENT
   +
CLOUD DATA
   +
TELEGRAM VOICE ALERTS
   +
WEB DASHBOARD

This creates an end-to-end agentic IoT monitoring platform in which the ESP32 performs local sensing, n8n coordinates events and services, the AI agent interprets events, and the caregiver receives actionable notifications.

The system should always be presented as an assistive prototype. Cry detection and sleep-state estimation are probabilistic and should not be represented as medical diagnosis or as a substitute for direct caregiver supervision.

 

Project Summary

AI Smart Cradle with Baby Cry Detection & Sleep Analysis is an IoT-based smart cradle using ESP32 + AI/ML + n8n + Telegram + Google Sheets + ThingSpeak + Web Dashboard.

Core workflow

Baby
 ↓
Microphone + Temperature + Humidity + Motion Sensors
 ↓
ESP32
 ↓
AI Cry Detection + Sleep/Activity Estimation
 ↓
Wi-Fi
 ↓
n8n Automation
 ├── Google Sheets → Data/Event Logging
 ├── ThingSpeak → Cloud Graphs
 ├── AI Agent → Event Analysis
 └── Telegram → Text + Voice Alerts
              ↓
            Parent

Main functions

  • 🎤 Detect possible baby crying using an audio ML model.

  • 🌡️ Monitor temperature and humidity.

  • 📡 Monitor cradle/baby movement.

  • 😴 Estimate states such as quiet sleep, active, or possible crying.

  • 🤖 Use an AI agent to summarize events.

  • ⚙️ Use n8n to automate the complete workflow.

  • 📱 Send Telegram notifications.

  • 🔊 Send Telegram voice alerts through a TTS service.

  • 📊 Store historical data in Google Sheets.

  • 📈 Visualize IoT data with ThingSpeak.

  • 🌐 Provide a live web dashboard.

Hardware

  • ESP32 DevKit

  • I2S microphone

  • DHT22/SHT31

  • MPU6050

  • Vibration sensor

  • OLED display

  • LED/buzzer

  • Optional motor + motor driver

Software

ESP32
  ↓
Arduino IDE / PlatformIO
  ↓
Edge AI / TensorFlow Lite Micro
  ↓
n8n
  ├── Google Sheets
  ├── ThingSpeak
  ├── AI Agent
  └── Telegram
       ├── Text
       └── Voice
  ↓
Web Dashboard

Important design principle

The AI agent should not directly control the cradle motor without independent safety controls. Hardware limits, watchdogs, emergency stop/manual override, and bounded operating times should be implemented separately.

The complete project can therefore be presented as an end-to-end Agentic IoT system:

Sense → Analyze → Automate → Store → Notify → Visualize.

 

🧠 AI Smart Cr adle — Mind Map

                              ┌──────────────────────────────┐
                              │      AI SMART CRADLE         │
                              │ Baby Cry Detection + Sleep   │
                              │ Analysis + Agentic IoT       │
                              └──────────────┬───────────────┘
                                             │
       ┌─────────────────────────────────────┼─────────────────────────────────────┐
       │                                     │                                     │
       ▼                                     ▼                                     ▼
┌───────────────┐                     ┌───────────────┐                     ┌───────────────┐
│   HARDWARE    │                     │     AI/ML     │                     │     IoT       │
└───────┬───────┘                     └───────┬───────┘                     └───────┬───────┘
        │                                     │                                     │
        ├── ESP32                             ├── Audio preprocessing                ├── Wi-Fi
        ├── I2S Microphone                    ├── MFCC / Mel features                ├── HTTP/JSON
        ├── DHT22 / SHT31                     ├── Cry classifier                     ├── n8n
        ├── MPU6050                            ├── Cry probability                    ├── Google Sheets
        ├── Vibration sensor                  ├── Sleep estimation                   ├── ThingSpeak
        ├── OLED                              ├── Activity detection                 └── Cloud API
        ├── LED
        ├── Buzzer
        └── Optional Motor
                                             │
                                             ▼
                                  ┌─────────────────────┐
                                  │   EVENT ANALYSIS    │
                                  └──────────┬──────────┘
                                             │
                          ┌──────────────────┼──────────────────┐
                          │                  │                  │
                          ▼                  ▼                  ▼
                       Normal            Sleeping           Crying
                          │                  │                  │
                          └──────────────────┼──────────────────┘
                                             │
                                             ▼
                                  ┌─────────────────────┐
                                  │   n8n AUTOMATION    │
                                  └──────────┬──────────┘
                                             │
                  ┌──────────────────────────┼─────────────────────────┐
                  │                          │                         │
                  ▼                          ▼                         ▼
          ┌───────────────┐          ┌───────────────┐         ┌───────────────┐
          │ Google Sheets │          │  ThingSpeak   │         │   AI AGENT    │
          └───────────────┘          └───────────────┘         └───────┬───────┘
                  │                          │                         │
                  ▼                          ▼                         ▼
             Event Log                  IoT Graphs              Event Summary
                                                                        │
                                                                        ▼
                                                            ┌────────────────────┐
                                                            │  ALERT DECISION     │
                                                            └─────────┬──────────┘
                                                                      │
                                                       ┌──────────────┴─────────────┐
                                                       │                            │
                                                       ▼                            ▼
                                                Telegram Text                Telegram Voice
                                                       │                            │
                                                       └──────────────┬─────────────┘
                                                                      ▼
                                                                  👨‍👩‍👧 Parent
                                                                      │
                                                                      ▼
                                                            ┌──────────────────┐
                                                            │  WEB DASHBOARD   │
                                                            └────────┬─────────┘
                                                                     │
                                      ┌──────────────────────────────┼───────────────────────┐
                                      │                              │                       │
                                      ▼                              ▼                       ▼
                                Temperature                    Humidity              Cry Probability
                                      │                              │                       │
                                      └──────────────────────────────┼───────────────────────┘
                                                                     │
                                                                     ▼
                                                               Baby State

🔄 Core Concept

SENSE
  ↓
ESP32 Sensors
  ↓
PROCESS
  ↓
Edge AI / Cry Detection
  ↓
ANALYZE
  ↓
n8n + AI Agent
  ↓
AUTOMATE
  ↓
Google Sheets + ThingSpeak
  ↓
NOTIFY
  ↓
Telegram Text + Voice
  ↓
VISUALIZE
  ↓
Web Dashboard

🎯 Project Goal

“Build an intelligent, connected cradle that detects possible crying and activity locally, analyzes events through an automated AI/IoT pipeline, stores historical data, and provides timely caregiver notifications.”

 

No comments:

Post a Comment