NADBYTE

How to send SMS with GSM module from Raspberry Pi using Python

Introduction

Hi guys, in this article we will see how to interface GSM Module with Raspberry pi and send SMS using python.

Components Required

Schematic Diagram

Code

import serial as io

gsm = io.Serial("/dev/ttyUSB0",9600, timeout=0.5)
gsm.flush()

def sendSms(msg):
    print("Sending SMS\n")
    gsm.write(b'AT+CMGF=1\r\n')
    sleep(0.5)
    gsm.write(b'AT+CMGS=\"')
    serialcmd = args["mobile"]
    gsm.write(serialcmd.encode())
    gsm.write(b'\"\r\n')
    sleep(0.5)
    data = msg
    gsm.write(data.encode())
    gsm.write(b'\x1A')
    sleep(3)

sendSms("Hello nadbyte.com")

Thanks for reading this article for any assistance or doubts comment below.

[jetpack_subscription_form show_subscribers_total=”false” button_on_newline=”false” custom_font_size=”16″ custom_border_radius=”0″ custom_border_weight=”1″ custom_padding=”15″ custom_spacing=”10″ submit_button_classes=”” email_field_classes=”” show_only_email_and_button=”true”]
Exit mobile version