Introduction: Backpack Anti-Theft Alarm

Picture of Backpack Anti-Theft Alarm

If you're a student, like me, then you have heard of all the theft that occurs on campuses today. I can't even leave my backpack alone for five minutes without worrying about it getting stolen. To ease my mind and to help fellow students, I've designed a backpack ant-theft alarm. When activated, this device senses when a backpack is picked up and sounds an alarm to draw attention to the thief. The alarm is perfect for quiet places such as libraries or classrooms where a buzzer would be heard clearly. It is a great project for beginners and experienced electronics hobbyists alike!

The backpack anti-theft alarm is powered by an ATtiny85 and functions using an ultrasonic range sensor (HC-SR04) to calculate distance from the backpack to the ground and a 5V buzzer to produce an alarm. Once the backpack is above a certain distance, the buzzer sounds and does not stop until the device is turned off. To provide the most security, you must enter a 5-bit binary code to turn the device off. This code is made using 5 SPDT switches, (by connecting them in a way that only one combination connects the circuit to ground). If mounted to a backpack correctly, this device can provide excellent security against backpack theft!

Throughout this instructable, you will learn an innovative way of protecting your circuits using binary code, how to interact with the HC-SR04, how to use ATtiny85s, and you'll have a more secure anti-theft backpack! Let's get started with our parts list!

Step 1: Get Parts!

Picture of Get Parts!

You'll need these parts:

-Project Box (3.34"L x 1.96"W x 0.83"H)

-10K Ohm Resistor

-330 Ohm Resistor

-Green 5mm LED

-HC-SR04

-Two CR2032s

-Coin-cell Battery Holder

-SPDT Slide Switches

-Perfboard

-ATtiny85 (with socket)

-5V Buzzer

-1N4007 Diode

-2N3904 Transistor (NPN general purpose)

-2.54mm Connectors

You'll need these tools:

-Computer

-Wire Stripper

-Dremel

-Soldering Iron (with rosin)

-Hot Glue Gun (with sticks)

-Multimeter (optional)

-Arduino (for programming ATtiny85)

Step 2: Solder Main Components

Picture of Solder Main Components

Let's begin by soldering our main components to our perfboard. Before you solder, make sure you map out which holes in your perfboard will line up correctly with the project box. Check that the HC-SR04 and buzzer are positioned correctly so that they will be able to protrude from the enclosure later on.

Now that you have an idea of what goes where, heat up your soldering iron and solder the HC-SR04, coin-cell holder, buzzer, female 2.54mm connector, and 8-pin DIP socket to the perfboard.

When all your major components are soldered in the correct positions on your perfboard, we can start making our 5-bit security switch!

Step 3: Make Security Switch

Picture of Make Security Switch

Our security switch is going to ensure that only the owner of the backpack alarm can turn it off. Using 5 SPDT switches, we can make a single 5-bit security switch which is off only when one combination of 0s and 1s are entered.

To start the switch, use your wire cutter (or metal cutter) to snip any excess metal on your switches (see pictures). Then hot glue each switch to the last. Make sure you hot glue both sides to make a firm bond. Continue these steps until all 5 switches are straightly and strongly bonded together.

To get our security switch working we will have to move on to the next step to wire our switches!

Step 4: Wire Security Switch

Picture of Wire Security Switch

To wire the switch requires a little knowledge about SPDT switches. Single Pole Double Throw switches have two positions and connects the center terminal to either the upper or lower terminal. This switch is perfect for our purposes. We can treat the upper terminals as 1, and lower as 0s.

We will use two wires that we can name: GND and OUT. First, connect all the center terminals to OUT. To make the switches code, connect GND to either the upper or lower terminal on each switch and randomly alternate to create a pattern. Each terminal that is left with no connection will be the correct code to turn off our switch. This is because if any switch is not in the correct position, it will connect the circuit. You have to have all 5 switches in the correct position to turn the device off. Finally, connect our GND and OUT wires to a 2.54mm two pin male connector. To protect your switch, use hot glue to hold all loose wires in place.

When your security switch is connected properly, and you have wired your 2.54mm male connector, we can finish soldering the main perfboard.

Step 5: Solder Connections

Picture of Solder Connections

Now that we have soldered the security switch and main components, we can finish the circuit by connecting our main components to the ATtiny85!

Using the attached schematic (see 5th picture) connect the HC-SR04, buzzer, indicator LED, power supply, and security switch to the appropriate arduino pins. In case you have difficulties reading a schematic, here are the connections that you will have to make:

-For the HC-SR04: VCC -> 5V, TRIG -> ATtiny pin 7. ECHO -> ATtiny pin 3, GND -> GND.

-For the indicator LED, connect a 330 ohm resistor to the positive lead on your 5mm LED then connect the negative lead to GND (all in parallel with the ATtiny85).

-For the "power supply" all we need to do is connect a 1N4007 from the 6V supply (coming from our two 2032s) to the ATtiny's VCC (pin 8). This is to drop the voltage down to a safe operating voltage for the ATtiny85 (it must be no higher than 6V).

-To get the buzzer working, we need a transistor. This is because we want the buzzer to be as loud as possible, and if we just supplied it with an ATtiny pin, it wouldn't have much current (or voltage). So connect ATtiny pin 5 to the base of a transistor via a 10k resistor. Next connect 6V from our batteries to the transistor's collector, and the buzzer to its emitter. Finally connect the other end of the buzzer to GND.

-To connect the security switch, connect GND to the previously named GND connection on the switch and finally, OUT to the GND of our ATtiny85 chip.

Now our circuit should be connected and ready for the code.If you're having trouble with the circuit, refer back to the schematic and don't hesitate to ask a question in the comments. Let's move onto uploading the code in the next step!

Step 6: Upload Code

Picture of Upload Code

The code is very simple, it should even be easy for all you beginners! If you're new to coding I suggest looking at the code and thinking of some lines as just some psudo-code. For example, check out this code:

//getDistance:

long duration, distance;
digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = (duration/2) / 29.1;

Looks confusing, right? Well actually it is! So it is best to just think of all those lines as one function that gets the distance. Interfacing with a complex module like the HC-SR04 can be confusing and that's why there are libraries written for it!

Be sure you look for some good documentation on how to program an ATtiny85! You will need another arduino (or programmer). Here is my favorite reference.

If my code confuses you or you are not quite code literate, please continue reading to learn about the basics of my code. (If this still doesn't answer your questions please comment below!). The first few lines of my code are just declarations and definitions of variables all of which are basic arduino syntax. In the setup() function I declare the pin modes to tell arduino what pins i'll be using for input or output. Also, I add a short delay for the user to get the device situated so that the alarm doesn't accidentally go off while setting it up. Finally, there is the loop() function. This function continuously checks the distance between the HC-SR04 and any object in front of it. If it ever exceeds the constant ALARM_DISTANCE, then the boolean variable "alarm" will become true. If that variable is true, the loop() executes a few lines to sound the alarm.

Finally our alarm should be beeping and working identically to the video shown in the introduction! However, it is still missing one thing: the case!

Step 7: Dremel Enclosure

Picture of Dremel Enclosure

To make the circuit fit in the enclosure, we need to dremel holes for the HC-SR04, buzzer, security switch and indicator LED. This should be a matter of guess and check for most of the way (as dremel work usually is), but there are some tips to help you out.

-Make sure you try to outline your cuts with ink before you begin so you know where and how large each cut should be.

-Be careful not to cut too much plastic out where you don't need to.

-Always cut from the inside so you don't accidentally scratch the outside of the case.

-Dremels are very dangerous. Wear gloves and stay away from the tip!

Once all the pieces of our circuit fit snug in their spaces, we can mount the security switch!

Step 8: Hot Glue Security Switch

Picture of Hot Glue Security Switch

Since our enclosure doesn't have room for screw mounting the switches, we have to mount them using either hot glue or epoxy. Make sure you place your security switch into your dremeled enclosure ensuring that it is straight and aligned in the correct direction.

Heat up your hot glue gun and use generous amounts of glue to mount the security switch to the project box. Use glue on both the outside and inside; however, be careful not to get glue inside of any of the switches since that will cause the switches to stop conducting.

Make sure your hot glue doesn't rise too far above the case since we will be closing the enclosure in our next step!

Step 9: Close Enclosure

Picture of Close Enclosure

Finally the circuit is complete, the case is all dremeled out, and the security switch is mounted! Now we can just snap on the back of the case and mount it right? Well most of the time it'll be that easy; however, we have to be careful that no components inhibit the back panel from snapping in,.

If you have trouble closing the case, check to see if any hot glue is blocking the case from closing and use a utility knife to cut it away. Also make sure no transistors, diodes, or leads are jutting out from the case that could prevent the enclosure from closing. Finally, check to see if the HC-SR04, buzzer, and LED protrude from the enclosure. If they aren't this could be stopping the case from closing. Use a dremel tool to enlarge the cuts you made before, so that the components slide through the holes and make room for the back panel.

Now that your backpack anti-theft alarm is all closed up and functional, we can mount it to your backpack!

Step 10: Mount It!

Picture of Mount It!

To use your new backpack anti-theft alarm, you will need to mount it to your backpack securely. In the event of a theft,,you don't want the thief to be able to simply remove the alarm. In the attached pictures, I show a simple way to quickly mount it to just about any backpack; however, it isn't the most secure option.

To make a more safe alarm you could mount using:

-Epoxy or hot glue

-Backpack clips

-Velcro

-Thread

If you find a secure way to mount your backpack anti-security alarm, please comment below with an attached picture!

Step 11: Secure Your Backpack!

Picture of Secure Your Backpack!

Finally you can enjoy the security of having your own backpack anti-theft alarm for some ease of mind this school year! I hope you've learned a lot about HC-SR04s, ATtinys, buzzers, making a security switch, and using the dremel tool. If you enjoyed this article and would like to support me, please vote for this instructable in the DIY University, Tech, or Microcontroller contests! Click here for more fun and rewarding projects. Thanks for your interest and enjoy your new device!

Comments

DarysyiniS (author)2016-08-12

hello, is AT tiny85 an IC? if so what is the serial number?? really urgent i need... thank you..

frankdark (author)2016-01-07

Good Day.
just want to ask if Atiny85 can read the data of Accelerometer
and transfer it to 433Mhz transmitter so the transmitter would send it
to the 433Mhz receiver on the other end?
:) Thanks for the future Help..

ariff.rahman.927 (author)2015-06-14

hello, i have a question regarding the safety switch. can i use tact switches for it ?

LordBlade (author)2015-05-02

hello there i'm currently doing a different type of alarm project but i would like to adopt your security switch idea. the think is i was a bit puzzled and convoluted with the wiring part of it and how implement it correctly in order to disable the alarm. would you be so kind to provide me with thurough explanation and tutorial?

mderbass made it! (author)2015-05-01

thanks , it was a great idea

ariff.rahman.927 (author)2015-02-10

hey, i noticed your video doesn't work, mind fixing it because i want to see how your alarm works ? :)

Thanks for your interest and letting me know! I haven't found any issues with playing the video on my computer. I'm using Chrome. Maybe try a different browser?

jveri27 (author)2014-12-12

Great Project :). I want to create one but in our country they did not have attiny85, is there any substitute for attiny85 ?

bergerab (author)jveri272015-02-01

Sorry for the late response, but yes! There are plenty of ATTiny85 substitutes. Assuming you don't want to change any of the code, I would suggest the following Arduino boards: Nano, Uno, or Micro.

zulboy45 (author)2014-11-25

thanks. i want to use it for my project microprocessor. may I?

handelb (author)2014-10-30

very useful device!!

can I program attiny85 using arduino uno?

ianyeo1994 (author)handelb2014-11-24

Yes you can

ibenkos (author)2014-10-18

Smart idea! I really like this project. Thanks for shearig :)

ianyeo1994 (author)2014-10-02

I know that it says to connect the resistor to ground but its not shown in the fritzing circuit diagram, is there any way to update or include it into the diagram so that its easier to see where it should be placed?

ianyeo1994 (author)2014-09-29

In the circuit diagram what is J1?

bergerab (author)ianyeo19942014-10-01

J1 is the label for the buzzer. Fritzing randomly gave it that name I'm not sure why, in the future I'll just remove that to avoid confusion. Thanks for the comment!

MSawyer (author)2014-09-08

Switches need to be wired in series {AND} not parellel {OR} .

bergerab (author)MSawyer2014-09-08

Hello! Thanks for the comment. I wired the switches in parallel which actually does work. You could look at it using either AND or OR logic (depending on what you're trying to define). Here is the boolean equation for our function "F". F = s1 OR s2 OR s3 OR s4 OR s5. This equation is correct since we want F to equal 1 in every circumstance other than all the switches being equal to: s1=0 s2=0 s3=0 s4=0 s5=0. I hope this answers your concern!

slimeph (author)bergerab2014-09-12

An OR will be true if any switch is TRUE. Based on the diagram, I think that only s1 is needed to be 'tried' to disable the alarm.

bergerab (author)slimeph2014-09-12

Exactly! If any switch is TRUE, the circuit will be closed (ON). You need to put all 5 switches in the correct positions in order to make the circuit open (OFF). Try implementing the circuit and you'll see what I mean. Thanks!

bergerab (author)2014-09-08

Thanks so much! If you get a chance to try it out yourself please post some pictures of your results!

webmanoffesto (author)2014-09-08

Thanks for the great project.

bergerab (author)webmanoffesto2014-09-08

No problem! Let me know if you get a chance to make it yourself. I'd love to see some pictures! Thanks

LockonStratos (author)2014-09-07

A really nice project. Simple and effective.

However I have some questions about whether this device is actually useful in some certain cases.
Case one, if the thief just open the backpack and took something from it without lift the backpack, the alarm wont be triggered.
Case two, if the thief simply smash the device by throwing it on the ground, is there anything we can do to make the device worked more effective? Like making the sounding part extremely sturdy so that it can take a heave hit on the ground?

As far as I have concerned, those kinds of cases may not be rare cases.
And a little suggestion on the sound level of the buzzer, maybe it's a little bit low and won't be able to alarm the people around, especially when people are focused on their own business(Maybe it is only too low on the video, never mind). But on the other hand it will cause a interrupt for the others.

But even with those short commings, there's no doubt that this idea is great. Well we all agree that nothing can be perfect. Looking forward to saw a new project comming out from you which can overcome the shorting commings.
At last, thank you for turning such a great idea into a real working stuff~~

bergerab (author)LockonStratos2014-09-07

Thanks for the comment! Yes of course there's always a way to break a security system, so there's going to be some shortcomings. (Even of home security!) For this alarm to be 100% safe you will have to lock all the zippers on your backpack. However, this device is pretty unbreakable when it's mounted to the backpack. For the thief would have to dismount the device, and if mounted securely that would be difficult. Not to mention if someone threw this device across the floor of a library it's likely everyone would be at least suspicious!

webmanoffesto (author)bergerab2014-09-08

This seems designed for a student at a university. He doesn't want the bag (and the laptop it) stolen when he puts it down for a minute in the library, or in a campus coffee shop.

BLR_RAVI (author)2014-09-04

very nice project

ch5 (author)2014-09-03

Nice Idea.

I especially like the 5 bit security switch thing, this is what commercial personnal alarms lack to be of any use.

You could improve your noise output by canibalizing one of those really cheap "window alarms" from any home improvement store.

(This kind :

http://i00.i.aliimg.com/photo/221015342/Door_And_Window_Alarm.jpg

)

They come in packs of 3-4 for a few bucks and are loud as hell.

All you have to do is remove their reed switch, and replace it with a transistor or optocoupler commanded by the Attiny.

They are my favorite cheap source of big noise for alarm projects :)

You
could even leave the reed swith in and add your control transistor in
parralel, so you'd retain the "alarm if magnet absence"
functionnality.You could then make any kind of arrangment for the magnet
to fall if the bag is lifted away, or fix it to something you don't
want separated from your bag without your knowledge.

seamster (author)2014-09-03

You've graduated to the awesome category.

Excellent idea and great documentation. Well done!

About This Instructable

44,796views

312favorites

License:

Bio: I'm a student at UW-Milwaukee studying computer science with a passion for electronics. I'm always working on a project or thinking of new ... More »
More by bergerab:Flame Controlled MIDI ControllerSOLO Cup SpeakerBackpack Anti-Theft Alarm
Add instructable to: