Project Overview
This project creates a smart baby monitor that detects when your baby wakes up and sends an alert to your phone. Unlike traditional audio or video monitors, this system uses a PIR sensor to detect movement in the crib without intrusive cameras or microphones, preserving privacy while still alerting you when the baby is awake.
Difficulty: Intermediate
Estimated time: 2 hours
Estimated cost: $20-30
How It Works
A PIR sensor is positioned above or near the crib to detect motion. When the baby moves (wakes up), the ESP32 detects the motion and sends a notification to your phone via Blynk or Telegram. A sensitivity adjustment ensures small movements (like breathing) don’t trigger false alerts while larger movements (waking up) do.
Materials Needed
- ESP32 (1)
- HC-SR501 or AM312 PIR sensor (1)
- DHT22 temperature/humidity sensor (optional)
- RGB LED or WS2812B LED strip for night light (optional)
- Buzzer for local audible alert (optional)
- Jumper wires
- Power supply (5V 1A)
- Project enclosure
Blynk Setup
- Download Blynk IoT app and create an account
- Create a new template for your baby monitor
- Add a Notification widget
- Add a Button widget for night light control
- Add a Gauge widget for temperature display (if using DHT22)
- Note your BLYNK_TEMPLATE_ID and BLYNK_AUTH_TOKEN
Circuit Diagram
Connection Table
| Component |
Pin |
ESP32 Pin |
PIR Sensor |
VCC
3.3V
PIR Sensor |
GND
GND
PIR Sensor |
OUT
GPIO 4
DHT22 |
DATA
GPIO 5
WS2812B LED |
DATA
GPIO 6
Buzzer |
Positive
GPIO 7
表
Arduino Code (Blynk IoT Platform)
// PIR Baby Monitor with Blynk
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
#include <FastLED.h>
#define BLYNK_TEMPLATE_ID "YourTemplateID"
#define BLYNK_TEMPLATE_NAME "Baby Monitor"
#define BLYNK_AUTH_TOKEN "YourAuthToken"
char ssid[] = "YourWiFiSSID";
char pass[] = "YourWiFiPassword";
const int pirPin = 4;
const int dhtPin = 5;
const int ledPin = 6;
const int buzzerPin = 7;
#define DHTTYPE DHT22
DHT dht(dhtPin, DHTTYPE);
#define NUM_LEDS 8
CRGB leds[NUM_LEDS];
bool nightLightOn = false;
unsigned long lastAlertTime = 0;
const unsigned long alertCooldown = 300000;
bool motionDetectedFlag = false;
void setup() {
Serial.begin(115200);
pinMode(pirPin, INPUT);
pinMode(buzzerPin, OUTPUT);
digitalWrite(buzzerPin, LOW);
FastLED.addLeds<WS2812B, ledPin, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(64);
FastLED.clear();
dht.begin();
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
delay(60000);
}
BLYNK_WRITE(V0) {
nightLightOn = param.asInt();
if (nightLightOn) {
for (int i = 0; i < NUM_LEDS; i++) leds[i] = CRGB(255, 180, 100);
FastLED.show();
} else {
FastLED.clear();
FastLED.show();
}
}
void sendAlert() {
if (millis() - lastAlertTime > alertCooldown) {
Blynk.logEvent("baby_wakeup", "Baby is waking up!");
lastAlertTime = millis();
tone(buzzerPin, 1000, 200);
delay(200);
tone(buzzerPin, 1500, 200);
if (!nightLightOn) {
for (int i = 0; i < NUM_LEDS; i++) leds[i] = CRGB(255, 180, 100);
FastLED.show();
delay(10000);
if (!nightLightOn) FastLED.clear();
FastLED.show();
}
}
}
void readAndSendTemperature() {
float temp = dht.readTemperature();
float humidity = dht.readHumidity();
if (!isnan(temp)) {
Blynk.virtualWrite(V1, temp);
Blynk.virtualWrite(V2, humidity);
}
}
void loop() {
Blynk.run();
bool motion = digitalRead(pirPin) == HIGH;
if (motion && !motionDetectedFlag) {
motionDetectedFlag = true;
sendAlert();
}
if (!motion) motionDetectedFlag = false;
static unsigned long lastTempRead = 0;
if (millis() - lastTempRead > 30000) {
readAndSendTemperature();
lastTempRead = millis();
}
delay(100);
}
Telegram Bot Version (No Blynk Account)
#include <WiFi.h>
#include <UniversalTelegramBot.h>
const char* ssid = "YourWiFiSSID";
const char* password = "YourWiFiPassword";
const char* botToken = "YourTelegramBotToken";
const char* chatID = "YourChatID";
WiFiClientSecure client;
UniversalTelegramBot bot(botToken, client);
const int pirPin = 4;
unsigned long lastAlertTime = 0;
const unsigned long alertCooldown = 300000;
void setup() {
Serial.begin(115200);
pinMode(pirPin, INPUT);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) delay(500);
client.setCACert(TELEGRAM_CERTIFICATE_ROOT);
delay(60000);
}
void sendTelegramAlert() {
if (millis() - lastAlertTime > alertCooldown) {
bot.sendMessage(chatID, "Baby is waking up! 👶", "");
lastAlertTime = millis();
}
}
void loop() {
if (digitalRead(pirPin) == HIGH) {
sendTelegramAlert();
delay(10000);
}
delay(100);
}
Installation Steps
- Assemble circuit on breadboard and test
- Configure Blynk or Telegram notifications
- Test motion detection by waving hand
- Mount sensor above crib at 1-1.5m height, angled downward
- Adjust sensitivity to detect baby movement only
- Test with baby to ensure alerts are reliable but not excessive
Project Extensions
- Add temperature alerts if room is too hot or cold
- Add sound sensor to detect crying
- Add DFPlayer Mini to play lullabies when motion detected
- Add data logging to track sleep/wake patterns
- Add Google Assistant integration to ask “Is the baby awake?”
Conclusion
This PIR-based baby monitor provides peace of mind without intrusive cameras or constant audio monitoring. You will know exactly when your baby wakes up, allowing you to respond promptly while preserving privacy.