Interfacing SIM900A GSM Modem with RaspberryPi

This post is intended to help begineers to interface GSM Modem with RaspberryPi and send data through serial port.

RaspberryPi

SIM900A

Note: Programs are written in Python Language. For C++ examples please contact our Technical support section at http://www.elementzonline.com

Connect a USB to Serial converter to the RaspberryPi USB port. A compatible USB to Serial converter can be obtained from this link.

Create a new file named serial_test.py by typing the following command

nano serial_test.py

write the following lines to the file

“””
author: dhanish
company: Elementz Engineers Guild Pvt Ltd
Created on: Tue Aug 12 20:17:12 2014″””
import serial
import time
ser = serial.Serial(‘/dev/ttyUSB0’,9600,timeout=1) # 9600 is the default Baudrate for SIM900A modem
ser.flush()
ser.write(‘ATD9020XXXXXX;\r’) # AT command to call a number using GSM Modem — Edit here
#ser.read(2) # read 2 bytes of data from the serial port
time.sleep(10) # wait for 10 secondsser.write(‘ATH\r’) # Hold the call
ser.close() # close the serial port

And finally save the file using Ctrl+O and Ctrl+X
Run the following command in the terminal

python serial_test.py
External Links:

Elementz Github channel for RasperryPi sample codes.
Ebay Link — SIM900A Modem
Ebay Link — USB2Serial Converter

56 thoughts on “Interfacing SIM900A GSM Modem with RaspberryPi

    • Hello Hussain,
      You may use AT+CMGS=”phonenumber” for the purpose
      after that you can read ‘>’ symbol.
      After printing your message to the terminal send ser.write(26) // ctrl+z
      We will be updating this post by providing a sample code to send SMS soon.

  1. I connected the GSM module to my Raspberry Pi using USB to serial converter. I connected TXD of USB to serial converter to TXD of SIM900, RXD of converter to RXD of sim900 and VDD to 5v , GND to GND.

    I have an LED called NWK constantly blinking for every 3 seconds. I send the echo command

    ser.write(“ATE0\r”)
    response = ser.readlines(None)
    print response

    I get the result printed as simply this [ ]

    I run the code you’ve given in the page and it does not make any call. Is there anything I should set up?

    • Sir, you should connect RXD of USB2Serial to TXD of GSM Modem and TXD of Serial to RXD of GSM Modem. Also check if you can make a call to the modem and see whether a ring sound, so that network connection can be ensured.

      • I connected the way you told me to and it is working. I send Echo command and it returns OK.

        I call SIM card number and the GSM module starts the buzzer whenever it rings. I try your code and I get the following

        [‘\r\n’, ‘NO CARRIER\r\n’, ‘\r\n’, ‘OK\r\n’]

        What does this mean and how should I rectify it?

      • Hello Srinivas,

        It seems that you don’t have enough balance to make a call,( correct me if it was a silly observation). Assuming there is no network issue as you have said that the ring buzzer is responding whenever you make a call to the module.

  2. hi
    itz showing an error “import timeser=serial.Serial(‘/dev/ttyUSB0′,9600,timeout=1)”
    invalid syntax

    • There was a mistake in the code pasted.
      import time
      ser=serial.Serial(‘/dev/ttyUSB0′,9600,timeout=1)
      should be used instead. Please see the edited code above.

  3. How to connect Speaker to SIM900 module there are pins which indicating SP- and SP+. How to use these pins for speaker for Ring indicator in standalone condition.

  4. Hi Dhruvin,
    Please check whether your serial port is working correctly. Make an echo test(short Rx and Tx of your serial port- you should get the characters which are typed in the terminal ). Also ensure that you have connected the GSM Modem UART correctly. Rx of GSM to Tx of PC and Tx of GSM to Rx of PC. Make sure you are using TTL-TTL or RS232-RS232 level communication(do not connect TTL-RS232).

  5. Hi,
    i am connecting a raspberry pi to gsm sim900 module. i made a set up by connecting pi to LCD and gsm module to pi by connecting wires.. i.e tx, rx, gnd. and giving power to gsm module all LED’s are working fine. I am executing the code you are given above. but it could not make any call to sim inserted into gsm module neither get any output. pls help me in this.

  6. Actually we are working on project consisting of LCD monitor(PC display),GSM module and raspberry pi..
    so can you tell me how to display message on LCD monitor instead of mobile phone using HDMI protocol

  7. can u pls help me i am beginner with raspberry pi and i wish to make calling and sending sms using gsm modem i dont used it all so i need a complete connection setup and python script hope u geniuses can help me to get through this situation

  8. I had reffered the link which you had provide but how could i connect it with pi.the connection now i had given are
    1.connected usb to serial converter from raspberry usb port to rs 232(the diagram that the site provided at the top).
    2.connected 5v vco of gsm to raspberry pi 5v out and connected gnd of gsm with raspberry pi gnd
    Note: i dont know whwther there is a requirement for external supply of 5v 1a to gsm

    Sir is my connections enough to interface the gsm modem with raspberry pi or any other connection required if required you please mention those necessary connections

  9. Hi gents can anyone help me please.
    I would like to connect my raspberry pi2 model B with gsm modem(cell phone) and connect it with AC, can anyone help me with please? equipments required and the full connection diagram with python script.
    celciosoares@gmail.com

  10. Hey, great tutorial but I’m having a small problem, probably stupid. It took me a long time to get ttyUSB0 show up in /dev/. Now when I run the code, I get the following exception –

    serial.serialutil.SerialException: Could not open port /dev/ttyUSB0: [Errno 6] No such device or address: ‘/dev/ttyUSB0’

    I could really use your help.

  11. Hello Sir,
    i want to interface GSM and Risberry Pi through USB to USB. IS it possible? if yes then send me code for that

    Thanks

  12. hi we r interfacing respberry pi with gsm as wireless notice bord is there any commands to display the popup messages if its there please send me

  13. Please help me…..
    i connected GSM SIM900 with Raspberry pi using Serial cable to USB ,Working All Very Well
    But i enter command on putty as a AT+CMGL=”ALL” showing all message
    But I want code for Python Language how to write commad in python and print message in python programming……Its very Urgent Please Help me

  14. Hi; I use code ,but error
    Traceback (most recent call last):
    File “test1.py”, line 1, in
    import serial
    ImportError: No module named serial

    • You need to install serial library.
      Whenever you get an error in import statement in python, it simply means you havent install that library.
      sudo apt-get install python-serial
      pip install python-serial

  15. I like your post. It is really interesting. But using AT commands you can just make a call and hang up incoming call. But for the communication between two ends raspberry pi is not useful. It requires some extra functionalities which are not available in raspberry pi system.

  16. We had try alot but it can’t run for ongoing call for user to listen for audio and text to speech.Actually raspberry with gsm modem is working bt only in 1 way handshake.
    Because it need some extra hardware for telephonic serail port and connection.

Leave a comment