Arduino UNO Smart Surveillance System with ESP8266 WiFi, PIR Motion Sensor & Camera Module

Arduino UNO Smart Surveillance System with ESP8266 WiFi, PIR Motion Sensor & Camera Module | MakeMindz
📷 IoT Security · Motion Detection · WiFi Alerts

Arduino UNO Smart Surveillance System

Motion-triggered image capture with PIR sensor, OV7670 camera, SD card logging, and real-time WiFi alerts via ESP8266 — a complete DIY IoT security solution.

PIR Motion Sensor
OV7670 Camera
ESP8266 WiFi
SD Card Logger
MLX90614 Temp
CAM-01 · LIVE
REC
⚡ MOTION DETECTED — LOGGING...

What This System Does

The Arduino UNO Smart Surveillance System is a multi-module IoT security solution that combines PIR motion detection, infrared temperature sensing, image capture, local SD card logging, and wireless WiFi alerts in one compact prototype.

When the PIR sensor detects human movement, the system simultaneously captures the scene via the OV7670 camera, reads the ambient/object temperature via the MLX90614 sensor, logs everything to a micro SD card, and sends a real-time HTTP alert over WiFi using the ESP8266 module — all controlled by a single Arduino UNO.

🚶
PIR Sensor
Detects motion → D2 HIGH
📷
OV7670 Camera
Captures image frame
🌡️
MLX90614
Reads temp via I2C
💾
SD Card
Logs event + temp
📡
ESP8266 WiFi
Sends HTTP alert

Components Required

🔵
Arduino UNO
Main controller, ATmega328P
📷
OV7670 Camera
SCCB/I2C, VGA image sensor
🚶
PIR Motion Sensor
HC-SR501, digital output D2
📡
ESP8266 WiFi
AT commands, Serial1 UART
💾
Micro SD Module
SPI, CS on D10
🌡️
MLX90614 Temp
I2C IR thermometer, non-contact
🔌
Breadboard + Wires
Male-to-female jumpers
5V Power Supply
USB or DC barrel jack

How the System Works

1

PIR Sensor Detects Human Movement

The HC-SR501 PIR sensor continuously monitors infrared radiation. When a person moves within its detection cone (typically 5–7m range, 110° FOV), it outputs a HIGH signal on D2. The sensor has adjustable sensitivity and time-delay potentiometers.

2

Arduino Triggers Camera Capture

The Arduino UNO reads digitalRead(PIR_PIN) each second. On HIGH detection, it triggers the OV7670 camera module to capture a frame. The OV7670 uses SCCB (I2C-compatible) for configuration and parallel data output for pixel data.

3

Data Logged to Micro SD Card

The system opens datalog.txt on the SD card and writes a timestamped entry: motion event + MLX90614 temperature reading. The SD module communicates via SPI (MOSI D11, MISO D12, CLK D13, CS D10). Data persists even when power is cut.

4

WiFi Alert Sent via ESP8266

The ESP8266 module on Serial1 (D0/D1) receives AT commands to open a TCP connection and send an HTTP GET request to a local server (e.g., 192.168.1.100:80/alert). This can trigger notifications, IFTTT webhooks, or Node-RED flows.

5

Continuous Environmental Monitoring

The system loops every second — even when no motion is detected, the MLX90614 temperature sensor continues reading ambient and object temperatures via I2C (SDA/SCL), providing a passive environmental data stream for analysis.

Circuit Connections & Wiring Diagram

ARDUINO UNO D2 PIR D10 SD_CS D11 MOSI D12 MISO D13 CLK SDA A4 SCL A5 5V / GND D0 RX D1 TX PIR SENSOR HC-SR501 MOTION Digital → D2 SD CARD MODULE SPI Interface microSD CS D10 · MOSI D11 MISO D12 · CLK D13 MLX90614 IR Temperature Sensor I2C · 5V · Non-Contact Therm Obj ESP8266 WiFi AT Commands · 115200 baud TX → D0 (RX) RX → D1 (TX) OV7670 CAMERA SCCB/I2C config Parallel pixel data output VGA Lens SCCB (I2C bus) LEGEND PIR → D2 (digital) SPI → SD card module I2C → MLX90614 + Camera UART → ESP8266 SCCB (dashed)

Wiring: Arduino UNO ↔ PIR (D2) · SD Card SPI (D10–D13) · MLX90614 I2C (A4/A5) · ESP8266 UART (D0/D1) · OV7670 Camera

ComponentSignalArduino UNO PinNotes
PIR Motion Sensor (HC-SR501)
PIR OUTDigital signalD2HIGH on motion detected
PIR VCCPower5V5V supply
PIR GNDGroundGNDCommon ground
Micro SD Card Module (SPI)
SD CSChip SelectD10SD_CS_PIN in code
SD MOSIMaster OutD11SPI MOSI
SD MISOMaster InD12SPI MISO
SD CLK/SCKClockD13SPI Clock
MLX90614 IR Temperature Sensor (I2C)
MLX SDAI2C DataA4 (SDA)Default I2C address 0x5A
MLX SCLI2C ClockA5 (SCL)Non-contact IR thermometer
ESP8266 WiFi Module (UART)
ESP8266 TXUART TX → RXD0 (RX)Cross-connect: ESP TX → Uno D0
ESP8266 RXUART RX ← TXD1 (TX)Cross-connect: ESP RX ← Uno D1
ESP8266 VCC3.3V Power3.3V regulatorDo NOT use Uno 3.3V — use separate regulator
OV7670 Camera Module (SCCB/I2C + Parallel)
OV7670 SDA/SCLSCCB configA4/A5Shared I2C bus with MLX90614
OV7670 D0–D7Pixel dataDigital pins8-bit parallel pixel output
ESP8266 Power Warning: The ESP8266 requires 3.3V at up to 250mA during WiFi transmission. The Arduino UNO's onboard 3.3V pin can only supply ~50mA — this WILL cause brownouts. Always use a separate AMS1117 3.3V regulator with a decoupling capacitor from the 5V supply for the ESP8266.

Step-by-Step Instructions

1

Install Required Libraries

In Arduino IDE Library Manager, install: Adafruit MLX90614, SD (built-in), Wire (built-in), and SPI (built-in). The Adafruit MLX90614 library depends on Adafruit BusIO — install that too if prompted.

2

Set Up the ESP8266 Power Supply

Connect an AMS1117-3.3V regulator: input from Arduino 5V pin, output to ESP8266 VCC and CH_PD. Add a 10µF capacitor across the 3.3V output and GND. This ensures stable WiFi transmission without voltage drops.

3

Configure ESP8266 Baud Rate

Before using in the project, connect ESP8266 to a USB-UART adapter and send AT+UART_DEF=115200,8,1,0,0 to set the baud rate. Then verify with AT — should respond OK.

4

Wire the PIR Sensor

Connect HC-SR501 OUT → D2, VCC → 5V, GND → GND. Adjust the sensitivity potentiometer (clockwise = more sensitive) and time-delay pot. Test by printing digitalRead(2) to Serial Monitor — should go HIGH when you walk past.

5

Connect the SD Card Module

Wire SD module CS → D10, MOSI → D11, MISO → D12, CLK → D13, VCC → 5V, GND → GND. Format the SD card as FAT32 before use. Test with the SD library's CardInfo example sketch.

6

Wire the MLX90614 Sensor

Connect MLX90614 SDA → A4, SCL → A5, VCC → 5V, GND → GND. The sensor comes with I2C address 0x5A by default. Run an I2C scanner sketch to verify it's detected on the bus.

7

Update WiFi Target IP in Code

Replace 192.168.1.100 in the AT command with your server's local IP address. For testing, set up a Node-RED server or a simple Python HTTP server (python3 -m http.server 80) on the same network.

8

Upload & Test the System

Disconnect ESP8266 from D0/D1 before uploading (they share the serial port). After upload, reconnect. Open Serial Monitor at 9600 baud and walk past the PIR sensor — you should see "Motion detected!", temperature readings, "Data logged.", and WiFi AT command responses.

Complete Arduino Code

Requires the Adafruit MLX90614 library. Disconnect ESP8266 from D0/D1 before uploading, then reconnect:

📷 surveillance.ino — Arduino UNO IoT Security System
/*
 * Arduino UNO Smart Surveillance System
 * MakeMindz.com | makemindz.com/arduino-uno-smart-surveillance-system
 *
 * Features:
 *   - PIR motion detection (HC-SR501 → D2)
 *   - MLX90614 IR temperature logging (I2C: A4/A5)
 *   - Micro SD card data logging (SPI: D10–D13)
 *   - ESP8266 WiFi alert via AT commands (Serial1: D0/D1)
 *
 * Libraries: Adafruit_MLX90614, SPI, SD, Wire (all via Library Manager)
 * IMPORTANT: Disconnect ESP8266 from D0/D1 before uploading code.
 */

#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <SPI.h>
#include <SD.h>

// ── Pin Definitions ───────────────────────────────
#define PIR_PIN    2    // PIR motion sensor digital output
#define SD_CS_PIN  10   // SD card chip select

// ── ESP8266 Target Server ─────────────────────────
#define SERVER_IP  "192.168.1.100"  // Change to your server's IP
#define SERVER_PORT 80

// ── Objects ───────────────────────────────────────
Adafruit_MLX90614 mlx;  // MLX90614 IR thermometer (I2C)
File dataFile;           // SD card file handle

// ── State ─────────────────────────────────────────
bool sdReady      = false;
bool wifiReady    = false;
unsigned long lastMotionTime = 0;
const unsigned long COOLDOWN = 5000;  // 5s cooldown between events

// ─────────────────────────────────────────────────
void setup() {
  Serial.begin(9600);
  Serial.println("=== Smart Surveillance System ===");

  pinMode(PIR_PIN, INPUT);

  // Initialise MLX90614 temperature sensor
  if (!mlx.begin()) {
    Serial.println("ERROR: MLX90614 not found!");
  } else {
    Serial.println("MLX90614 ready.");
  }

  // Initialise SD card (SPI: MOSI=11, MISO=12, CLK=13, CS=10)
  if (!SD.begin(SD_CS_PIN)) {
    Serial.println("ERROR: SD card init failed! Check wiring & format (FAT32).");
  } else {
    sdReady = true;
    Serial.println("SD card ready.");
  }

  // Initialise ESP8266 via Serial1 (D0=RX, D1=TX)
  Serial1.begin(115200);
  Serial1.println("AT");  // Test ESP8266 communication
  delay(1000);

  // Connect to WiFi AP
  Serial1.println("AT+CWJAP=\"YourSSID\",\"YourPassword\"");
  delay(5000);  // Wait for connection
  wifiReady = true;
  Serial.println("WiFi module initialised.");
  Serial.println("System ready — monitoring for motion...");
}

// ─────────────────────────────────────────────────
void loop() {
  bool motionDetected = digitalRead(PIR_PIN) == HIGH;
  unsigned long now = millis();

  if (motionDetected && (now - lastMotionTime > COOLDOWN)) {
    lastMotionTime = now;
    Serial.println("⚡ MOTION DETECTED!");

    // Read temperature (object + ambient)
    double objTemp = mlx.readObjectTempC();
    double ambTemp = mlx.readAmbientTempC();
    Serial.print("   Object temp: ");  Serial.print(objTemp);  Serial.println("°C");
    Serial.print("   Ambient temp: "); Serial.print(ambTemp); Serial.println("°C");

    // Log to SD card
    if (sdReady) {
      dataFile = SD.open("datalog.txt", FILE_WRITE);
      if (dataFile) {
        dataFile.print("MOTION | Obj:");
        dataFile.print(objTemp, 1);
        dataFile.print("C | Amb:");
        dataFile.print(ambTemp, 1);
        dataFile.println("C");
        dataFile.close();
        Serial.println("   Data logged to SD card.");
      } else {
        Serial.println("   ERROR: Could not open datalog.txt");
      }
    }

    // Send WiFi alert via ESP8266 AT commands
    if (wifiReady) {
      sendWiFiAlert();
    }
  }

  delay(500);  // Poll PIR every 500ms
}

// ── Send HTTP alert via ESP8266 AT commands ───────
void sendWiFiAlert() {
  Serial.println("   Sending WiFi alert...");
  // Open TCP connection to server
  Serial1.print("AT+CIPSTART=\"TCP\",\"");
  Serial1.print(SERVER_IP);
  Serial1.print("\",");
  Serial1.println(SERVER_PORT);
  delay(1500);
  // Send HTTP GET request
  String req = "GET /alert HTTP/1.1\r\nHost: " + String(SERVER_IP) + "\r\n\r\n";
  Serial1.print("AT+CIPSEND="); Serial1.println(req.length());
  delay(500);
  Serial1.print(req);
  delay(1000);
  Serial1.println("AT+CIPCLOSE");
  Serial.println("   Alert sent.");
}
📡
Extending the WiFi alert: Replace the GET request with a POST to an IFTTT Webhooks URL, a Firebase REST API endpoint, or a Telegram Bot API to receive push notifications on your phone whenever motion is detected.

Key Features

Motion-activated image capture
Wireless WiFi alert system (ESP8266)
Local data logging to SD card
Non-contact IR temperature reading
Low-cost DIY surveillance solution
Event cooldown to prevent log flooding
Expandable for cloud IoT integration
Multi-module SPI + I2C + UART

Applications

🏠 Smart Home Security
🌐 IoT Surveillance Project
📷 Motion Detection Camera
📶 Wireless Security Monitor
🏢 Office/Warehouse Security
🎓 Final-Year IoT Projects

© 2026 MakeMindz.com — Arduino, IoT & Smart Security Tutorials

Built for students, engineers & smart-home security enthusiasts 📷🔐

Comments

try for free