Tutorial 43: Send a Text Message!

In this tutorial I show you how you can use your Raspberry Pi to send a text message to your cellphone using Twilio. Sending text messages is useful if you want updates from your home automation system. In the context of the project I'm working on in the previous tutorial (and the next one), I will use this texting service to send myself a greeting message whenever I come home from work.

This is done using Twilio. I'm not affiliated with them, and there are other options out there. However it's easy to get started with Twilio and the Raspberry Pi, so I thought I would show that. If you want to use another service or have your own GSM module and subscribe to provider, you will need to look elsewhere.

  • How to setup an account with Twilio.
  • How to write a Python 3 script that sends you a text message.
You can copy / paste the code below if you’re having issues with typos or want a shortcut. However I recommend that you follow along in the tutorial to understand what is going on!

from twilio.rest import Client

account_sid ="XXXXXXX" # Put your Twilio account SID here
auth_token ="XXXXXXX" # Put your auth token here

client = Client(account_sid, auth_token)

message = client.api.account.messages.create(
		to="+#####", # Put your cellphone number here
		from_="+######", # Put your Twilio number here
		body="This is my message that I am sending to my phone!")

A Twilio account is needed for this to work. See below for a link: