0
#include <GSMSim.h>
#include <SoftwareSerial.h>
#define RX 7
#define TX 8
#define RESET 13
#define BAUD 9600


GSMSim gsm(RX, TX, RESET);

const int doorSensor= 2;
int doorSensorState= 0;
int lastdoorSensorState= 0;
const int buzzer= 5;
char* number = "+918909088171";

void setup() {
  // put your setup code here, to run once:

  pinMode(doorSensor,INPUT);
  pinMode(buzzer,OUTPUT);

  Serial.begin(9600);

  Serial.println("GSMSim Library - Module Information");
  Serial.println("");
  delay(1000);
  //gsm.start(); // baud default 9600
  gsm.start(BAUD);
  Serial.print("Manufacturer:\t\t");
  Serial.println(gsm.moduleManufacturer());
  delay(250);
  Serial.print("Model:\t\t\t");
  Serial.println(gsm.moduleModel());
  delay(250);
  Serial.print("Revision:\t\t");
  Serial.println(gsm.moduleRevision());
  delay(250);
  Serial.print("IMEI:\t\t\t");
  Serial.println(gsm.moduleIMEI());
  delay(250);
  Serial.print("IMSI:\t\t\t");
  Serial.println(gsm.moduleIMSI());
  delay(250);
  Serial.print("ICCID:\t\t\t");
  Serial.println(gsm.moduleICCID());
  delay(250);
  Serial.print("Is Connected?:\t\t");
  Serial.println(gsm.isRegistered());
  delay(250);
  Serial.print("Signal Quality:\t\t");
  Serial.println(gsm.signalQuality());
  delay(250);
  Serial.print("Operator:\t\t");
  Serial.println(gsm.operatorName());
  delay(250);
  Serial.print("Operator From Sim:\t");
  Serial.println(gsm.operatorNameFromSim());
  delay(250);
  delay(250);

  char* message = "Hello......                        Welcome To Automation...... You Are Connected......"; // message lenght must be <= 160. Only english characters.

  Serial.println("Sending Message --->");
  Serial.println(gsm.smsSend(number, message)); // if success it returns true (1) else false (0)
  delay(2000);
  Serial.println("Listing unread message(s).");
  Serial.println(gsm.smsListUnread()); // if not unread messages have it returns "NO_SMS"
  delay(500);
  Serial.println("Read SMS on index no = 1");
  Serial.println(gsm.smsRead(1)); // if no message in that index, it returns IXDEX_NO_ERROR  
  delay(500);
}

void loop() {

  switch (gsm.callStatus()) // Automatic Call Recieve 
  {
    case 0: // Nothing is happening
      break;
    case RINGING: // Yes! Someone is calling us
      delay(500);
      Serial.println("Call Recieved ");
      delay(500);
      Serial.println(gsm.callAnswer());       
      break;
  }

  /////////// Door Sensor programe \\\\\\\\\\\

  doorSensorState = digitalRead(doorSensor);
  if(doorSensorState != lastdoorSensorState )
  {
    if(doorSensorState == 0)
    {
      Serial.println("doorSensorState: OPEN");

      Serial.println("Sending Message --->");
      Serial.println(gsm.smsSend(number, "DOOR ALERT")); // if success it returns true (1) else false (0)
      delay(2000);
    }
  }  
  lastdoorSensorState = doorSensorState;

  delay(100);

  if(doorSensorState == 0)
  {
    Serial.println("doorSensorState: OPEN");
    digitalWrite(buzzer, LOW);   // turn buzzer and Led oN because door open 

    delay(100);  
    digitalWrite(buzzer, HIGH);    

    delay(100);
  }
  else
  {
    digitalWrite(buzzer, LOW);    // turn buzzer off because door closed 
  }   
  delay(100);
}

here i send message 2 times one is in void setup which i receive correctly but the second message which is in void loop that i get blank message what i do i using maker and hacker simm900a

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.