Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO-Based Smart Anti-Theft Security System with Bluetooth and Motion Detection

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Smart Anti-Theft Security System with Bluetooth and Motion Detection

Smart Anti-Theft Security System Documentation

Summary

This document provides a detailed overview of a Smart Anti-Theft Security System designed using an Arduino UNO microcontroller. The system integrates various sensors and actuators, including an ultrasonic sensor, a servo motor, a solenoid lock, an MPU6050 motion sensor, a Hall-effect sensor, and an HC-05 Bluetooth module. The system detects room entry, closes and locks the door, monitors a metal box for tampering, and sends alerts via Bluetooth.

Component List

  1. Arduino UNO

    • Description: Microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. Micro Servo 9G

    • Description: Small servo motor used for precise control of angular position.
    • Pins: GND, +5V, PWM
  3. Ultrasonic Sensor

    • Description: Sensor used to measure distance by using ultrasonic waves.
    • Pins: +VCC, Trigger, Echo, GND
  4. Relay Module 5V-30V

    • Description: Relay module used to control high voltage devices.
    • Pins: Common contact, Normally open, Normally closed, Trigger, V-, V+
  5. 12V Solenoid Lock

    • Description: Electromechanical lock that can be controlled electronically.
    • Pins: VCC, GND
  6. MPU6050

    • Description: 6-axis motion tracking device that combines a 3-axis gyroscope and a 3-axis accelerometer.
    • Pins: VCC, GND, SCL, SDA, XDA, XCL, AD0, INT, 3.3V
  7. Hall Sensor

    • Description: Sensor used to detect the presence of a magnetic field.
    • Pins: -, +, S
  8. HC-05 Bluetooth Module

    • Description: Bluetooth module used for wireless communication.
    • Pins: Key, VCC, GND, TXD, RXD, State
  9. 12V Battery

    • Description: Power source for the circuit.
    • Pins: VCC, GND

Wiring Details

Arduino UNO

Micro Servo 9G

Ultrasonic Sensor

Relay Module 5V-30V

12V Solenoid Lock

MPU6050

Hall Sensor

HC-05 Bluetooth Module

12V Battery

Documented Code

/*
 * Smart Anti-Theft Security System
 * This Arduino sketch integrates an ultrasonic sensor, servo motor, solenoid
 * lock, MPU6050 motion sensor, Hall-effect sensor, and HC-05 Bluetooth module
 * to enhance room and asset security. The system detects room entry, closes
 * and locks the door, monitors a metal box for tampering, and sends alerts
 * via Bluetooth.
 */

#include <Servo.h>
#include <Wire.h>
#include <MPU6050.h>

Servo servoMotor;
MPU6050 mpu;

const int trigPin = 9;
const int echoPin = 8;
const int relayPin = 11;
const int hallPin = 7;
const int servoPin = 10;

#define SERIAL_BAUD_RATE 9600

void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(hallPin, INPUT);

  servoMotor.attach(servoPin);
  servoMotor.write(0); // Initial position (door open)

  Wire.begin();
  mpu.initialize();
  Serial.begin(SERIAL_BAUD_RATE);
}

void loop() {
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2;

  if (distance < 20) { // If distance < 20 cm
    servoMotor.write(90); // Close the door
    delay(2000);          // Wait for person to enter
    digitalWrite(relayPin, HIGH); // Lock the door
    delay(1000);          // Short delay
    digitalWrite(relayPin, LOW);
  }

  if (digitalRead(hallPin) == LOW) {
    Serial.println("Alert! Box is being tampered with!");
  }

  int16_t ax, ay, az;
  mpu.getAcceleration(&ax, &ay, &az);
  if (abs(ax) > 1500 || abs(ay) > 1500 || abs(az) > 1500) {
    Serial.println("Alert! Box motion detected!");
  }
  delay(500); // Delay for stability
}

This code initializes the various components and continuously monitors the ultrasonic sensor for proximity, the Hall sensor for tampering, and the MPU6050 for motion. It controls the servo motor to close the door and the relay to lock it, and sends alerts via the Bluetooth module when tampering or motion is detected.