Joseph Taylor

Arduino SIM Card Module

My friend gave me a SIM900 Arduino Module for me to look at as he was having trouble getting it to work.

This module is designed to allow GPRS and GSM communication with an Arduino. You put a SIM card into the SIM card slot on the device and communicate with the SIM900 using serial commands.

Included in my broadband package is a mobile phone plan, which includes 500MB of data, 200 minutes and unlimited texts. Perfect for experimenting with, using an Arduino and this module.

So far I have been able to send text messages using the module, with the code below:


#include <SoftwareSerial.h>;
#include <String.h>;
 
SoftwareSerial SIM900(7, 8); // Set the SoftwareSerial pins.
 
char incoming_char = 0;
 
void setup()
{
 SIM900.begin(19200); // Set the baud rate.
 Serial.begin(19200); // Set the baud rate.
 delay(500); // Give the module time to establish a serial connection.
}
 
void loop()
{
 /* When sending a 't' to the module, it runs the script
 to send a text message, configured below. The switch statement has
 been used early on so that other options can easily be added. */
 if (Serial.available())
 switch (Serial.read())
 {
 case 't':
 SendTextMessage();
 break;
 }
 /* When the module sends something back to the Arduino,
 it runs it's own function. This is so the responses can
 be processed later on. */
 if (SIM900.available())
 RecievedMessage();
}
 
// This function is to send an SMS message.
void SendTextMessage()
{
 SIM900.print("AT+CMGF=1\r"); // Because we want to send the SMS in text mode.
 delay(100);
 SIM900.println("AT + CMGS = \"+447755544321\"");// Send the AT command to the module, include the phone number with country code.
 delay(100);
 SIM900.println("Hi, I sent this using my Arduino!");// Message contents.
 delay(100);
 SIM900.println((char)26);// The ASCII code of the CTRL+Z is 26, this tells the module to send the text.
 delay(100);
 SIM900.println();
}
 
void RecievedMessage()
{
 /* Here we're checking if information is available from the module. Running
 the data through a char makes it easier to process later on. The module
 only sends one character at a time. Later on we will look at combining
 the characters into a string of text for parsing. */
 if (SIM900.available() > 0)
 {
 incoming_char = SIM900.read(); // Get the character from the serial port.
 Serial.print(incoming_char); // Print the incoming character to the serial monitor.
 // The characters will keep coming through until there aren't any left to send.
 }
}

I am now working on being able to receive a text message and parsing information out of it (e.g. phone number message sent from and message contents).

If you’re interested in a sketch I wrote that sends the lyrics of Rick Astley – Never Gonna Give You Up to a number of choice, the sketch can be found here.


If you have any questions about this project, or any others on my site get in touch!