Como receber SMS usando módulo GSM com Arduino- (Parte 47/49)

How to receive SMS using GSM module with Arduino - (Part 47/49)

In certain applications, microcontroller-based systems must be connected to the GSM network, which will allow the user to control the system by sending messages or making a call. The advantage of using GSM communication with a system or device is that the user can control the system wirelessly regardless of distance compared to any other wireless communication as long as both the user and the device are in a cellular coverage area. . .

Cell phones have built-in GSM modules that can be used by the phone's internal processor to make a call, send or receive messages or even connect to the GPRS network. When it comes to a microcontroller based system, a separate GSM module is used instead of a cell phone itself. There are GSM modules available that can do serial communication with microcontroller-based systems. Communication is done by sending or receiving AT commands with the GSM module. This specific project demonstrates how to interface with a GSM module and read and display SMS on 16*2 LCD.

Any AVR microcontroller based board that follows the standard Arduino schematic and is flashed with the Arduino bootloader can be called an Arduino board. Arduino is known as open source hardware and Arduino IDE is also open source and anyone can contribute their libraries to Arduino. All Arduino boards must be compatible with the Arduino IDE, which can be used to program Arduino boards.

The operation of this project is explained based on the Arduino pro-mini board and the IDE version 1.0.3 for Windows. The advantage of this board is that it comes in a very small size; any type of connector can be soldered to its periphery according to our needs. It is very breadboard compatible and takes up much less space than a typical breadboard.

The image of the Arduino pro-mini board and Arduino IDE is shown below:

Fig. 2: Typical Arduino Pro-Mini board

Fig. 3: Arduino IDE software window

Since the Arduino pro-mini board does not have circuitry to interface with the PC's serial port or USB port, an external USB to TTL converter board is required to connect it to the PC. This hardware helps in programming the Arduino board and also helps in serial communication with the USB port of the PC.

4: External USB to TTL converter board for Arduino programming and serial communication

It is assumed that the reader has gone through the project how to get started with Arduino and tried all the things discussed there. The GSM module used in this project is a SIM900 based module that can communicate with other devices using the RS232 serial communication port. It works on 9V power supply and the image of the same is given below:

Fig. 5: GSM SIM900 module connected to the Tx pin of the Arduino board module through max232

The GSM module is connected to the Arduino board using the serial communication port. Since the module has an RS232 port and the Arduino pro-mini can communicate using TTL logic levels, a max232 IC is used to do a bidirectional conversion between RS232 and TTL logic levels. The Tx pin of the Arduino board is connected to the Rx pin of the GSM module through max232 and the Rx pin of the Arduino is connected to the Tx pin of the GSM module using the max232 itself.

The code written on Arduino is capable of communicating with the GSM module using AT Commands . AT Commands are sent or received from the module using the serial communication functions provided by the Arduino library. The functions like Serial.begin which helps to initialize the serial port with a certain baud rate, Serial.write to send data to the serial port, Serial.available and Serial.read functions to read data from the serial port are used in this project and They have already been discussed in previous projects on how to do serial communication with Arduino , how to send and receive serial data using Arduino and how to do serial debugging with Arduino.

GSM modules respond “OK” when they receive the “AT” command and it is the best way to check communication between the module and the microcontroller.

+CMGF – This command is used to set SMS mode. Text or PDU mode can be selected by assigning 1 or 0 to the command.

Syntax: AT+CMGF=

0: for PDU mode

1: for text mode

For example,

AT+CMGF=1

+CNMI- This AT command is used to specify how newly arrived SMS messages should be handled. It can be used to configure the GSM/GPRS modem or mobile phone to route incoming SMS messages directly to the serial port or to save them in the message store and then notify the host device by sending a string through the serial port.

SYNTAX: AT+CNMI=

For example, to route the sequence of incoming messages to the device's serial port, the code written for this project uses the following command;

AT+CNMI=2,2,0,0,0

As soon as an SMS is received, the GSM module sends a long string to the Arduino board that consists of many details about the message and also includes the original text. The code is written in such a way that it will wait until some character is received by the serial port and as soon as it starts receiving it will check the occurrence of the fourth ' ” ' and write the rest of the characters directly on the 16 * 2 LCD. The characters after the fourth ' “ ' in the received string will be the original text and the rest of the characters are ignored in the code using the following lines;

to do

{

while ( !Serial.available );

} while ( '”' != Serial.read );

to do

{

while ( !Serial.available );

} while ( '”' != Serial.read );

to do

{

while ( !Serial.available );

} while ( '”' != Serial.read );

to do

{

while ( !Serial.available );

} while ( '”' != Serial.read );

SMS text is recorded on 16*2 LCD using library functions which can be used to interface an external LCD module with the Arduino board. The functions that can be used to access the LCD have already been discussed in previous projects in how to interface with an LCD , how to display the sensor value on the LCD , how to connect the LCD to the PC and how to make a scrolling LCD display .

You can check and upload the code that can send the same commands to the Arduino board as explained in the project how to get started with Arduino . Make sure that the GSM module has been turned on at least 2 minutes before the Arduino board starts sending commands so that the GSM can establish communication with the cellular network corresponding to the SIM card inserted in it.

Project source code

 ###




 /*============================= EG LABS ================== =================//
 
Demonstration on how to receive an SMS using GSM module


 The circuit:

 LCD:

 * LCD RS pin to digital pin 12

 * LCD Enable pin to digital pin 11

 * LCD D4 pin to digital pin 7

 * LCD D5 pin to digital pin 6

 * LCD D6 pin to digital pin 5

 * LCD D7 pin to digital pin 4

 * LCD R/W pin to ground

 * 10K resistor:

 * ends to +5V and ground

 *wiper to LCD pin 3

 * LED anode attached to digital output 9

 * LED cathode attached to ground through a 1K resistor


 GSM:

 RX PIN OF GSM TO TX0 PIN OF ARDUINO

 SHORT THE GROUND PINS OF ARDUINO AND XBEE

 =============================== EG LABS ================== =================*/



 #include

 // initialize the library with the numbers of the interface pins

 LiquidCrystal LCD(12, 11, 7, 6, 5, 4);


 // give the pin a name:

 int led = 9;

 // incoming serial byte

 int inByte = 0;


 void setup

 {

 pinMode(9, OUTPUT);

 lcd.begin(16, 2);

 lcd.print("ENGINEERS GARAGE");

 lcd.setCursor(0, 1);

 lcd.print(" GSM SMS ");

 delay(1000);



 // initialize the led pin as an output.

 pinMode(led, OUTPUT);
 
// start serial port at 9600 bps

 Serial.begin(9600);

 // wait for a while until the serial port is ready

 delay(100);


 // send the initial data once //

 Serial.print("AT+CMGF=1nr");

 delay(500);

 Serial.print("AT+CNMI=2,2,0,0,0nr");

 delay(2000);



 digitalWrite(led, HIGH);

 }


 void loop

 {

 of

 {

 while ( !Serial.available );

 } while ( '"' != Serial.read );



 of

 {

 while ( !Serial.available );

 } while ( '"' != Serial.read );



 of

 {

 while ( !Serial.available );

 } while ( '"' != Serial.read );



 of

 {

 while ( !Serial.available );

 } while ( '"' != Serial.read );



 while ( !Serial.available );

 inByte = Serial.read;

 while ( !Serial.available );

 inByte = Serial.read;



 lcd.clear;

 while(1)

 {

 while ( !Serial.available );

 inByte = Serial.read;



 if ( inByte == 'r' )

 break;

 else;



 lcd.write (inByte);

 }

 }

 ###

Circuit diagrams

Circuit Diagram-SMS Receiving Using GSM-Arduino Module

Project Components

  • Arduino ProMini
  • Capacitor
  • LCD
  • LED
  • MAX232
  • Potentiometer
  • Resistor

Project video

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.