Saturday, January 17, 2015

Arduino code for Send and Receive SMS using GSM module.

This is a example program to send and receive sms using gsm module and arduino. I tested these code with the SIM900A gsm module.

____________________________________________________________________________________

/*
Press--> t: To Send Text Message.
r: To Receive Text Message.
*/

#include <SoftwareSerial.h>

SoftwareSerial mySerial(7, 8);

void setup()
{
  mySerial.begin(9600);               // the GPRS baud rate   
  Serial.begin(9600);    // the GPRS baud rate 
  delay(500);
}


void loop()
{
  if (Serial.available()>0)
   switch(Serial.read())
  {
    case 't':
      SendTextMessage();
      break;
    case 'r':
      RecieveTextMessage();
      break;
  }

 if (mySerial.available()>0)
   Serial.write(mySerial.read());
}

///SendTextMessage()
///this function is to send a sms
 void SendTextMessage()
{
  mySerial.println("AT+CMGF=1");    //Because we want to send the SMS in text mode
  delay(100);
  mySerial.println("AT+CMGS=\"+91******\"\r"); // change to the phone number you using 
  delay(100);
  mySerial.println("A test message!");//the content of the message
  delay(100);
  
  mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(100);
}

///RecieveTextMessage()
///this function is to show received a sms
 void RecieveTextMessage()
{
  mySerial.println("AT+CMGF=1\r");
  delay(200);
  
  //mySerial.println("AT+CNMI=2,2,0,0,0");
  //delay(200);
   
  //mySerial.println("AT+CSCS=\"GSM\"\r");
  //delay(100);
   
  mySerial.println("AT+CMGL=\"ALL\"\r"); // to read ALL the SMS in text mode
  delay(200);
  //mySerial.println("AT+CMGR=3\r");//  to read the SMS in text mode from location x
  //delay(100);
}

______________________________________________________________________________________

Related Posts:

  • DC Motor Control by LabVIEW This Video's about controlling a DC motor from LabVIEW The above video explains how to control DC motor with the help of arduino and labview, its possible to control 2 motors using L293D Motor IC, by using this motor… Read More
  • Virtual Prototyping in Solidworks and LabVIEW The above video explains about how to use solidworks and LabVIEW for real time simulation,  real time machining operation can be done using these soft-wares. Unlike other simulators that is inbuilt with many … Read More
  • How to connect Labview and Soliworks This video's about interfacing NI labview with SolidWorks. You need NI labview, NI softmotion and solidworks with Motion analysis to successfully do this testing on your own. More details are included in the video che… Read More
  • Robot Kinematics Using Labview, Solidworks and Arduino Virtual prototype of LR Mate 200ic This project uses solidworks, labview, softmotion and arduino. CAD model is created with help of SoldiWorks, Labview used for creating control singnals, Softmotion used for i… Read More
  • Automatic Light control using Labview and arduino This project is about automatically turning on LED's , when the light intensity goes low. It uses a LDR, 10k , 220 ohm resistors, and arduino uno . A very simple Easy to do automatic light controller in Labview , LDR… Read More

4 comments :

  1. Where to press 't' or 'r'?? Is it from the serial monitor??

    ReplyDelete
  2. i used this code but nothing to show it because i want to recieve sms from mobile on gsm..

    ReplyDelete
  3. Your code has worked wonders. Is there some code to read out the phone number and message body in a string

    ReplyDelete