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:
Handling electricity carries inherent risks. It’s essential to have the appropriate skills to manage it safely. Proceed at your own risk, as the author disclaims responsibility for any misuse, harm, or errors. All content on this website is unique and copyrighted; please avoid unauthorized copying. While most articles are open-source for your benefit, feel free to use the knowledge provided. If you find our resources helpful, consider purchasing available materials to support our work.
For assistance or guidance, leave a comment below; the author is committed to helping. Some articles may contain affiliate links that support the author with a commission at no additional cost to you. Thank you for your understanding and support.
Table of Contents
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:
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:
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.
For Professional Designs or Help:
You may check other articles: Interfacing multiple external EEPROM with Arduino through I2C
0 Comments