The Code for Sending a Text Message

1577 Words4 Pages

GSM Shield library

GSM coding is significantly facilitated by using the GSM library. The library consists of a few header files and examples. The header files encompass AT commands to start up SIM900 and test the serial communications between Arduino and GSM. Moreover, several functions are integrated in the library to facilitate sending text messages, making phone calls and data transfer. It is worthwhile to note that two GSM libraries can be found on the internet, including GSM_Shield library and GSM-GPRS-GPS-Shield library. Both libraries have been tested in the project and it has been found out that the former is not functional. Therefore, the latter is used.

The GSM-GPRS shield header files include: call.h, GPS.h, GSM.h, HWSerial.h, inetGSM.h, log.h, SIM900.h, sms.h, Streaming.h and Widetextfinder.h. In this project, the objective of GSM shield is to send a text message upon detection of an intruder. The libraries required for sending a text message are SIM900.h and sms.h.

The code for sending a text message is shown below. After declaring the header files, variable “sms” of type SMSGSM is declared. The Boolean variable “started” is used to check whether the shield is started or not. The first function sets up the GSM shield. In the first step the serial port of Arduino is started at a Baud rate of 9600 and then a text message is sent to the serial port. The text messages can be monitored using “Serial Monitor” tool in Arduino IDE or on any serial communication software on a PC. This helps examining the operation of GSM and making sure that it is started without any error. Then, the command “gsm.begin” is used to start GSM. The command encompasses a large number of AT commands, which aim at testing the communication link between GSM and Arduino and starting up the GSM. The serial communication is tested for several different Baud rates. By attempting Baud rates from 19200 to 2400, the maximum valid Baud rate is found. After establishing serial communication, the GSM is started. It is worthwhile to point out that prior to starting up the GSM, the SIM900 has to be turned on by pressing the SIM900 power button on the shield. Otherwise, the program will get stock on “gsm.begin” and the system will not work. Another necessary condition for starting up the GSM is proving appropriate power source. If GSM starting is successful, it will return “1”and the message “status=ready” is printed on the serial monitor.

More about The Code for Sending a Text Message

Open Document