Arduino UNO-Based Smart Anti-Theft Security System with Bluetooth and Motion Detection
View and Edit Project In Cirkit Designer
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
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
Micro Servo 9G
- Description: Small servo motor used for precise control of angular position.
- Pins: GND, +5V, PWM
Ultrasonic Sensor
- Description: Sensor used to measure distance by using ultrasonic waves.
- Pins: +VCC, Trigger, Echo, GND
Relay Module 5V-30V
- Description: Relay module used to control high voltage devices.
- Pins: Common contact, Normally open, Normally closed, Trigger, V-, V+
12V Solenoid Lock
- Description: Electromechanical lock that can be controlled electronically.
- Pins: VCC, GND
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
Hall Sensor
- Description: Sensor used to detect the presence of a magnetic field.
- Pins: -, +, S
HC-05 Bluetooth Module
- Description: Bluetooth module used for wireless communication.
- Pins: Key, VCC, GND, TXD, RXD, State
12V Battery
- Description: Power source for the circuit.
- Pins: VCC, GND
Wiring Details
Arduino UNO
5V connected to:
- Micro Servo 9G (+5V)
- Ultrasonic Sensor (+VCC)
- Relay Module 5V-30V (V+)
- MPU6050 (VCC)
- Hall Sensor (+)
- HC-05 Bluetooth Module (VCC)
GND connected to:
- Micro Servo 9G (GND)
- Ultrasonic Sensor (GND)
- Relay Module 5V-30V (V-)
- MPU6050 (GND)
- Hall Sensor (-)
- HC-05 Bluetooth Module (GND)
A4 connected to:
- MPU6050 (SDA)
A5 connected to:
- MPU6050 (SCL)
D11 connected to:
- Relay Module 5V-30V (Trigger)
D10 connected to:
- Micro Servo 9G (PWM)
D9 connected to:
- Ultrasonic Sensor (Trigger)
D8 connected to:
- Ultrasonic Sensor (Echo)
D7 connected to:
- Hall Sensor (S)
D1 connected to:
- HC-05 Bluetooth Module (RXD)
D0 connected to:
- HC-05 Bluetooth Module (TXD)
Micro Servo 9G
GND connected to:
- Arduino UNO (GND)
+5V connected to:
- Arduino UNO (5V)
PWM connected to:
- Arduino UNO (D10)
Ultrasonic Sensor
+VCC connected to:
- Arduino UNO (5V)
Trigger connected to:
- Arduino UNO (D9)
Echo connected to:
- Arduino UNO (D8)
GND connected to:
- Arduino UNO (GND)
Relay Module 5V-30V
Common contact connected to:
- 12V Battery (VCC)
Normally open connected to:
- 12V Solenoid Lock (VCC)
Trigger connected to:
- Arduino UNO (D11)
V- connected to:
- Arduino UNO (GND)
V+ connected to:
- Arduino UNO (5V)
12V Solenoid Lock
VCC connected to:
- Relay Module 5V-30V (Normally open)
GND connected to:
- 12V Battery (GND)
MPU6050
VCC connected to:
- Arduino UNO (5V)
GND connected to:
- Arduino UNO (GND)
SCL connected to:
- Arduino UNO (A5)
SDA connected to:
- Arduino UNO (A4)
Hall Sensor
- connected to:
- Arduino UNO (GND)
+ connected to:
- Arduino UNO (5V)
S connected to:
- Arduino UNO (D7)
HC-05 Bluetooth Module
VCC connected to:
- Arduino UNO (5V)
GND connected to:
- Arduino UNO (GND)
TXD connected to:
- Arduino UNO (D0)
RXD connected to:
- Arduino UNO (D1)
12V Battery
VCC connected to:
- Relay Module 5V-30V (Common contact)
GND connected to:
- 12V Solenoid Lock (GND)
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.