Sending SMS on a Raspberry Pi (2019 UPDATE)

Sending SMS on a Raspberry Pi

Your Ingredients

To send SMS messages you will need at a minimum: one Raspberry Pi, a USB 3G Modem and a SIM card(pay-as-you-go or otherwise, it’s up to you).

As usual the Raspberry Pi I’m using comes from the great ModMyPi , I have more Pis that I’m ever going to admit in public and they have all come from here. There have been a couple of problems, but they were fixed very quickly, not at my cost and in a very friendly manner. This is not a paid advert for them, I’m just a fan! Hi @ModMyPi!

I wrote some intro posts on Building a Pi on Inventability btw.

The Dongle

The USB 3G Modem I used was the Unlocked HUAWEI E173 from Amazon but I also used the Huawei 3G/21 Mbps Unlocked E3531 with some success as well. I know that the unlocked dongle is are a little bit more expensive than the dongle’s that are locked to a particular network, but it’s worth spending that little extra money so you can use any Sim card you want. There are many reasons why you would use multiple carriers, signal coverage in your area being one of them. As in you might need to go through a couple of Sim cards from different carriers to find one with decent coverage, this is almost certainly not going to be a problem if you’re in a major urban areas.

The SIM Card

Finally comes the SIM card which I got for free from GiffGaff as they had an offer on and then bought some pay you go minutes so that I could send SMS messages. I believe this is a UK only company, so YMMV depending on where you are in the world. I spent one whole English pound on a sim card at my local corner shop, and top it up with £5 which works perfectly well too.

The Process

Assembling Your Pieces and Parts

Take the cover off the back of your dongle, insert your SIM card, then go to your provider’s website and register1 your new SIM card. That done, turn off your Raspberry Pi and plug-in your dongle then restart your Raspberry Pi and ssh in to it.

Finding Your Dongle

Okay, the first thing we should do, on the off chance that the computer gods are with you is to check that your dongle actually believes it’s a 3G modem and not an ordinary USB thumb drive. Open a new Terminal 2 either on your Raspberry Pi (if you’re using a keyboard and monitor) or via SSH) from your local machine (if you’re handsfree like I am).

Checking 3G Modem

To find the modem we need to list all of the USB devices connected to our Raspberry Pi. Do this with the lsusb command. Run the following command:


And you will almost certainly see your new 3G dongle in the list as something like:

Bus 001 Device 006: ID 12d1:1001 Huawei Technologies Co., Ltd.


Converting the (3G) Masses

So you discovered that your new 3G dongle thinks it is a normal USB drive and not a 3G modem, we just need to install a few packages and are just a couple of files and we will be all set.

Installing Packages

You will need the following packages, to install them use the following command:

sudo apt install ppp usb-modeswitch usb-modeswitch-data

After they are installed, reboot your Raspberry Pi with:

sudo reboot

When your Raspberry Pi has finished rebooting, run the lsusb command again and if you look something like this you are golden:

Bus 001 Device 006: ID 12d1:1001 Huawei Technologies Co., Ltd. E169/E620/E800 HSDPA Modem

Understanding Dawns

After you run the lsusb command and discover that your dongle now understands it’s a modem, you need to make a note of the ID number of your device. It will almost certainly be different from the one you see above but will take the same form, the ID number of the device above the one you will need to remember is: 12d1:1001

Where’s our Dongle Mounted

Now we need to know where on your Raspberry Pi the USB modem is mounted in the Raspberry Pi’s file system with:

dmesg | grep ttyUSB

If you’re successful you will see this in your Terminal:

[3.235831] usb 1-1.3.3: GSM modem (1-port) converter now attached to ttyUSB0
[3.236856] usb 1-1.3.3: GSM modem (1-port) converter now attached to ttyUSB1
[3.237626] usb 1-1.3.3: GSM modem (1-port) converter now attached to ttyUSB2

You will almost certainly be using the name ttyUSB0 in the upcoming commands.

If You Don’t See ttyUSB(something)

If you don‘t see any GSM Modems mounted somewhere like the above example we are going to need to create a config file so that your Raspberry Pi knows what to do with the dongle.

Making our own usb_modeswitch Configuration File

Remember before when I said you need to keep track of those eight numbers, well this is where you will need them. You need to create a new config file with the following command (note the file name is the same 8 digits):

sudo nano /etc/usb_modeswitch.d/12d1:1001

The file should have the following contents, obviously adjusted to use your devices ID numbers. That should be the only thing you would need to change.

# Huawei E353 (

TargetVendor=  0x12d1
TargetProduct= 0x1001


Run the following command again:

dmesg | grep ttyUSB

We Have Some Success!

If everything went well, you should see the following in your terminal:

[3.235831] usb 1-1.3.3: GSM modem (1-port) converter now attached to ttyUSB0
[3.236856] usb 1-1.3.3: GSM modem (1-port) converter now attached to ttyUSB1
[3.237626] usb 1-1.3.3: GSM modem (1-port) converter now attached to ttyUSB2

Installing the SMS Software

Next we need to install the software that’s actually going to do the sending and receiving of the SMS messages. This software is called Gammu and we install it like this:

Installing Gammu

sudo apt install gammu

Now we need to configure Gammu so that the Raspberry Pi knows where to look for our dongle:

Configuration of Gammu

sudo gammu-config

A menu will appear. Use the arrow keys and the return key to navigate. When you’ve finished, your settings should look something like this. Note the /dev/ttyUSB0 from earlier:

Port: /dev/ttyUSB0
Connection: at19200
Model: empty
Synchronize time: yes
Log file: leave empty
Log format: nothing
Use locking: leave empty
Gammu localisation: leave empty

Now use the arrow keys to navigate down to Make Sure You Save by using the arrow keys to highlight the save option and then pressing the tab key and selecting the ok option. We check everything is groovy with the following command:

Identifying our Dongle

sudo gammu --identify

The response you get back in your Terminal will look something like this (obviously I’ve redacted some personal information, but yours will be fairly similar):

Gammu Identify Results

Device               : /dev/ttyUSB0
Manufacturer         : Huawei
Model                : E173 (E173)
Firmware             : **.***.**.**.**
IMEI                 : ***************
SIM IMSI             : ***************

Sending an SMS (woot!)

Finally, time for some computer-based SMS shenanigans! Exciting stuff, kids: we’re finally at the good bit. Use the following command to see if everything is working. Replace ********** with your mobile number. You may also need to format it with the country code; I’ve never had to but you may need to.

Sending a test SMS

echo "test" | sudo gammu sendsms TEXT **********

If all goes well, after a few seconds you will receive a text message to your mobile phone with the word test.

Rock! :metal:

And that’s it, you’re finished! In a follow-up post I will show you how to get your Raspberry Pi to do things when it receives SMS messages containing particular words or phrases, so look out for that.

If you get stuck, just drop me a line and I’ll be happy to help. I’m @escapologybb and @robotsandcakes On Twitter.

  1. If you wanted to, you can activate them without registering them to your home address. 

  2. The terminal is located in the folder /Applications/Utilities/ on macOS, and should be pretty easy to find on other distributions as well.