Linux Format

Texting doorbell

Get an SMS alert whenever a visitor drops by.

-

The humble doorbell is great for alerting us to visitors as long as we’re in earshot, but we could fix that with a little Internet of Things (IoT) knowhow. For this project, we’ve used a cheap wireless doorbell (found on Amazon for a fiver). We took apart the push button unit and found a circuit which uses a simple momentary switch powered by a 12V battery. The Raspberry Pi GPIO can’t directly work with voltages over 5V so we first need to change the power supply for something lower.

You’ll need to solder two wires onto the battery contacts for the push button unit. When pressed, the momentary switch connects the power to ground and effectivel­y drops the current, changing the state of the unit from on to off and creating a trigger. Using a multimeter, locate the correct pins for your unit and solder wires to them. For added strength use a hot-glue gun to keep the wires on the contacts. Attach the positive battery terminal to the 3V3 GPIO pin and the GND of the battery terminal to the GND of your Raspberry Pi. On your momentary switch attach the button to pin 17 (Broadcom pin reference) and the other to the 3V3 GPIO pin.

You will need to create a trial account ( https://www.twilio.com) in order to send an SMS. Boot your Raspberry and navigate to the terminal and type the following to install the Twilio API for Python: $ sudo w pip3 install twilio . Open the Python 3 applicatio­n via the Programmin­g menu, create a new file and immediatel­y save it as Doorbell-SMS.py. We start our project by importing the Twilio API, the time library and the GPIO library: from twilio.rest import TwilioRest­Client import time import RPi.GPIO as GPIO

Afterwards, we need to configure our GPIO to use the Broadcom pin-mapping, set up pin 17 as an input and set its built-in resistor to pull the current down: GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.IN, GPIO.PUD_DOWN)

Next, we create a function that will handle sending a text message using the Twilio API. You will need to replace the account and token details with that of your own and change the to= and from_= telephone numbers to correspond with our requiremen­ts: def sendsms(): ACCOUNT_SID = “ACCOUNT ID“AUTH_TOKEN = “AUTH TOKEN“client = TwilioRest­Client(ACCOUNT_SID, AUTH_TOKEN) message = client.messages.create(

body=”Doorbell has been rung“, to=”NUMBER TO SMS”, from_=”YOUR TWILIO PHONE NUMBER”, ) print(message.sid) time.sleep(5)

Our last section of code is a loop that will constantly go round. We look for the current on pin 17 to drop in the loop and when it does the function is called triggering an SMS being sent to your mobile: while True: GPIO.wait_for_edge(17, GPIO.FALLING) sendsms() Save your code and click on Run > Run Module to test. You will need...

Newspapers in English

Newspapers from Australia