Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Manufacturing Technology >> Manufacturing process

Raspberry Pi Home Security System: PIR Motion Detection + Camera Email Alerts

Hardware Components

Software and Services

Project Overview

In this project, a Raspberry Pi 3 Model B is paired with a camera module and a PIR motion sensor. When motion is detected, the camera captures an image and the system sends it to a designated email address via Gmail.

Wiring Diagram

Connect the sensor’s 5V pin to Raspberry Pi pin 3 (5 V), the sensor’s GND pin to pin 5 (GND), and the sensor’s OUT pin to GPIO 23. You can select a different GPIO pin but remember to update the Python code accordingly.

Python Implementation

The following script demonstrates the core logic. Update the email addresses and Gmail password before running.

from picamera import PiCamera
from time import sleep
import smtplib
import time
from datetime import datetime
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
import RPi.GPIO as GPIO

TO_EMAIL = 'TO_EMAIL'
FROM_EMAIL = 'FROM_EMAIL'
PASSWORD = 'PASSWORD'  # Gmail account password or App password

GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)

camera = PiCamera()
camera.resolution = (1024, 768)
camera.start_preview()

while True:
    if GPIO.input(23):
        print("Motion detected...")
        time.sleep(2)  # camera warm‑up
        camera.capture('movement.jpg')
        time.sleep(10)  # debounce period

        msg = MIMEMultipart()
        msg['Subject'] = 'Security alert'
        msg['From'] = FROM_EMAIL
        msg['To'] = TO_EMAIL

        with open('movement.jpg', 'rb') as fp:
            img = MIMEImage(fp.read())
        msg.attach(img)

        server = smtplib.SMTP('smtp.gmail.com', 587)
        server.starttls()
        server.login(FROM_EMAIL, PASSWORD)
        server.send_message(msg)
        server.quit()

For detailed steps, refer to the full guide: Raspberry Pi Home Security System with Camera and PIR Sensor.

Manufacturing process

  1. Connect Multiple DS18B20 1‑Wire Sensors to a Raspberry Pi for Accurate Temperature Monitoring
  2. Build a 433 MHz Smart Home Controller with Sensorflare and Raspberry Pi
  3. Raspberry Pi Photocell Logging & Alert System – Build a Low‑Power Light Sensor with Python
  4. Build Your First IoT Project with Raspberry Pi, DHT11, and ThingSpeak
  5. Build an Automated Aeroponics System with Raspberry Pi and Humidity Sensor
  6. Master Raspberry Pi GPIO: Interfacing a PIR Motion Sensor on B+/Model 2
  7. How to Connect, Calibrate, and Program the HC‑SR501 PIR Motion Sensor with a Raspberry Pi
  8. Smart Indoor Air Quality & Waste Monitoring System
  9. Build a Smart Home Automation & Security System with 1Sheeld
  10. PIR Motion Sensor: Working Principles & Arduino Integration Guide