1

I want to give missed call to GSM module; how to do that? Whenever I call to GSM module, after 3 RINGs, it should be disconnected. How to do this?

#include <SoftwareSerial.h>

String string = "";
int ring=0;
int i;
//Create software serial object to communicate with SIM800L
 SoftwareSerial mySerial(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2
    
void setup() {
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);
      
  //Begin serial communication with Arduino and SIM800L
  mySerial.begin(9600);
    
  Serial.println("Initializing..."); 
}
    
void loop() {
  serialEvent();
  if (ring >= 1) {
    Serial.write("ATH");
  }
}
    
void serialEvent() {
  while (mySerial.available()) {
    char read_char = Serial.read();
    string += read_char;
    i++;

    if (string[i - 4] == 'R' && string[i - 3] == 'I' && string[i - 2] == 'N' && string[i - 1] == 'G') {
      ring = 1;
    }
  }
}
1
  • 3
    You're reading from Serial after checking mySerial.available(). Use a better name for the serial connected to the GSM module to avoid confusing yourself.
    – Mat
    Feb 3 '21 at 9:56

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.