Bag Movement Alarm for Theft Prevention

by micahmelnyk in Circuits > Microcontrollers

41397 Views, 339 Favorites, 0 Comments

Bag Movement Alarm for Theft Prevention

clean pic of completed project.jpg
Arduino based bag movement alarm in action

In short: I developed a portable, battery powered device that sounds an alarm when your bag or purse is moved. Once armed, can only be turned off by your secret code.

The device is built off an Arduino compatible Trinket Pro, using an off-the-shelf project box with PCB.

----------------------------------------------------------------------

Problem I had:

When I go to a happy-hour or a cocktail party, I often have my computer bag with me. But I do not want to carry it around with me, so I put it down somewhere, hoping that no one takes it. I may check on it periodically, or stand so that my bag is in my view, but I am still concerned someone may take it. Or I may be traveling, taking a nap at an airport or when waiting for train and be concerned that it might disappear while I am sleeping. Or any number of circumstances in my life where I need to protect my bag from being stolen.

Solution I built:

I built a small, portable alarm to warn when my bag has been moved. It is 9V battery operated, but without an on/off switch, otherwise the potential thief could just hit the off button. As a result, I have an 'arm' button, and then you have 20 seconds to but the bag/purse + device stationary. After being armed, if the bag/device is moved for more than 5 seconds and above a threshold level, it sounds an alarm until the correct code is entered. The secret code uses a 4 button interface, but the code can be any length.

Genesis / special motivation:

My parents were recently traveling abroad, and their bag (with their camera) was stolen while they slept. I decided to build this for them for a Christmas present, so that they would not have to go through that again. I was thus forced to build this over the course of December, which was great motivation.

----------------------------------------------------------------------

If you want more info on how I made this:

I also blogged about making this (and the challenges I faced along the way) on my personal blog at MakerSelf.com.

----------------------------------------------------------------------

Improvements are coming! Improvements are coming!

I have been blown away by the interest in this project. Thanks to all the helpful comments I have received here and other inputs I have received, I intend on making an improved version of this project. Right now, I am thinking about adding a rechargeable battery and RF/Bluetooth. If you would like to be updated when that project is done feel free to sign up for updates (I can't embed a form here, so that is a direct link to a form to sign up to get updates). I don't intend on sending out very many updates: I am fairly lazy and hate email!

Putting this up publicly and having a signup is in part to give me motivation to complete the improvements: if there is a lot of interest, I will find the time!

Gather Your Components

Obtain or purchase the following components:

Core components:

  1. A Trinket Pro as the brains of the show. You can get one from Adafruit or Hackaday.
  2. An accelerometer to tell when the device is moving. You can use a variety, but I used the GY-521 available from Amazon or Deal Extreme (or many other sources). The GY-521 is a bit overkill, as it also includes a gyro that I did not use in the product, but it was relatively affordable compared to commonly available accelerometers.
  3. A speaker/peizo to act as an alarm. You can use various depending on your preference for sound, but I used this one from RadioShack. I chose it based on the loud sound but low current consumption, and that it takes a broad range of voltages (3V-28V) so I wouldn't need to be too fussy about battery voltage.
  4. Four buttons to input a code
  5. One button to turn the device on, paired with a power circuit that allows the device to be turned on by hardware (the button), but off by software (by putting a pin to low)
  6. Two LEDs: one green LED to tell status, and one yellow LED as a low battery warning

Other components include:

  1. Project box. I used a project box with an integrated PCB and battery compartment, available from Amazon.
  2. Piece of perf board (doesn't need to be very big, just enough to cover one end of the project box)
  3. 2x P-Channel MOSFET transistor. From Mouser here. These are TO-92 packages, so fairly small. The max current is below what I anticipate would ever be needed to power all the components.
  4. 2x N-Channel MOSFET transistor. From Mouser here.
  5. 2x 330 ohm resistor (for current limiting on the LEDs). This does not have to be the exact resistance value, but in the general ballpark.
  6. 12x 10k ohm resistor (for ground ties, battery monitor pin voltage divider, etc.). The ground ties don't have to be exactly 10k, but just high enough, and the voltage divider just needs to be two the same value. I also tried 1k for these and it worked just fine.
  7. 1x 47k ohm resistor (for current limiting for the battery monitor pin). Also doesn't need to be exact.
  8. 1x 100nF capacitor (for dealing with any spikes on the battery monitor pin)
  9. 1x 6 pin female header
  10. 2x 12pin male headers (for the Trinket Pro, and may come with your Trinket Pro)
  11. 1x 9V battery clip
  12. 1x 9V battery
  13. Hook up wire (multi color if you want to keep things straight for yourself)
  14. Some thin foam padding (e.g. from envelope padding). This is optional, to make the battery fit more snug.

Gather Your Tools

tools.jpg
Dremel.jpg
file.jpg

To complete this project you will need:

  • Soldering iron and solder
  • Hot glue gun
  • Dremel or similar saw (for cutting the perf board)
  • File (for filing the cut perf board)
  • Helping Hands and tweezers, for helping to hold and place the components
  • Wire snips
  • Wire stripper

Plan How to Lay Out the Components on the PCB

project box blank.jpg
schematic.jpg
wiring fritzing.jpg
circuit layout on pcb.jpg

I had prototyped this on a breadboard, so to make this an actual project I had to think about how to lay out the PCB. The PCB I used is the board that came with the project box, which you can see in the photo of the project box and components.

I put the schematic, fritzing wiring diagram, and the diagram of the layout on the PCB in the pictures.

For the Fritzing wiring diagram: I have used orange to indicate 9V rail (stripped indicates that it is only sometimes on), and red to indicate 5V rail. Ground is consistent as black. Yellow connects to the LEDs, Cyan to the push buttons, purple is the input to the battery monitor pin, blue is the SCL and SDA for the accelerometer, and green are the two switching pins (to turn the power circuit on and the speaker on.

For the layout on the PCB: I laid all the components out on the board by drawing it out on a piece of paper (just made it easier). The end result is in the picture, and some comments to explain how it works:

  • The two headers for the Trinket Pro are marked in the light blue boxes, with the USB port for the Trinket Pro pointed to the left. The headers I used on the Trinket Pro had enough space so I could run wires underneath it (you can see the gold, green, pink, red wires all underneath the board. These components and wires are actually placed on the OTHER side of the board, with the soldering on this side. For the GY-521, I actually soldered on a header, and then put the GY-521 into the header. I had enough head room (barely) in the project box to do this and it made it easier to fit the wires underneath the GY-521.
  • The grey lines are passive components, and are marked as what they are (e.g. 10k is a 10k ohm resistor).
  • The black, red and orange squares are ground, +5V and +9V rails. You will need to solder all connections in this square together.
  • The transistors are in an arrow head pattern, allowing the drain of the N-Channel MOSFETS to go directly to the gate of the P-Channel MOSFET. The top of the arrow head is the common source (+9V) for the two P-Channel MOSFETs. With the TO-92 packages, the P and N MOSFET pairs should either face each other or have their backs to each other. The left ones should face each other (rounded part towards rounded part) and the right ones should have backs to each other (flat part towards flat part). Confirm the pin layout for your transistors.
  • The five buttons and the two LEDs go on a piece of perf board that would replace the end piece of the project box was removable (see the small black rectangular piece in the project box picture above. Where those connections are (buttons and LEDs) are marked on the diagram above. Additional external connections are the battery + and - from the battery clip, and the speaker would just hang loose and be stuffed in on top of the Trinket Pro when closing up the box.

Cut the Perf Board

perf board traced.jpg
cutting perf board 1.jpg
cutting perf board 2.jpg
filing perf board.jpg
perf board match.jpg
perf board testing in project box.jpg

The easiest way to mount the buttons is to cut a piece of perf board the same size as the end piece for the project box. To do this:

  1. Trace out the piece from the project box on a piece of perf board (see pic 1)
  2. Then cut it with a Dremel (see pics 2 and 3)
  3. Then file the perf board (see pic 4) so it matched the piece from the project box pretty exactly (see pic 5)
  4. Finally, make sure the perf board fits nicely in the project box before proceeding (see pic 6)

Solder the Perf Board

soldering LED 1.JPG
soldering LED 2.JPG
soldering LED 3.JPG
soldering buttons 1.JPG
soldering buttons 2.JPG
soldering buttons 3.JPG
soldering buttons 4.JPG
soldering buttons 5.JPG

It is easier to solder to the components on the perf board first, and then solder the other end of the wire to the project board.

After laying out the buttons and the LEDs on the perf board to get a sense of where they will go:

  1. Solder the LEDs (excuse the abundant and poor quality soldering in the pics 1 and 2!).
  2. Solder on the buttons. The easiest way is to loop the wire into the perf board (through a hole under the button), and then out the hole where the leg of the button would be coming out. This way, they are both coming out the same direction and it made it a lot easier to solder. You can see the loops in pic 3. Make sure that you put the loops on opposite sides of the button, so that they are not connected normally. Then place your button on top of the loops (pic 4) and squish it down (pic 5).
  3. Solder wires to the two ends of the button on the opposite side of the perf board (pic 6) I also put a little solder on the unused legs, just for additional physical support. Complete this for the rest of the buttons (pic 7 and 8).

Solder the Project Board

soldering project board 1.jpg
soldering project board 2.jpg
soldering project board 3.jpg
soldering project board 4.jpg
soldering project board 5.jpg
soldering project board 6.jpg

It takes a fair amount of time to solder the board. Start with placing all the passive components and wires on the board, and then turning it over and soldering all of those components.

The board that comes with the box is a one-sided board. Place all the components on the side that does NOT have the plating, and then solder on the side that does have the plating. In many cases, there are multiple things that go into the same hole (e.g. resistor and a wire) so make sure you get both in there before soldering it up.

  1. First, do the transistors, resistors for the power circuit and wires that run to them from the Trinket Pro pins (pic 1). I used little loops of wire to run the ground link from the source of the N-Channel MOSFETs (pic 2), and then the wires that would come from out from under the Trinket Pro go through them. Always be conscious that you need to put the Trinket Pro overtop of these wires.
  2. I had red and black hook up wire, so the red was power and the black was ground and logic wires (pic 3 is clearest on this).
  3. Periodically (when done a section), flip it over and solder those components (see pic 4).
  4. Then add the other components and wires in a step by step fashion (pic 5), following the PCB layout from earlier. Pic 6 shows it nearly complete, but still a few wires to add in the above (e.g. from SDA and SCL to the Trinket Pro).

NOTE: do not complete soldering on this board, as you still need to connect the perf board wires to the project board. Where there are holes that the wires from the perf board will come in or holes where the Trinket Pro will be added, hold off else you will not be able to make the connection if you do the soldering already.

Solder the Connection Between the Perf Board and the Project Board

connecting project board and perf board 1.jpg
connecting project board and perf board 2.jpg

Connect the two boards by soldering the wires from the perf board to the right spot on the project board. You should not have soldered these connections yet.

  1. Start with one button (in pic 1, the power button).
  2. Then complete the rest of the connections (pic 2). Note: in this pic, I had temporarily removed the header for the the GY-521 while doing this soldering, and soldered it on later.

Add the Trinket Pro

adding trinket pro 1.JPG
adding trinket pro 2.JPG
adding trinket pro 3.JPG

In order to add the Trinket Pro to the board:

  1. Insert the Trinket Pro over top of the wires in the center of the board. This is why you needed to keep the wires low profile and tight to PCB for those that will end up under the Trinket Pro. The Trinket Pro has some space under it with the headers, but not a lot.
  2. Then flip it over and solder the remaining pins.

Insert Accelerometer and Finalize Soldering

insert accelerometer.JPG

Finalize any soldering (e.g. ground rails) and insert the GY-521 accelerometer into the header. I made the accelerometer fit into a header as it made it easier to have the wires underneath it (it did not have as much space as the Trinket Pro under it if directly on the PCB). I would have done the same for the Trinket Pro, but the room above the Trinket Pro was not enough inside the project box, so I needed to put it directly on the PCB.

Upload the Sketch to the Board

program the board.jpg

Really, you could upload the sketch first, but you will possibly need to upload a revised version to the Trinket Pro here anyway to do some modifications (e.g. flip the pins for the LEDs if they are connected to the wrong ones).

The Trinket Pro requires you to take a few steps to get code to upload. You can read about it at Adafruit, or you can also read more at MakerSelf (my personal blog) as to how to do this.

The sketch is attached (alarmbox.ino).

IMPORTANT: Before you upload the sketch, set your secret code in the sketch. This is in the section marked " --SECRET CODE-- " along with all the other user changeable parameters. If you change the length of the code (eg. 4 digits instead of 7 digits), make sure you also change the "secretCodeLength" to reflect the new length.

You can also change all the other parameters, such as sensitivity or how long upfront you have to put the device stationary (starts as 20 seconds).

Downloads

Test the Device and User Interface

Arduino bag movement alarm soldered and working (outside of box)

The project should work now. Test it out. Make sure it works and the user interface is working fine and that the different elements of the user interface make sense for you. Now is the time to change any of these elements, as once you put it into the project box it will be very hard to make the changes.

You can see a video of the test above.

The user interface is as follows. The [x] indicate changeable elements (hard coded in the top of the sketch).

(1) Device is normally off. Press and hold power button for 3-5 seconds to turn device on; wait for the Status LED [green LED] to turn on.

(2) After powering up, Status LED will blink for [10] seconds. During this time the user must enter the [secret code]. This is to ensure against turning on accidentally as well as to ensure that user remembers what the code is before the device gets armed. If the user does not successfully enter the secret code during this time, the device turns itself off.

(3) After successfully entering the code, the Status LED will turn solid on. This indicates that the device is giving the user time to put the device stationary, in this sketch [20] seconds.

(4) The Status LED turns off, indicating that the device is now armed and listening to the accelerometer. If there is movement, the Status LED blinks slightly to indicate movement.

(5) If there is movement for more than [5] seconds and above [threshold], the alarm goes off and turns the Status LED solid on. The alarm stays on until the user enters the secret code.

(6) Once the device is on, if the user enters the secret code after or during the settling time, the Status LED will blink once long, then three short, and then then the device will turn itself off without turning the alarm on.

(7) If the battery is low voltage, set as below [6.5] volts, then when the Status LED is turned on in step (1) or in (5) or (6), the Battery Low Voltage LED [yellow LED] will turn on solid on.

Put the Project PCB Into the Project Box

insert board into project box 1.JPG
insert board into project box 2.JPG
insert board into project box 3.JPG

Insert the screws into the holes of the project board (I could only get three in there, which was good enough, see pic 1), and then insert the project board into the bottom box and screw the screws in (see pic 2).

Then add some hot glue to the battery connection wires, so they don't get pulled on at the connection to the project board (pic 3).

Put the Perf Board Into the Project Box

insert perf board into project box.JPG

The perf board was cut to fit the end piece exactly, so slide it in were the end piece would have gone. You can discard of the end piece for the project box.

Close Up the Project Box

close project box 1.JPG
close project box 2.JPG

Squeeze the wires into the box and close the box, placing the buzzer (which up to now has been hanging loose) on top of the Trinket Pro. This can be a bit of a challenge, and will likely required bending the wires a fair amount to fit it all in, particularly the wires to the buttons from the 5V rail on the close side of the project board (in pic 1).

Then screw in the screws for the project box, and attach the battery (see pic 2).

Add Padding for Battery (optional)

battery padding 1.JPG
battery padding 2.JPG
battery padding 3.JPG

If the 9V battery is not quite snug, you can add some padding to battery compartment.

Use some thin foam padding and hot glue it into the box. When doing this, put the hot glue in the project box, and then wait a few seconds to let it start to cool down. On the first time, I did not and the hot glue melted the foam a bit.

Put the Battery Cover On. You're Done!

Arduino based bag movement alarm - final completed project

Add the battery cover, and now it is ready for use.

Final, completed device in action in the video.