This guide will help you set up an IoT-Based Theft Detection System using Raspberry Pi. The system will monitor for unauthorized access using sensors and send real-time alerts to ensure security.

Components Required

  • Raspberry Pi (Model 3 or later)
  • Motion sensor (e.g., PIR sensor)
  • Door/window contact sensor (magnetic sensor)
  • Camera module (for capturing images or videos)
  • Buzzer or alarm (for local alerts)
  • Relay module (for controlling alarms or notifications)
  • Connecting wires and breadboard
  • Power supply (for Raspberry Pi and peripherals)
  • Cloud service account (e.g., AWS IoT, Google Cloud IoT)

Setting Up the Hardware

Follow these steps to set up the hardware:

  1. Install the Motion Sensor

    Connect the motion sensor to the Raspberry Pi GPIO pins. This sensor will detect movement in the monitored area and trigger alerts.

  2. Attach the Door/Window Contact Sensor

    Install the contact sensor on doors or windows to monitor if they are opened or tampered with. Connect the sensor to the Raspberry Pi.

  3. Set Up the Camera Module

    Connect the camera module to capture images or videos when motion is detected or a contact sensor is triggered. This will help in verifying the alerts.

  4. Connect the Buzzer or Alarm

    Connect the buzzer or alarm to the Raspberry Pi via the relay module to sound an alert when a theft is detected.

  5. Power the System

    Ensure that the Raspberry Pi and all connected components are properly powered and connected.

Programming the Raspberry Pi

Write the code to handle sensor inputs, capture images, and send alerts. Below is a basic example using Python:


                import time
                import RPi.GPIO as GPIO
                from picamera import PiCamera
                import requests

                # Configuration
                MOTION_SENSOR_PIN = 17
                CONTACT_SENSOR_PIN = 27
                ALARM_PIN = 22
                CAMERA = PiCamera()
                CLOUD_URL = "https://api.example.com/theft_alert?api_key=YOUR_API_KEY"

                # Setup
                GPIO.setmode(GPIO.BCM)
                GPIO.setup(MOTION_SENSOR_PIN, GPIO.IN)
                GPIO.setup(CONTACT_SENSOR_PIN, GPIO.IN)
                GPIO.setup(ALARM_PIN, GPIO.OUT)

                def send_alert(image_path):
                    # Send image and alert to cloud
                    files = {'file': open(image_path, 'rb')}
                    response = requests.post(CLOUD_URL, files=files)
                    print(f"Alert sent to cloud: {response.status_code}")

                def capture_image():
                    # Capture image from camera
                    image_path = '/home/pi/image.jpg'
                    CAMERA.capture(image_path)
                    return image_path

                try:
                    while True:
                        if GPIO.input(MOTION_SENSOR_PIN) or GPIO.input(CONTACT_SENSOR_PIN):
                            print("Motion detected or sensor triggered!")
                            GPIO.output(ALARM_PIN, GPIO.HIGH)  # Activate alarm
                            image_path = capture_image()
                            send_alert(image_path)
                            time.sleep(60)  # Wait before next check
                        else:
                            GPIO.output(ALARM_PIN, GPIO.LOW)  # Deactivate alarm
                        time.sleep(1)  # Adjust as necessary

                except KeyboardInterrupt:
                    GPIO.cleanup()
            

This code detects motion or sensor triggers, captures an image, and sends an alert to the cloud. It also activates a local alarm for immediate alerting.

Setting Up Cloud Integration

To monitor alerts and manage notifications, integrate the system with a cloud service. Configure the cloud service to receive image files and alert data from the Raspberry Pi, and set up dashboards or notifications as needed.

Testing and Calibration

Test the system by simulating theft scenarios and ensuring that the sensors, camera, and alarm respond correctly. Verify that alerts are sent to the cloud and that the image capture and notification functions work as expected.

Conclusion

The IoT-Based Theft Detection System provides an effective solution for monitoring and securing premises. By integrating sensors, a camera, and cloud services with Raspberry Pi, this system enhances security and provides real-time alerts for unauthorized access.