Personal Item Security Guard

by jouwmaatsenna in Circuits > Arduino

61 Views, 1 Favorites, 0 Comments

Personal Item Security Guard

IMG_4319.jpg
IMG_4320.jpg
Personal Item Security Guard

I've made a Personal Item Security Guard that alarms the surrounding area whenever your valuable item that you placed on the pedestal has been stolen!

Supplies

Main Components


Arduino Uno

PIR motion sensor

DFPlayer Mini MP3 player module

Servo motor

Speaker

SD card with audio file

Breadboard

PCB breadboard

Wires

Power source (USB cable or battery pack for Arduino)


Components for Casing/Decoration


2 printed illustrations of a security guard, awake on one side, asleep on the other (customise or change these pictures any way you like!)

Single-sided tape

Double-sided tape

A skewer

Wood

Wood glue

Screws

Magnet

(Optional) Speaker mesh cloth


Tools


Soldering iron

Tin

(Optional) S-39 soldering liquid

Circular saw

Hole saw

Screwdriver

Glue gun

Small Description & Earlier Ideas and Iterations

Using a PIR motion sensor, whenever movement is detected, in this case an item being taken, it activates a servo motor arm and a DFPlayer Mini MP3 player module. The servo motor arm rotates 180 degrees, from an image of a sleeping security guard to an active one, giving the impression of the guard waking up. The player module will then play audio through a speaker, alarming the thief and warning them about the consequences of their actions. It happens way too often that I leave my room and my little brother comes in with evil thoughts of stealing my belongings and hiding them. Using this device, I'll even hear when my belongings are being taken from downstairs!

When I started this project I struggled a lot with coming up realistic concepts. My first idea was to build a weather sensor with digital illustrations on an LCD based on what weather it is, but that seemed too complicated, and you always need to look further than your first idea. After a whole lot of thought I came up with this idea.

I initially wanted to stick to LCD screens for the security guard, which would've been fun, but by using printed out images, the idea would be a lot easier to customise. I also wanted to voice the audio file myself, but found a text to speech voice to (surprisingly) be more fun and "threatening" :)

Prepare Components

IMG_4301.jpg
IMG_4302.jpg

Prepare the illustration


Print the illustrations of a security guard with one side awake and the other side asleep. Stick the two of them together and attach them on a wooden/metal skewer with the help of some double-sided tape and/or glue. Additionally, you can create some wooden supports with some trimmed skewers to stick in between the two images if you want more stability.


Prepare the SD card


Format the SD card to FAT32 and load it with your desired audio file(s). Name the file 0001.mp3.


Connect the Components

arduino breadboard graphic.png

Insert the SD card into the DFPlayer Mini and proceed with connecting the components to the Arduino and breadboard according to the provided image.

Important to know: On the image provided it says that the PIR Motion Sensor's signal pin that is supposed to connect to digital pin 2 on the Arduino, is located in the middle. To my knowledge, this can differ from sensor to sensor, the power and signal pin (left and middle) may be swapped in position.

Upload the Code

Screenshot 2024-06-30 232424.png

Install libraries


  1. Open the Arduino IDE.
  2. Go to Sketch -> Include Library -> Manage Libraries.
  3. Search for and install DFRobotDFPlayerMini and install it.

The DFRobotDFPlayerMini Library is the only one you need to install, the rest (Servo Library & Software Serial) are pre-installed with Arduino IDE.


Upload the Code


Copy and paste the provided code into your sketch and upload it to your Arduino:

//Include libraries
#include <Servo.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>


//Assign Arduino digital pins
const int pirPin = 2;                       //PIR sensor output pin
const int servoPin = 9;                     //Servo control pin
const int busyPin = 6;                      //DFPlayer Mini busy pin


//Define instances
Servo myservo;                              //Servo motor
SoftwareSerial mySoftwareSerial(10, 11);    //SoftwareSerial for DFPlayer Mini
DFRobotDFPlayerMini myDFPlayer;             //DFPlayer Mini


//Define variables
bool isPlaying = false;                     //Audio-playing state
unsigned long lastMotionTime = 0;           //Last time motion was detected
unsigned long motionDetectedTime = 0;       //Time when motion was detected
const unsigned long debounceDelay = 5000;   //Debounce delay in milliseconds
const unsigned long audioDuration = 16000;  //Duration of the audio in milliseconds


void setup() {
  Serial.begin(9600);                       //Initialize serial communication
  mySoftwareSerial.begin(9600);             //Initialize software serial for DFPlayer Mini


  myservo.attach(servoPin);                 //Attach servo to servoPin
  pinMode(pirPin, INPUT);                   //Set pirPin as input
  pinMode(busyPin, INPUT);                  //Set busyPin as input for DFPlayer Mini


  //Initialize DFPlayer Mini
  if (!myDFPlayer.begin(mySoftwareSerial)) {
    Serial.println(F("Unable to begin: Check connection or SD Card"));
    while (true);
  }
  Serial.println(F("DFPlayer Mini online."));


  myDFPlayer.volume(24);                    //Set volume
  myservo.write(0);                         //Initialize servo position
}


void loop() {
  int pirState = digitalRead(pirPin);       //Read PIR sensor state
  unsigned long currentMillis = millis();   //Current time in milliseconds


  Serial.println(pirState);                 //Print the state to the Serial Monitor for debugging


  //If motion is detected, record the time
  if (pirState == HIGH && !isPlaying) {
    motionDetectedTime = currentMillis;
  }


  //Check if valid motion is detected and debounce delay has passed
  if (pirState == HIGH && !isPlaying && (currentMillis - lastMotionTime >= debounceDelay)) {
    Serial.println("Motion detected!");
    playAudioAndRotate();                   //Call function to play audio and rotate
    lastMotionTime = currentMillis;         //Update last motion time
  }


  //Check if audio finished playing
  if (digitalRead(busyPin) == LOW && isPlaying && (currentMillis - lastMotionTime >= audioDuration)) {
    Serial.println("Audio finished!");
    isPlaying = false;                      //Update audio-playing state
    rotateBack();                           //Rotate servo back to initial position
  }
}


void playAudioAndRotate() {
  isPlaying = true;                         //Update audio-playing state
  Serial.println("Playing audio and rotating servo...");
 
  // Smooth servo movement to 180 degrees
  for (int pos = 0; pos <= 180; pos += 1) { // Change 1 to adjust speed
    myservo.write(pos);
    delay(0);                               // Change delay to adjust speed
  }


  // Play audio file
  myDFPlayer.play(1);                       //Play audio file
}


void rotateBack() {
  Serial.println("Rotating servo back...");
 
  // Smooth servo movement back to 0 degrees
  for (int pos = 180; pos >= 0; pos -= 1) { // Change 1 to adjust speed
    myservo.write(pos);
    delay(15);                              // Change delay to adjust speed
  }
}

Testing and Troubleshooting

Power On your Arduino using the USB cable or battery pack.

Open the Serial Monitor in the Arduino IDE to check the output and ensure the PIR sensor is detecting motion properly and triggering the servo and audio.

Adjust PIR Sensitivity if necessary by using the orange adjustment knobs on the PIR sensor to change its sensitivity and time delay settings.

Soldering

IMG_4309.jpg

Remove the components from the breadboard one by one.

Solder the wires directly to the components on the PCB breadboard as per the connections in Step 2. Ensure that the connections are secure and insulated to prevent short circuits.

S-39 soldering liquid is a chemical compound that helps prepare the metal surfaces for soldering by removing oxides, promoting wetting, and enhancing the flow of solder. You can definitely solder without, but I heavily recommend it as it made the process much easier for me. :)

Making the Casing

IMG_4303.jpg
IMG_4306.jpg
IMG_4304.jpg
IMG_4310.jpg
IMG_4307.jpg
IMG_4311.jpg
IMG_4312.jpg
IMG_4318.jpg

The Case Itself


Make a wooden box that can hold all the components. The front of the cube sticks out, serving as a platform for your personal item. I decided to make the case out of white wood, it blends in with the majority of my home's furniture and that way the object doesn't seem to out of place, but you can decorate the cube however you would like!


Drill Holes


Drill holes for the Arduino USB cable port, PIR motion sensor, servo motor arm and speaker into their respective walls, the servo motor has to specifically be screwed into the top wall.


Mount Components


Use small screws or glue to mount the Arduino, PIR sensor, speaker, servo motor and PCB breadboard inside the enclosure. Because of some of my soldering sticking out a bit, i used some plastic tubes to prop up the breadboard while it is screwed on.


Secure Wiring & Case


Ensure all wires are neatly secured inside the enclosure to prevent disconnections. Glue all sides of the box together and use some tape to keep the sides together while the glue dries. I also decided to screw in a magnet on the back of the top panel, so I could magnetically shut the back of the case with some screws and open it in case of any instances where I'd have to fix something internal.


Attach Image


Attach the image on the skewer to the servo motor arm through the hole in the top using some glue. Make sure to only glue onto the servo and not the sides of the hole, or the arm might not be able to rotate properly.


Add Speaker Mesh Cloth


Additionally, I decided add some speaker mesh cloth in front of the speaker hole, for aesthetic purposes. :)

Conclusion

You've now made your very own Personal Item Security Guard! Plug a USB cable into the back (into the Arduino USB port), put your incredibly valuable item in front of the sensor and enjoy a life without worry as your security team keeps a watchful (but sleepy) eye on your belongings!


Reflection


This project has been a very good introduction to combining hardware and software to create an interactive system. It has boosted my confidence in tackling more complex projects in the future and has improved my abilities in both documenting and finding errors in a process, as I often forget to document progress when working on a project, and I was able to fix certain issues, like the motion sensor constantly detecting motion. This project provided a basic, strong foundation in embedded systems, electronics, programming and soldering.