Introduction: Email Notification Capacitive Touch Doorknob Alarm (Phew!)
I have finally, amidst high school and other things, decided to have some fun and make my first instructable. If you have any feedback for me are questions you can write them down in the comments and I will try to answer them.
This instructable will walk you through how to set up a basic alarm system on the Arduino, as well as the more a more advanced version with the Raspberry Pi and a webcam, will send you an email with a picture when an intruder is detected. I will try my best to make this as easy as possible for the beginner, while not bogging down in the nitty-gritty of how everything works. For example, I will give you the code for the programs but not go through how they all work--however, I did leave some comments in the code so you can dissect it that way/. If you are a beginner I recommend trying the Arduino version, which is a fun and easy project. If you have more experience or like Raspberry Pi then try the webcam version.
What is Capacitance?
Capacitance is the ability to store an electrical charge, most often seen in electronics in capacitors. However, the human body (or any creature's body for that matter) also stores an electrical charge. Capacitance is measured in Farads, named after Micheal Faraday, a British electrochemist of the 19th century. Capacitive touch screens and capacitive buttons in smartphones and other devices use capacitance to tell when and/or where you are touching. The cool thing about capacitance as a sensor is you can use any metal object to probe and measure for it.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Breadboard It!
The simplest way to show and experiment with capacitance is through an Arduino microcontroller because of the fabulous library written by Paul Badger.
The wiring is fairly simple, just follow the diagram to breadboard it up.
-piezo or small speaker is connected to pin 3
- the red led is connected to pin 5
- the green led is connected to pin 6
-button is connected to pin 4
-aluminum foil is connected to pin 8 and pin 9 through 1 MOhm resistor
Done? Great, continue to the next step to program you Arduino
Step 2: Time to Code (Yay!)
The code here is pretty straightforward so I won't go over it too much, however, there are a few comments in the code so check them out for yourself.
Connect your Arduino to you computer and chose your board and serial port. Having trouble? Look at this link.
Then upload to your board!
The next step explains how the doorknob alarm works.
Step 3: Set Up the Alarm
The doorknob alarm starts by fading in and out both of the LEDs. It will not start detecting touch until you press and hold the button and wait for the green led to flash a couple of times. When the green LED stays on you know it is armed. Try touching the tinfoil and see if the alarm goes off and the red led starts flashing. If it does, congratulations! you've finished the alarm. Press the button once again to reset.
Now press the reset button on your Arduino and position the whole rig on the door. You can tape it like me or come up with a nicer looking enclosure. Tape the tinfoil to the doorknobs base or wrap it around an extrusion or screw, just try to make it so you can still turn the knob easily, but so that the tinfoil still touches metal. At this point, also set up your power system. You can use a wall power supply, just make sure it is between 7 and 12 volts and can supply enough current. Alternatively, you could use a battery pack, again checking it is between 7 and 12 volts. Once everything looks good you can press and hold the button so the green led starts blinking. Now, touch the doorknob and listen for the alarm.
Once you've had fun playing with this alarm, try your luck building the "smarter" version, complete with webcam and email notifications!
Step 4: Mmm, Dessert Time
For webcam and internet support, a microcontroller like the Arduino won't cut it. We need some thing more powerful, the Raspberry Pi!
The image above shows the extra components we will need in this section. We will need--a Raspberry pi with case, a wifi dongle, a webcam, and a GPIO cable plus cobbler.
SimpleCV is an image processing library for python that can be used with webcams to do all sorts of things like facial recognition, interfacing with XBox Kinect or just simple image manipulation. We will be using this library for our webcam alarm project. Here are the steps to download it.
1. Boot and log in to your raspberry pi. Default user and password are pi and raspberry respectively.
2. run a "sudo apt-get update" to update your system
3. type "sudo apt-get install ipython python-opencv python-scipy python-numpy python-pygame python-setuptools python-pip" and press 'y' when prompted
4. now type "wget https://github.com/ingenuitas/SimpleCV/master"
5. finally, type "pip install http:///home/pi/master --download-cache /home/pi/tmp"
6. You can now start xwindows (startx)
7. To test SimpleCV, open up LXTerminal and type "simplecv"
8. Once you are in the SimpleCV shell plug in your usb webcam and type "wc = Camera()" (You may get an error, just ignore it)
9. Now type "img = wc.getImage()"
10. Now, type "img.show()"
If an image shows up in a popup window then you have done everything right. If not you might want to switch webcams if you can or consult the comments on the troubleshooting page to (hopefully) find an answer to your problem
Step 5: Download the Python Code
Download the python code onto your raspberry pi and place it into your home directory. Open the file and edit all the email addresses to your own gmail address (if you don't have a gmail you need to find your specific server's port and a couple other things which isn't really within the scope of this instructable. There are numerous resources online on the subject). Now shutdown your Pi. Connect pin 17 to a piece of aluminium foil and to the door through a 10k ohm resistor (to help prevent ESD damage to the pi). Now put a 1M ohm resistor between GPIO pin 18 and the foil. Reboot your pi and make sure your webcam is plugged in. Now login with pi and raspberry and run "sudo python SmartDoorKnobAlarm.py" . Wait for a few seconds then touch the alumium foil. Wait another few seconds and you should get an email with the subject ALERT! and an attachment. You might have to go in your security settings in gmail and allow "less secure apps" if it doesn't work. If you did recieve the email with the attachment then good job! This was a tough project!
Step 6: Troubleshoot -- Bang Bang!
I hope that this page will fill up with help from the comments, so if you have a fix or a suggestion to streamline the code, please leave it below.
Step 7: Going Beyond...
There are plenty of ways to adapt this project, and as creative DIYers I expect to see plenty of changes :)
Here are a few I thought would be a good idea
Not only a door -- This project doesn't have be attached to a door. I can be stuck to anything metal. You could convert it so that it fits in a drawer and will go off anytime someone tries to open it. You could also attach the alarm to a metal platter and put some valuable metal relics on it. If someone comes to close, you will know the minute it happens.
Alarm???? -- The raspberry pi build didn't have any audible feedback! Try making the Pi play a loud noise when you touch the door. Or maybe instead of an alarm, you could have a voice emulator tell you the weather or how many emails you have when you open the door. The possibilities are endless!