In this article, we are going to make our own Caller ID detection using Arduino. Usually, there are several libraries over the internet, but recently I had some bad experiences with most of them. That is why I simplified the process so that we can easily integrate this function in our GSM project. So let’s find it out.

Disclaimer: Electricity is always dangerous. Proper skill is required to work with electricity. Do work at your own risk. The author will not be responsible for any misuse or harmful act or any mistake you make. The contents of this website are unique and copyright protected. Kindly don’t do any nonsensical act copying and claiming it as yours. Most of the articles published here are kept as open-source to help you. Take the knowledge for free and use it, but if you are interested you can buy the ready resources offered here. If you need any help or guide feel free to comment below, the author will try to help you. Thanks.

About GSM library:

There are lots of libraries for GSM on the Arduino platform. The most common one is Adafruit_FONA. The library is good for complete phone function. I personally used this library for different purposes. But the problem is, when using the caller ID detection function, the Arduino works fine it is used only a single feature.

As you may need to use this function for different purposes, so you may add some other functions. Then the problem comes in. The Arduino falls in deadloop.

And once this starts, no way to come back to work except restart the power. I was looking for a solution to this. And from that point, I wrote this simple code that we can use for caller ID detection that never falls in deadloop like that one.

But before that, you may need to know more about GSM modules. Here I used SIM800L the most common one. You can use similar modules.

The code:

#include <SoftwareSerial.h>
#define RX 4
#define TX 3
SoftwareSerial gsm = SoftwareSerial(TX, RX);


void setup()
{

  Serial.begin(115200);
  gsm.begin(4800);
  delay(1000);
  gsm.println("AT\r\n");delay(100);
  gsm.println("AT+CLIP=1\r\n");//enable caller id

}

void loop()
{
   
  while (gsm.available())
  {
    String line = gsm.readStringUntil('\n'); 
    int index_line = line.indexOf("+88");//find the position of phn_initial  
    index_line+=3;//start after +88, [3 digits leter] 
    line = line.substring(index_line, index_line+11); //seperate phone number from main String
    int line_len = line.length() + 1;
    char phn[line_len];
    line.toCharArray(phn, line_len);
    if (line_len >= 11)
    {
      Serial.print("Phn:");
      Serial.println(phn);
    }    
  }
}



//

Explanation:

When anyone calls to the number (SIM number of the module), it replies like this:

caller id detection using Arduino.

Here, “+CLIP: “+880197xxxx70″,145,””,0,””,0” is the String we found from the module’s serial terminal.

Now, if we find the index of ‘+88’ which is my country code. [Use as per your country code], we can easily identify the caller ID.

Let’s see what happens if we run our code.

Result:

caller id detection using Arduino.

Now, you can easily use this code in your project to identify caller ID using GSM modules.

Thanks for your time. I hope this article will help you in your GSM projects.

Loading

JLCPCB – Only $2 for PCB Prototype (Any Color)

24 Hours fast turnaround, Excellent quality & Unbeatable prices

$18 Welcome Bonus for new registrations Now!!! https://jlcpcb.com


You may check other articles: Interfacing multiple external EEPROM with Arduino through I2C


Lab Projects BD

This is a personal electronics blog. The author loves to write on different topics and shares his knowledge to help others.

0 Comments

Leave a Reply

Avatar placeholder

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