How to Send and Receive Message from GSM Module using Arduino

Required components:

  • Arduino
  • GSM(900)
  • Jumpers
  • Bread board

program:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 10);

void setup()
{
  // Setting the baud rate of GSM Module
  mySerial.begin(9600);     
  // Setting the baud rate of Serial Monitor (Arduino)
  Serial.begin(9600);
  delay(100);
}


void loop()
{
  if (Serial.available()>0)
   switch(Serial.read())
  {
    case 's':
             SendMessage();
             break;
    case 'r':
             RecieveMessage();
             break;
  }

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


 void SendMessage()
{
  //Sets the GSM Module in Text Mode
  mySerial.println("AT+CMGF=1"); 
// Delay of 1000 milli seconds or 1 second   
  delay(1000);  
// Replace x with mobile number
  mySerial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); 
  delay(1000);
  mySerial.println("I am SMS from GSM Module");// The SMS text you want to send
  delay(100);
   mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
}


 void RecieveMessage()
{
   // AT Command to receive a live SMS
  mySerial.println("AT+CNMI=2,2,0,0,0"); 
  delay(1000);
 }

Leave a Reply

Your email address will not be published. Required fields are marked *