Software apps and online services
Hand tools and fabrication machines
This project was part of the Lane Tech HS Physical Computing Lab course. I created this project as part of the Home Automation / IoT project.Summary
The Raspberry Pi IoT door buzzer has two (2) main functionalities: to be able to "buzz" myself in to the main doors of my condo and to take a picture of who was at the door and text it to me.
Most of the code is in python, and was put combined from multiple sources on the Internet.Steps:
I first started by examining the door buzzer system in my house, and how it worked. There was a button that needed to be pushed in order to unlock the doors. I decided to use a relay to "push the button" by connecting the two contacts.
After I knew that I needed to use a relay to "push the button", I prototyped a relay control circuit in a breadboard. This uses a NPN transistor, a diode, and a resistor to control the relay via a 3.3 v logic signal. An easier option would be to purchase a relay board that directly controls the relay. Two wires will come connect the two sides of the button to the common pin of the relay and the normally open pin. Later, I soldered the circuit onto a perf board to make it smaller and permanent.
Once I got the circuit working, I researched and found how I would control the relay using the raspberry pi. I wrote the code control.py to turn the relay on for a second then off. It is connected to pin 12 (GPIO 18) of the raspberry pi. To run the code, type "sudo python control.py" into the terminal window.
If you want to stop here and still have a functioning door buzzer, you can download SSH Button (https://play.google.com/store/apps/details?id=com.pd7l.sshbutton&hl=en) and run the code if you are connected to the same network as your Raspberry Pi.Additions
To make this project more permanent, I decided to access the Door control box from behind, to keep the wires out of the way. Luckily, there is a utility closet behind the panel. I cut a hole in the wall small enough to fish the wire from the control panel, then I spliced my relay circuit into it. I also mounted the raspberry pi and relay to the wall inside of the closet. The enclosure that holds the raspberry pi and relay circuit is just a plastic container, then I drilled a small hole in the front and glued in a small led to act as a power indicator.
I wanted to make this project a little more complex and useful, so I decided to add a feature that would take a picture of the door/ who is at the door whenever the buzzer is used and text it to me. I accomplished this by using an old Android phone with the app IP Webcam downloaded on it (https://play.google.com/store/apps/details?id=com.pas.webcam&hl=en). This runs a live video streamer from the Phone on the network it is connected to. There are many helpful features like the button that will take a picture of the video. I used this link in raspberry pi code to acquire and download the picture of my front door. The phone in my living room window pointed at the front door.
I used the code
image.py to go the link of the image then download it to the Raspberry Pi.
To give the raspberry pi the ability to send the picture to me, I used the python smtplib library. This allows you to sign into your email account and send an email. To make this a text, I used the (https://www.wikihow.com/Email-to-a-Cell-Phone) so I could email my phone number. The code is testmail.py.Connecting Code
To run the next piece of code after the first is done, I used the os library to that I could run the command to run the text piece of code. This allows you to add other features in the future if you want.Accessing the Raspberry Pi from Anywhere
At this point, I am only able to run the code when I am connected to my home network (the same one the ip webcam phone and raspberry pi are on). I wanted to be able to use this project from anywhere, incase I had to let someone else into my house, or if my wifi signal was ever super weak and my phone has trouble connecting to it. To do this, I used a service called Dataplicity (Dataplicity.com) which offers a website and a mobile app. Dataplicity used a technique called port forwarding to allow the user to ssh into the device from anywhere. I would suggest starting by using the mobile app because it will scan the network and download all necessary software for you automatically. Once the Dataplicity software has been installed on your raspberry pi, you should move over to the online version on a computer so you can copy and paste all the code.
Some things are difficulty to explain so you can check out https://docs.dataplicity.com/docs/custom-actions-gpio for more information
Once connected to the raspberry pi through Dataplicity, type su pi, then the password for your raspberry pi, usually raspberry . Doing this allows you to make changes as the pi user.
Next, navigate to the dataplicity user by typing cd /home/dataplicity
Then create a file called
dataplicity.actions.conf by typing
sudo nano dataplicity.actions.conf
Copy and paste the provided code. This code creates the custom actions user interface.
Next create 2 strings of folders by using the sudo mkdir foldername
Make a directory called actions, then in that directory make /action/buzzer . Also in the actions directory make /on-off/leds .
After that, in the leds folder create the control-state and get-state files with the corresponding code provided.
In the buzzer directory, create the
testmail.py files with their respective code.
Lastly run sudo chmod 755 /home/dataplicity/actions/on-off/leds/* and sudo chmod 755 /home/dataplicity/actions/action/buzzer/* to make all the files executable.
At this point, I realized that some of the code I had would not run when trying to use the Dataplicity custom actions app, so I came up with some solutions:Problems and Solutions
Originally, I had planned to use the
listener.py code to "listen" to the door buzzer to detect if anyone requested to be buzzed in, then it would take a picture of them and tell me, so that I could let them remotely if I wanted. Unfortunately, after probing the buzzer control board for usable signals, I found none. I believe that the reason for this is that it uses ac. Secondly, the code to take and send a picture to me took about a minute, which is too long to effectively see someone outside then let them in.
The second and larger problem is that I could not get the Dataplicity custom actions to work if I used a Button in the user interface. For some reason it would not run
control.py. At first, I thought it had to do with using the free version of Dataplicity, but I do not think this is the case because the sample code works. I attempted to contact their tech support but they never responded.
Luckily I figured out a way to use the seemingly useless
listener.py code to fix this problem. I ended up using the working sample code provided by Dataplicity that turned on and off an led to turn on and off my relay. The code was shell script. I was still unable to run the code to take and send myself a picture, so I used
listener.py to "listen" to the signal wire that powered the relay. When the relay received power, the
listener.py code would read that and then activate the picture taking and sending code. This actually works very well.
To make it so
listener.py was always running, I needed it to run on boot, and continue to run. To make it run on boot I used (https://www.raspberrypi-spy.co.uk/2015/02/how-to-autorun-a-python-script-on-raspberry-pi-boot/). All you need to do is type
sudo nano /etc/profile then at the very bottom of the file type
sudo python /home/dataplicity/actions/action/buzzer/listener.py &. Now,
listener.py will be ran at the beginning of every boot in the background.
These small work arounds gave me a fully functional project.Conclusion/ Operation
After these small fixes, to activate the door buzzer, all I do is go into the dataplicity app, custom actions, then turn the switch on then off. If I am carrying something big and I need more time, I can leave the switch on. In a minute or so, I receive a text with the picture of me at the door. In the future I plan to teach my neighbors living in the building how to use the app if they are interested.
If you have any questions, feel free to message me.