Send SMS from Raspberry Pi using Python

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

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.
Circuit for Send SMS from Raspberry Pi using Python

Step 3: Code Time

Follow below-given steps to run

  1. Sign-up for NEXMO account here.
  2. Once you sign-up visit your dashboard here.
  3. Make note of your API key and App secret. In new dashboard, it is namely key and secret.
  4. In Raspberry Pi, open the terminal and install NEXMO library using following code:pip install nexmo
  5. Following code will be used in your main program to send SMS.
    import nexmo
    client = nexmo.Client(key='YOUR-API-KEY', secret='YOUR-API-SECRET')
    client.send_message({'from': 'Nexmo', 'to': 'YOUR-PHONE-NUMBER', 'text': 'Hello world'})
    save this code in a file and name it “send_sms.py” in your Raspberry Pi.
  6. 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/

For basic hardware information about Raspberry PI 3, Click here.

 

Leave a Reply