Skip to content

Instantly share code, notes, and snippets.

@rafitc
Created October 31, 2020 04:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafitc/8bd58eec35f47d391b127030061c7e85 to your computer and use it in GitHub Desktop.
Save rafitc/8bd58eec35f47d391b127030061c7e85 to your computer and use it in GitHub Desktop.
#include <SoftwareSerial.h>
//Create software serial object to communicate with SIM800L
SoftwareSerial mySerial(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2
String callerID;
int flag = 0;
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...");
mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
updateSerial();
mySerial.println("AT+CLIP=1"); //To get caller ID
updateSerial();
}
void loop()
{
updateSerial();
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while(mySerial.available())
{
callerID = mySerial.readString(); //Read serial and make a string
if(callerID.indexOf("9747165032")>0){ //compare with a defined number
flag = 1;
Serial.println("Registered");
mySerial.println("ATH"); //to Refuse call
//Execute your loop here.
}
else if(flag){ //To avoid multiple time of execution
Serial.println("Not Registered");
flag = 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment