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!
Step 1: Gather your components
Obtain or purchase the following components:
Other components include:
Step 2: Gather your tools
To complete this project you will need:
Step 3: Plan how to lay out the components on the PCB
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:
Step 4: Cut the perf board
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:
Step 5: Solder the perf board
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:
Step 6: Solder the project board
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.
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.
Step 7: Solder the connection between the perf board and the project board
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.
Step 8: Add the Trinket Pro
In order to add the Trinket Pro to the board:
Step 9: Insert accelerometer and finalize soldering
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.
Step 10: Upload the sketch to the board
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).
Step 11: Test the device and user interface
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  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  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  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.
Step 12: Put the project PCB into the project box
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).
Step 13: Put the perf board into the project box
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.
Step 14: Close up the project box
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).
Step 15: Add padding for battery (optional)
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.
Step 16: Put the battery cover on. You're done!
Add the battery cover, and now it is ready for use.
Final, completed device in action in the video.