GSM interfacing with Arduino Uno board to send and receive SMS

We had interfaced GSM modem(MTSMC-G-F1) with arduino uno R3 board and also an LCD to display the received SMS.
How to send AT commands to modem from arduino board and receive the reply from modem to display it in the LCD...
Give me the coding please....
our coding is not working..

Hi,

Post your code here :slight_smile:

i programmed the gsm for the reply 0 instead of OK ,because while using the modem in hyper terminal i got the reply as 0 for OK and 4 for error.

#include<LiquidCrystal.h>
LiquidCrystal lcd(9,8,7,6,5,4);
byte gsm_count=0;
byte reply=0;
byte d_count=0;
byte msg_flg=0;
byte msg_flag_2=0;
byte i=0;
byte j=0;
char Rec_Data=0;
byte message_rcd=0;
byte message_dpl=0;
char number[15];
char message[160];
void modem_initialization();
void gsm_read_message();
void clear_buffer();

void setup()
{
delay(1000);
Serial.begin(9600);
lcd.begin(16,2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Arduino with GSM");
lcd.setCursor(0,1);
lcd.print(" Interfacing ");
delay(1000);
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("GSM Initialising ");
modem_initialization();
}
void loop()
{
gsm_read_message();
if(message_rcd==1)
{
lcd.clear();
lcd.setCursor(0,0);lcd.print(number);
lcd.setCursor(0,1);lcd.print(message);
message_dpl=1;
}
if(message_dpl==1)
{
clear_buffer();
Rec_Data =0;
msg_flg=0;
delay(100);
array_clear();
Serial.println("AT+CMGD=1");
i=0;j=0;
}
}
void modem_initialization()
{
while(gsm_count<5)
{
clear_buffer();
Serial.println("AT");
delay(100);
reply=Serial.read();
if(reply!='0')
{
gsm_count++;
modem_initialization();
}
else
{
lcd.setCursor(0,0);
lcd.print("GSM Modem Found ");
}
}
if(gsm_count=='5')
{
lcd.setCursor(0,0);
lcd.print("Error in GSM modem");
}
}
void gsm_read_message()
{
while(Serial.available() > 0)
{
Rec_Data = Serial.read();
if( Rec_Data == '+' && msg_flg == 0 )
msg_flg=1;
else if( Rec_Data == 'C' && msg_flg == 1 )
msg_flg=2;
else if( Rec_Data == 'M' && msg_flg == 2 )
msg_flg=3;
else if( Rec_Data == 'T' && msg_flg == 3 )
msg_flg=4;
else if( Rec_Data == 'I' && msg_flg == 4 )
{
clear_buffer();
Rec_Data =0;
msg_flg=0;
delay(300);
array_clear();
Serial.println("AT+CMGR=1");
i=0;j=0;
}
else if( Rec_Data== 'G' && msg_flg == 3 )
msg_flg=4;
else if( Rec_Data== 'R' && msg_flg == 4 )
msg_flg=5;
else if( Rec_Data== ':' && msg_flg == 5 )
msg_flg=6;
else if( Rec_Data == '"' && msg_flg == 6 )
d_count++;
else if( Rec_Data != '"' && d_count==3 && msg_flg == 6)
number[i++] = Rec_Data;
else if( Rec_Data=='' && d_count>=5 && msg_flg == 8 )
msg_flag_2=1;
else if( Rec_Data!='#' && msg_flag_2 == 1 && msg_flg == 8 && Rec_Data!=0X0D && Rec_Data!=0X0A )
message[j++]=Rec_Data;
else if( Rec_Data=='#' && msg_flag_2 == 1 && msg_flg == 8)
{
msg_flag_2 = 2;
number
='\0';*

  • message[j]='\0';*
  • i=0;j=0;*
  • message_rcd=1;*
  • } *
  • }*
    }
    void array_clear()
    {
    *byte k=0; *
  • for( k=0;k<=15;k++)*
  • number[k]='\0';*
  • for( k=0;k<=160;k++)*
  • message[k]='\0';*
    }
    void clear_buffer()
    {
  • char reply=0;*
  • while(Serial.available() > 0)*
  • reply = Serial.read(); *
    }

hey, i am trying to interface gsm\sim900A with arduino uno using following codes,but it is unable to make phone call, plz guide me through this :

The circuit:

  • RX is digital pin 10 (connect to TX of GSM Modem)
  • TX is digital pin 11 (connect to RX of GSM Modem)
    */
    #include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);

Serial.println("Calling through GSM Modem");

// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
delay(2000);
mySerial.println("ATD81290255XX;"); // ATD81290255XX; -- watch out here for semicolon at the end!!

Serial.println("Called ATD81290255XX");
}

void loop() // run over and over
{
// print response over serial port
if (mySerial.available())
Serial.write(mySerial.read());
}

samsau

  1. You have attached your post to an unrelated thread with is not considered polite.
  2. You have not read the 'How to use this forum' notes. Please do so and amend your post as instructed. This includes using the code tags and providing links to the hardware used. Not to the Arduino... And the official Arduino shield does not use the SIM900 chip.
  3. Try prefixing the subscribers number with the international dialing code.

How to send AT commands to modem from arduino board and receive the reply from modem to display it in the LCD...
Give me the coding please....
our coding is not working..
[/quote]

hello bro,
This code will definitely work i have used simple c language

#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int lenth,lenth1,i=0,temp;
char str[100];
char name[25];
void setup()
{
lcd.begin(16,2);
Serial.begin(9600);
}
void loop()
{
lcd.setCursor(16,0);
lcd.print("ENGINEERS GARAGE");
Serial.println("AT+CNMI=2,2,0,0,0");
delay(100);
lcd.setCursor(16,0);
while(1)
{
for(int j=0;j<400;j++)
{
serialEvent();
delay(1);
}
if(temp==1)
{
i=0;
lenth1=0;
lcd.setCursor(0,1);
while(i<lenth)
{
if(str_=='*')_

  • {*
  • i++;*
    _ while(str*!='#')_
    _
    {_
    _ name[lenth1]=str;
    lenth1++;
    i++;
    }
    for(lenth1;lenth1<25;lenth1++)
    {
    name[lenth1]=' ';
    }
    }
    i++;
    }
    lcd.setCursor(16,0);
    delay(10);
    lcd.print(name);
    temp=0;
    lenth=0;
    }
    lcd.scrollDisplayLeft();
    serialEvent();
    delay(1);
    }
    }
    void serialEvent()
    {
    while (Serial.available())
    {
    char inChar = (char)Serial.read();
    str[lenth]=inChar;
    lenth++;
    if (inChar == '\n')
    {
    temp=1;
    }
    }
    }*_