Amy Ciavolino’s friends were stuck outside of her apartment waiting to be let in to the party. They repeatedly pressed Amy’s apartment buzzer with no luck. The buzzer was too quiet, and Amy’s party was too loud. Throughout the night, the cycle repeated: Amy’s friends pressed the buzzer, waited in vain, finally called Amy, and Amy would come to the rescue, only to be interrupted moments later.
To fix her buzzkill of a buzzer, Amy and her friends put their heads together and built a Twilio powered solution that triggers Amy’s apartment buzzer by texting a password to a Twilio number.
Below is Amy’s tutorial originally posted on GitHub here.
How To Set Up A Buzzer Bot
Chances are if you have a Raspberry pi, and you’ve done anything at all with it, you’ve turned on an LED. This project is almost as simple as that. The software requires a some set up, but hardware-wise, if you can turn on a LED, you can do this.
- A raspberry pi with Node js installed
- A domain from freedns
- A twilio account with a phone number
- An optocoupler (I used this one)
- Some resistors
- An LED
Step 1: Install Stuff!
See the read me for the basics of installing this code on your pi. Once you install it, rename sample_config.json’);”>[crayon-55c47d3fd4b91940775320-i/] to config.json. You’ll need to fill in the blanks, but we’ll get to that later.
Step 2: Set Up Your Test Light
Before we connect anything to your buzzer box, let’s set up a simple test light to make sure the software is set up right.
All we need right now is to get one LED turning on and off, so I’m going to defer to another tutorial because there are lot of great ones already. This is the one I used, but if you find another you like that’s fine too. Once you have an LED connected to your raspberry pi, come back here.
Now that you have an LED turning on and off, open config.json, and change buzzer_pin to the physical pin number your LED is connected to. If you used the tutorial I mentioned above, your number is 11. Otherwise you can use this handy digram to figure it out. The numbers in the circles are the physical pin numbers.
Then, run node test.js and your LED should turn on for 2 seconds, and then turn off.
Step 3: Finish Software Setup
Now that we can test it, let’s get it hooked up to Twilio.
First you need to let your raspberry pi out onto the world wide web via your router, so twilio can get to it. I can’t really tell you how to do this for your router, but you want to open up a port, and send that port to your raspberry pi’s ip address. You’ll probably need to give you raspberry pi a static ip on your local network.
Here’d how I did it on my router:
First I went to DHCP Reservation…
So it had a static IP.
Then I sent http traffic on port 80, to port 5000 on the ip address for my raspberry pi. You can use a different port, you’ll just need to change port in config.json.
Go to freedns and find “Dynamic DNS”. At the button hit “[ add ]”. Leave the type as “A”, pick a subdomain (this can be whatever you want), pick on of the public domains (again whichever you want), and leave the destination (we’ll update it from the pi).
Once you’ve saved it click on “Dynamic DNS” again and find the “Direct URL” for your subdomain. Copy everything after the ? into freedns_key in config.json.
Then run ./bin/cron_install‘);”>[crayon-55c47d3fd4bee494747857-i/] which will install a cron to update the ip your DDNS points to periodically.
At this point you should be able to run npm start on your raspberry pi and you’ll see some stuff like this:
pi@amyspi ~/buzzerbot9000 $ npm start
> email@example.com start /home/pi/buzzerbot9000
> node server.js
Listening on 5000
Error when trying to close pin 11
gpio-admin: could not flush data to /sys/class/gpio/unexport: Invalid argument
Once that’s running you should be able to go to <your domain>/sms in a browder and see Webhook Error – we attempted to validate this request without first configuring our auth token. and see this in the console [Twilio]: Error – Twilio auth token is required for webhook request validation.
Now we need to point Twilio at the domain you just set up. Go to Twilio and set up a number. Then go to the settings for that number and set the message request url to <your domain>/sms:
Also grab your twilio Auth Token and fill in twilio_token in config.json.
Now when you run npm start and go to your domain it should say Twilio Request Validation Failed., and if you text it, you should get a message back saying “Hmmm, that’s not a password” but! If you open up config.json and put your phone number in the “sesame” whitelist, and then text “sesame” your test light should come on for a few seconds and go back off.
Step 4: Buzzer Box Time
Now you need to connect your optocoupler to your raspberry pi and your buzzer box.
Your optocoupler has two sides: one side has an LED, the other a photo resistor. When you turn the LED on, the resistor connects the leeds on the other side. Your buzzer box has a “door” button. When you press the door button, it connects two wires and the door opens.
What we want to do is connect the LED side of the optocoupler to the raspberry pi, and the photo resistor side to the door button. The raspberry pi will turn on the LED, which will connect the sides of the door button, and the door will open. Magic!
Here’s a diagram and an up close look at my wiring:
For more detail: Making Your Apartment Buzzer Party Friendly With Raspberry Pi and Twilio