Send SMS Messages - Raspberry Pi Pico W

Sending SMS messages with microcontrollers, in this case, the Raspberry Pi Pico W can be essential, especially in IoT applications. One of the most popular packages to send messages in MicroPython is the Twilio package, which is initially free and easy to use! However, the package cannot fit on the Pico itself since the storage is so minimal, thus we need another means to use the Twilio package. Thankfully the Pico W has wifi capability which allows you to access the internet and thus use the Twilio API to send the message. I will show you how to do this in this tutorial. 

Step 1-) Install Thonny on your Raspberry Pi Pico W

Thonny is a very IDE used to develop MicroPython applications on the Pico. However, if you already have another IDE ready to go you do not have to do this step.

  • https://thonny.org/

Step 2-) Create your Twilio Account

  • https://www.twilio.com/

Creating a Twilio account is initially free, and no need for credit cards which is nice! You get 15 dollars of credit, which is enough to send a few thousand SMS messages (great for development). When creating an account they will give you a Twilio phone number along with an account id and a token that you will need to start sending messages. Overall it is really easy, just click through the above link to set this up.

Step 3-) Connect to your Raspberry Pi and run the function from the script:

I am going to assume you already made a connection to your Raspberry Pi Pico in Thonny or whatever IDE you are using. 

The script itself is located on my GitHub page:

  • https://github.com/shillehbean/youtube-channel/blob/main/sms-micro-python.py

The function takes the following parameters:

The logic in the function is split into two parts:

1-) Making the internet connection:

Here we simply use the internet and password for whatever wifi network you are using and we wait 10 seconds for the connection to be made, otherwise, we throw an error. 

2-) Hit the Twilio API with the SMS you want to send:

This code uses the requests library, which is built into MicroPython, to hit the Twilio API. You need to pass in the headers or else the API will be unable to parse the information you send in the payload. More details of their API can be found here: 

  • https://www.twilio.com/docs/usage/api

As you can see the format of the post request in the code mimics the curl command seen on their website, just make sure you have the proper information when calling the function. You also need to be aware that you need to pass in the information from your Twilio account to authenticate, or else you will get an auth error. If you run the function and see a status code in the 200s, your recipient probably got the message! Good job! 

Conclusion:

As you can see it is relatively easy to send an SMS, the main takeaway is that you cannot download the package onto your Pico, the hardware is not built to hold large amounts of storage since this is a minimalistic microcontroller. Also note that this architecture I just showed you probably can be applied to other microcontrollers, because as long as you have internet connectivity you can take advantage of using API requests (which are much more lightweight), rather than downloading any sort of library. Hope I helped you develop your IoT applications. Please let me know if you have any questions in the comments.

Create a free account to access full content.

All access to code and resources on ShillehTek.

Signup Now

Already a member? Sign In

Explore More on Our Blog

How to Post to Reddit Using Python

How to Post to Reddit Using Python

Post to reddit automatically using a Python script.

How to Create a Time-Lapse Video with a Raspberry Pi Camera

How to Create a Time-Lapse Video with a Raspberry Pi Camera

Learn how to make a timelapse with your Raspberry Pi in Python.

How to Integrate the MPU6050 with the STM32 Blue Pill

How to Integrate the MPU6050 with the STM32 Blue Pill

Learn how to measure acceleration with the STM32 and the MPU6050 in the Arduino IDE.

Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter — Write Your First Program

Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter — Write Your First Program

This comprehensive tutorial will guide you through the process of setting up and programming the STM32 Blue Pill...

Automate Task Scheduling in AWS with Lambda, Step Functions, and CloudWatch

Automate Task Scheduling in AWS with Lambda, Step Functions, and CloudWatch

In this tutorial, I'll show you how to automatically schedule tasks in AWS at regular intervals using AWS...

Implementing Google reCAPTCHA in a Simple React and Node.js App

Implementing Google reCAPTCHA in a Simple React and Node.js App

Learn how to protect your React applications from bots and spam with Google reCAPTCHA integration! This step-by-step tutorial...

AWS Lambda Tutorial: Using Selenium with Chromedriver in Python

AWS Lambda Tutorial: Using Selenium with Chromedriver in Python

In this tutorial, I will guide you through the process of running Selenium with ChromeDriver inside an AWS...

How to Connect MLX90614 Infrared Thermometer to Raspberry Pi Pico W: MicroPython Tutorial!

How to Connect MLX90614 Infrared Thermometer to Raspberry Pi Pico W: MicroPython Tutorial!

Learn how to use the MLX90614 with the Raspberry Pi Pico W and get infrared values in MicroPython.

Raspberry Pi Pico/Pico W Free Simulator

Raspberry Pi Pico/Pico W Free Simulator

Discover how to simulate Raspberry Pi Pico projects using Wokwi, a free online simulator for Arduino and MicroPython....

Interfacing the MPU6050 with Raspberry Pi Pico W in C++

Interfacing the MPU6050 with Raspberry Pi Pico W in C++

Interface with the MPU6050 using the Raspberry Pi Pico W in C++.

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.