Learn to Send SMS from Raspberry Pi using Python. In this article, we will discuss how to Send SMS from Raspberry Pi when a certain event occurs. SMS sending feature can be used for many interesting projects. For sending SMS we will be using NEXMO service. In the trial period, you will be able to send SMS from your NEXMO registered mobile number. For now, we will send SMS by pressing Push Button. So, let’s start.
Step 1: Required Components
Raspberry Pi x 1
Push Button x 1
Generic LED x 1
Breadboard x 1
Jumper Wires
Step 2: Circuit Time
Make a circuit as per the given diagram. Connect the LED to GPIO 18 Pin of Raspberry Pi. Also, connect Pushbutton to GPIO pin 23 as given below.
Step 3: Code Time
Follow below-given steps to run
- Sign-up for the NEXMO account here.
- Once you sign-up visit your dashboard here.
- Make note of your API key and App secret. In the new dashboard, it is namely key and secret.
- In Raspberry Pi, open the terminal and install NEXMO library using the following code:
pip install nexmo
- The following code will be used in your main program to send SMS.
import nexmo
save this code in a file and name it “send_sms.py” in your Raspberry Pi.
client = nexmo.Client(key='YOUR-API-KEY', secret='YOUR-API-SECRET')
client.send_message({'from': 'Nexmo', 'to': 'YOUR-PHONE-NUMBER', 'text': 'Hello world'})
- This will be your main program which will call send_sms.py on the press of push-button.
Step 4: Run code to Raspberry Pi
Run the main code given in code time to send SMS directly from your Raspberry Pi. On pressing push-button SMS will be sent and the LED will light up which will show that SMS is sent.
For running python code in Raspberry PI, visit: raspberrypi.org/documentation/usage/python/
Learn basic hardware information of Raspberry Pi 3.