In this guide we will show you how to control the GPIO pins of a Raspberry pi by send a SMS to the Raspberry Pi from a mobile phone.
For this guide, the GSM modem we are using to receive the SMS is the BerryGPS-GSM.
On the software side, we will be using Gammu, which is specifically designed to control phones and GSM modules. It also has a daemon which will monitor the GSM modem for incoming SMSs.
We will configure Gammu to trigger a python script when a new SMS is received. We will use the contents of the SMS to control what happens in Python
LEDs are used here as an example, but you can do anything you like Eg. Open a garage door, turn on some lights, etc..
Wiring
We will be using the three bottom right GPIO pins on the Raspberry Pi header. These are GPIO 16, 20 and 21.Each is connected to a different color LED as shown above. TheThe resistors used are 330 Ohm and the GND pin (shorter pin) of the LEDs is connected to the GND power rail.
SetupInstall Gammu and python bindings;
sudo apt-get update
sudo apt-get install gammu-smsd python-gammu
Edit the config file;
sudo nano /etc/gammu-smsdrc
Find the below lines and add port and speed.For the BerryGPS-GSM, use /dev/ttyACM1 for port and at115200 for speed
port = /dev/ttyACM1
connection = at115200
At the bottom of the file, add the line below. This is the python script which will run when a new SMS is received.
RunOnReceive = sudo python /home/pi/smsReceived.py
We will do a quick test. Restart the gammu service so the new config takes effect;
sudo /etc/init.d/gammu-smsd restart
Send a test SMS to a mobile number. The mobile number below is an example, you will need to update this;
echo "This is a test from a Raspberry Pi" | /usr/bin/gammu --sendsms TEXT +614123456789
Python Script
This python script will run every time a new SMS is received. Create a new file.
nano ~/smsReceived.py
Copy in the code attached to this guide.
To troubleshoot you can view the syslog
tail -f /var/log/syslog
Comments
Please log in or sign up to comment.