Skip to content
cropped-image.webp

cropped-banner-promo-full-yellow.jpg

Connect with Us

  • Facebook
  • Twitter
  • Linkedin
  • VK
  • Youtube
  • Instagram
Primary Menu
  • Home
  • Blog
Light/Dark Button
Watch Video
  • Home
  • The Lab
  • ESP8266 Motion Sensor Security System
  • The Lab

ESP8266 Motion Sensor Security System

Friday February 19, 2026 (Last updated: February 20, 2026) 2 minutes read

Difficulty: Beginner
Time Required: 1-2 hours
Cost: $10-15
ESP Board: ESP8266

What You’ll Need

Component Cost Where to Buy
NodeMCU ESP8266 $4-6 Amazon
HC-SR501 PIR Sensor $2-3 Amazon
Buzzer $1-2 Amazon
LED $1 Amazon
Jumper Wires $2 Amazon

Circuit Diagram

ESP8266 Pin Component
3.3V PIR VCC
GND PIR GND
D1 (GPIO 5) PIR OUT
D2 (GPIO 4) Buzzer
D3 (GPIO 0) LED

The Complete Code

/*********************************************************************
 * ESP8266 Motion Sensor Security System
 * 
 * Detects motion and sends Telegram notifications
 * Hardware: NodeMCU, HC-SR501 PIR, Buzzer, LED
 *********************************************************************/

#include 
#include 
#include 

// ============== WIFI ==============
const char* wifi_ssid = "YOUR_WIFI";
const char* wifi_password = "YOUR_PASSWORD";

// ============== TELEGRAM ==============
#define BOT_TOKEN "YOUR_BOT_TOKEN"
#define CHAT_ID "YOUR_CHAT_ID"

WiFiClientSecure client;
UniversalTelegramBot bot(BOT_TOKEN, client);

// ============== PINS ==============
#define MOTION_SENSOR D1
#define BUZZER_PIN D2
#define LED_PIN D3

// ============== CONFIG ==============
unsigned long lastMotionTime = 0;
const unsigned long ALERT_COOLDOWN = 30000;  // 30 seconds
bool motionDetected = false;

void setup() {
  Serial.begin(115200);
  
  pinMode(MOTION_SENSOR, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  
  digitalWrite(BUZZER_PIN, LOW);
  digitalWrite(LED_PIN, LOW);
  
  connectToWiFi();
  client.setCACert(TELEGRAM_CERTIFICATE_ROOT);
  
  Serial.println(F("Security system active!"));
}

void loop() {
  if (digitalRead(MOTION_SENSOR) == HIGH) {
    if (millis() - lastMotionTime > ALERT_COOLDOWN) {
      triggerAlarm();
      lastMotionTime = millis();
    }
  }
  delay(100);
}

void triggerAlarm() {
  Serial.println(F("MOTION DETECTED!"));
  
  // Flash LED
  for (int i = 0; i < 10; i++) {
    digitalWrite(LED_PIN, HIGH);
    delay(100);
    digitalWrite(LED_PIN, LOW);
    delay(100);
  }
  
  // Sound buzzer
  digitalWrite(BUZZER_PIN, HIGH);
  delay(500);
  digitalWrite(BUZZER_PIN, LOW);
  
  // Send Telegram
  String msg = "🚨 Motion detected at " + String(millis()/1000) + " seconds ago!";
  bot.sendMessage(CHAT_ID, msg, "");
}

void connectToWiFi() {
  WiFi.begin(wifi_ssid, wifi_password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(F("."));
  }
  Serial.println(F(" Connected!"));
}

Official Documentation

  • Telegram Bot Library
  • HC-SR501 Datasheet

Frequently Asked Questions

Q: How do I adjust PIR sensitivity?

A: Use the sensitivity potentiometer on the PIR board. Turn clockwise to increase sensitivity.

About The Author

Friday

See author's posts

Post navigation

Previous: ESP32 Smart Plant Watering System
Next: ESP32 Smart Garage Door Opener (IoT)

Related Stories

  • The Lab

Raspberry Pi Pico vs ESP32: Which Should You Choose? 2026

Friday March 4, 2026
  • The Lab

ESP32-C3 vs ESP32-S3: Detailed Comparison 2026

Friday March 4, 2026
  • The Lab

STM32 vs ESP32: Battle of the Microcontrollers 2026

Friday March 3, 2026

Connect with Us

  • Facebook
  • Twitter
  • Linkedin
  • VK
  • Youtube
  • Instagram

Trending News

7 Best Shopify Alternatives for Dropshipping in 2026 1
  • Latest News

7 Best Shopify Alternatives for Dropshipping in 2026

Friday March 4, 2026
ESP32-C3 vs ESP32-S3: Detailed Comparison 2026 2
  • The Lab

ESP32-C3 vs ESP32-S3: Detailed Comparison 2026

Friday March 4, 2026
Raspberry Pi Pico vs ESP32: Which Should You Choose? 2026 3
  • The Lab

Raspberry Pi Pico vs ESP32: Which Should You Choose? 2026

Friday March 4, 2026
STM32 vs ESP32: Battle of the Microcontrollers 2026 4
  • The Lab

STM32 vs ESP32: Battle of the Microcontrollers 2026

Friday March 3, 2026
Arduino Mega vs ESP32: Processing Power Face-off 2026 5
  • The Lab

Arduino Mega vs ESP32: Processing Power Face-off 2026

Friday March 3, 2026

You May Have Missed

  • Latest News

7 Best Shopify Alternatives for Dropshipping in 2026

Friday March 4, 2026
  • The Lab

ESP32-C3 vs ESP32-S3: Detailed Comparison 2026

Friday March 4, 2026
  • The Lab

Raspberry Pi Pico vs ESP32: Which Should You Choose? 2026

Friday March 4, 2026
  • The Lab

STM32 vs ESP32: Battle of the Microcontrollers 2026

Friday March 3, 2026
CoreEcom provides honest, research-backed reviews and essential guides. We filter the noise to help global consumers find quality products that deliver real value, ensuring every purchase is a smart investment.

Categories

Buyer's Manuals Deep Reviews Editor's Choice Latest News Setup Guides The Lab

Quick Links

  • About
  • Editorial Standards
  • Privacy
  • Impressum
  • Contact
  • Facebook
  • Twitter
  • Linkedin
  • VK
  • Youtube
  • Instagram
Copyright © Growthscout 2026 All rights reserved. | ReviewNews by AF themes.