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.
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.
Components Required
How the System Works
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.
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.
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.
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.
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
Wiring: Arduino UNO ↔ PIR (D2) · SD Card SPI (D10–D13) · MLX90614 I2C (A4/A5) · ESP8266 UART (D0/D1) · OV7670 Camera
| Component | Signal | Arduino UNO Pin | Notes |
|---|---|---|---|
| PIR Motion Sensor (HC-SR501) | |||
| PIR OUT | Digital signal | D2 | HIGH on motion detected |
| PIR VCC | Power | 5V | 5V supply |
| PIR GND | Ground | GND | Common ground |
| Micro SD Card Module (SPI) | |||
| SD CS | Chip Select | D10 | SD_CS_PIN in code |
| SD MOSI | Master Out | D11 | SPI MOSI |
| SD MISO | Master In | D12 | SPI MISO |
| SD CLK/SCK | Clock | D13 | SPI Clock |
| MLX90614 IR Temperature Sensor (I2C) | |||
| MLX SDA | I2C Data | A4 (SDA) | Default I2C address 0x5A |
| MLX SCL | I2C Clock | A5 (SCL) | Non-contact IR thermometer |
| ESP8266 WiFi Module (UART) | |||
| ESP8266 TX | UART TX → RX | D0 (RX) | Cross-connect: ESP TX → Uno D0 |
| ESP8266 RX | UART RX ← TX | D1 (TX) | Cross-connect: ESP RX ← Uno D1 |
| ESP8266 VCC | 3.3V Power | 3.3V regulator | Do NOT use Uno 3.3V — use separate regulator |
| OV7670 Camera Module (SCCB/I2C + Parallel) | |||
| OV7670 SDA/SCL | SCCB config | A4/A5 | Shared I2C bus with MLX90614 |
| OV7670 D0–D7 | Pixel data | Digital pins | 8-bit parallel pixel output |
Step-by-Step Instructions
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.
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.
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.
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.
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.
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.
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.
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:
/* * 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."); }
Comments
Post a Comment