Dr. Kayarvizhy N Dr. Kayarvizhy N

Internet of Things

GSM Module – Call/SMS

August 25, 2016All posts

Configuration and Testing

Serial commands are available to configure and test the GSM Module. The below link provide you command set for GSM serial communication

https://kayarvizhy.com/wp-content/uploads/2015/09/GSM-AT-Commands.pdf

Arduino                     GSM

pin 2 (Rx)                   Tx

pin 3 (Tx)                   Rx

GND                           GND

GSM requires 12V external power supply

 

Serial Communication between Arduino board and GSM Module through Serial commands.

#include <SoftwareSerial.h>

SoftwareSerial cell(2,3);

char incomingchar=0;


void setup() {
  Serial.begin(9600);
  cell.begin(9600);
}

void loop() {
  
 if(cell.available()>0)
 {
   incomingchar=cell.read();
   Serial.print(incomingchar);
 }

 if(Serial.available()>0)
 {
   incomingchar=Serial.read();
   cell.print(incomingchar);
 }
}

The below program make a call as an alert when Light intensity is below 800

Arduino                     GSM

pin 2 (Rx)                   Tx

pin 3 (Tx)                   Rx

GND                           GND

GSM requires 12V external power supply

 

#include <SoftwareSerial.h>
SoftwareSerial cell(2,3);

void setup() {
 cell.begin(9600);
 delay(500);
 Serial.begin(9600);

}

void loop() {

  int val=analogRead(A0);
  Serial.println(val);
  delay(1000);

  if (val<800)
  {
     Serial.println("CALLING..........");
     cell.println("ATD+919900502934;");
     delay(20000);
   }
 

}

The below program sends a SMS alert when light intensity is below 800

#include <SoftwareSerial.h>
SoftwareSerial cell(2,3);

void setup() {
 cell.begin(9600);
 delay(500);
 Serial.begin(9600);

}

void read_and_print_from_GSM() {
 if (cell.available()) {
    while (cell.available()) {
      Serial.write(cell.read());
    }
  } 
}


void loop() {

  int val=analogRead(A0);
  Serial.println(val);
  delay(1000);

  if (val<800)
  {
     Serial.println ("Sending an SMS...");
    cell.println("AT+CMGF=1");
    delay(1000);
    read_and_print_from_GSM();
  
    cell.println("AT+CMGS=\"+919900502934\"");
    delay(1000);
    if (cell.find(">")) {
      char s[100];
      sprintf (s,"The light is down to %d...",val);
      cell.println(s);
      cell.write(0x1a);
      
      delay(20000);
      read_and_print_from_GSM();
      
    }
   }
 

}

The below program receive SMS to control the LED (SMS “LED ON” will switch on the LED and SMS “LED OFF” will switch off the LED)

#include<SoftwareSerial.h>
SoftwareSerial cell(2,3);

   void readfn()
   {
     
  
      if (cell.available()) {
       while (cell.available()) {
      Serial.write(cell.read());
      }
       }
   }
   
void setup() {
  pinMode(11,OUTPUT);
  Serial.begin(9600);
  cell.begin(9600);
  cell.println("AT");
  delay(1000);
  readfn();
  //New SMS alert
  cell.println("AT+CNMI=1,2,0,0,0");
 }


void loop() {


 if(cell.available())
 {
  String message =cell.readString();
  Serial.println(message);
  if(message.indexOf("LED ON")>0)
  {
    digitalWrite(11,HIGH);
  }
  else if(message.indexOf("LED OFF")>0)
  {
    digitalWrite(11,LOW);
  }
  else
  {
    Serial.println ("Nothing to do...");
  }
}

}

 

 

 

 

 

 

0 0 votes
Article Rating
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Oldest
Newest Most Voted