Monday, 2 February 2015

GSM MODULE INTERFACING WITH 8051 MICROCONTROLLER

GSM MODULE (SIM300) INTERFACING WITH 8051 MICROCONTROLLER


Hello readers, I hope you are interested in designing embedded system applications involving the feature of sending the SMS to a particular mobile phone on the occurrence of an event. For example take the case of a simple temperature monitoring system in which it is desired to get a notification SMS on a mobile phone when temperature value exceeds 70 degree celcius or getting a SMS notification on breach of security. All these type of applications can be very easily tackled with the help of a GSM modem. Two most popular GSM modules that are used in embedded applications are SIM300 and SIM900. In this article I will explain the concept of interfacing 8051 microcontroller with SIM300 GSM module. Fig. below shows a SIM300 GSM module-













    











AT commands are used to control GSM modem, AT is the abbreviation for “attention” and microcontroller can interact with the GSM modem by using AT commands. AT command set is very huge and here I will be explaining few AT commands that are quite often used in various embedded system applications. The general syntax of AT command is –

AT <command name> <carriage return>

Every AT command begins with a prefix AT and it ends with a carriage return. AT commands that are used in SMS and calling applications are given below-

      ATà TO INITIATE THE GSM MODEM

      ATD98XXXXXXX;à THIS WILL ESTABLISH THE CALL TO MOBILE NUMBER            
                                            (98XXXXXXXX)

      ATAàTO ANSWER THE CALL

      ATHàTO DISCONNECT THE CALL

      AT+CMGF=1àINITITATE THE GSM MODEM IN TEXT MODE

      AT+CMGS=“98XXXXXXXX”
             >TYPE YOUR MESSAGE HERE
            CRTL+ZàTO SEND MESSAGE

      AT+CMGR=MESSAGE NUMBER IN INBOX
MESSAGE AT POSITION MESSAGE NUMBER WILL BE DISPLAYED
 
If the AT command given by microcontroller to GSM modem is executed successfully by the GSM modem then OK return code will be given back to microcontroller otherwise error code will be returned back which will indicate the cause of unsuccessful execution of the given command.

Circuit Diagram-





Working Details-

SIM300 GSM modem is interfaced with 8051 microcontroller via RXD and TXD pins (P3.0 and P3.1 respectively). In order to send sms via GSM modem it is required to configure the GSM modem using AT commands. Readers must have good understanding of the serial communication programming fundamentals and if you are not aware of the same then you are recommended to go through my other post on “Serial Communication in 8051 Microcontroller”. As shown in the circuit diagram there is a push button connected on port pin P1.0 of 8051 microcontroller. Port pin P1.0 is configured as i/p pin and is pulled up using a 10K resistor. Default state of pin P1.0 is logic ‘1’ and when push button is pressed then the state of port pin P1.0 goes to logic ‘0’. It is required to send the SMS with the message body as “hello sir” to a predefined mobile phone number whenever push button is pressed.  The code for this is given below-           

Code-

#include<reg51.h>
#include<stdio.h>
sbit sw=P1^0;
// delay subroutine starts here
void delay()
{
int i,j;
for(j=0;j<40;j++)
for(i=0;i<15000;i++);
}
// main function starts here
void main()
{
sw=1; // initialize P1^0 as an i/p pin
if(sw==0) // if switch is pressed then send the SMS
{
 TMOD=0X20; // Timer 1 in mode2
 TH1=0XFD; // TH1 is loaded for 9600bps baud rate generation
 SCON=0X50; // Serial communication in mode 1 with receive enable
 TR1=1; // Start Timer 
 TI=1; // Since printf( ) is used so TI flag has to be raised
 printf("at"); // initiate the GSM modem
 printf("\n");
 printf("\r");
 delay();
 printf("at+cmgf=1"); // initiate GSM modem in text mode
 printf("\n");
 printf("\r");
 delay();
 printf("at+cmgs=\"098XXXXXXXX\""); // send sms to the specified mobile number
 printf("\n");
 printf("\r");
 delay();
 printf("Hello Sir"); // body of the SMS
 delay();
 SBUF=0x1A; // ASCII code for ctrl+z
 while(TI==0); // wait for the transmission to complete
 TI=0; // clear the transmit interrupt flag
 delay();
}
}

The code is tested on Proteus simulation platform and the snap shot of the commands that are sent to the virtual terminal from the 8051 microcontroller is shown below-




Caution: During testing on Proteus platform make sure that you set the clock frequency of crystal oscillator as 11.0592 MHz, Otherwise baud rate mismatch will happen and will cause the erroneous interpretation of the instructions sent by 8051 microcontroller.

THANKS FOR READING
UMESH DUTTA

5 comments:

  1. Dear, Umesh Dutta. this is really good post. for beginners this is spoon feeding. I thanks for the nice job.
    Can we use SIM900 in place of SIM300 for the same code?

    ReplyDelete
  2. Thank you Sir, Yes this code can be used but with little modifications, the modifications will be in terms of the usage of carriage return and new line character, try to modify and test it with SIM900.

    ReplyDelete
  3. Hii Sir how to receive the GPS location and send that location through GSM message using SIM808 module

    ReplyDelete
  4. useful to me sir... some reference.......

    ReplyDelete