My Cart

How to Make a Caller Identifier with LEDs Using GSM/GPRS Mobile Kit

Difficulty Level: Beginner -

Introduction

This tutorial allows to use your platform as a caller ID. Each LED can be assigned to a number. When this number calls to the module, the corresponding LED lights on.

Ingredients:

    - 1 x GSM/GPRS Mobile Kit:
    • 1x Platform
    • 1x GPRS/GSM QUADBAND MODULE (SIM900)
    • 1x GPRS antenna
    • 3x LEDs
    • 3x 220Ω resistors
    • 1x Breadboard
    • 1x External power supply
    • 1x Programming cable
    • Jumper Wires

Preparation Time: 30 minutes

Buy now
NOTE: Depending on the platform chosen to develop the project, the ingredients and the schematics shown in this tutorial can vary.

This project can be developed with Arduino or Intel Galileo. It is also compatible with Raspberry Pi using the Raspberry Pi to Arduino shields connection bridge.

For further information about the GPRS/GSM QUADBAND MODULE (SIM900) Shield, consult the main tutorial.

WARNING: In Raspberry Pi, GPIO voltage levels are 3.3 V and are not 5 V tolerant. There is no over-voltage protection on the board. Digital inputs use a 3V3 logic level and are not tolerant of 5V levels, such as you might find on a 5V powered Arduino. Extreme caution when working with GPIO, you may damage your Raspberry Pi, your equipment and potentially yourself and others. Doing so is at your own risk!

Step 1: Connection

Connect the GPRS antenna to the shield and then, connect the shield to Arduino or to Raspberry Pi connection bridge. Connect the LEDs and the resistors (220Ω) in the breadboard as you can see in the next diagram.

Connect two wires, red and black, to the two long rows on the side of the breadboard to provide access to the VCC supply (5V in Arduino and 3.3V in Raspberry Pi) and ground. Then, connect digital pin 9, 10 and 11 to one leg of each resistor. That other leg of the resistor is connected to the cathode (negative leg) of the LED. The other legs of the LEds (anode) connect to VCC supply.

Step 2: The Code

Arduino:

Code:
/*  
 *  GPRS/GSM Quadband Module (SIM900)
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis Miguel MartĂ­
 */

#define LED1 9
#define LED2 10
#define LED3 11
//phone numbers to do the caller ID check
const char number1[] = {"*********"};
const char number2[] = {"*********"};
const char number3[] = {"*********"};

int8_t answer;
int onModulePin = 2;
char aux_string[30];
char phone_number[9];
char received[13];

void setup() {

  pinMode(onModulePin, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  digitalWrite(LED1, HIGH);
  digitalWrite(LED2, HIGH);
  digitalWrite(LED3, HIGH);
  Serial.begin(115200);

  Serial.println("Starting...");
  power_on();

  delay(3000);

  // sets the PIN code
  sendATcommand("AT+CPIN=****", "OK", 2000);

  delay(3000);
  Serial.println("Connecting to the network...");

  while ( (sendATcommand("AT+CREG?", "+CREG: 0,1", 500) ||
           sendATcommand("AT+CREG?", "+CREG: 0,5", 500)) == 0 );

}

void loop() {

  //program is allways waiting for a +CLIP to confirm a call was received
  //it will receive a +CLIP command for every ring the calling phone does
  while (answer = sendATcommand("", "+CLIP", 1000)) {
    //answer is 1 if sendATcommand detects +CLIP
    if (answer == 1)
    {
      Serial.println("Incoming call");

      for (int i = 0; i < 13; i++) {
        //read the incoming byte:
        while (Serial.available() == 0)
        {
          delay (50);
        }
        //stores phone number
        received[i] = Serial.read();
      }
      Serial.flush();
      byte j = 0;
      //phone number comes after quotes (") so discard all bytes until find'em
      while (received[j] != '"') j++;
      j++;
      for (byte i = 0; i < 9; i++) {

        phone_number[i] = received[i + j];

      }
    }
    for (int i = 0; i < 9; i++) {
      // Print phone number:
      Serial.print(phone_number[i]);
    }

    switch (compareNumber(phone_number)) {

      case 0:

        Serial.print("Unkwon number");

      case 1:

        Serial.print("****** is calling");
        digitalWrite(LED1, LOW);
        delay(1000);
        digitalWrite(LED1, HIGH);
        break;

      case 2:

        Serial.print("****** is calling");
        digitalWrite(LED2, LOW);
        delay(1000);
        digitalWrite(LED2, HIGH);
        break;

      case 3:

        Serial.print("****** is calling");
        digitalWrite(LED3, LOW);
        delay(1000);
        digitalWrite(LED3, HIGH);
        break;

    }
  }
}

void power_on() {

  uint8_t answer = 0;

  // checks if the module is started
  answer = sendATcommand("AT", "OK", 2000);
  if (answer == 0)
  {
    // power on pulse
    digitalWrite(onModulePin, HIGH);
    delay(3000);
    digitalWrite(onModulePin, LOW);

    // waits for an answer from the module
    while (answer == 0) {   // send AT every two seconds and wait for the answer
      answer = sendATcommand("AT", "OK", 2000);
    }
  }

}

int8_t sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout) {

  uint8_t x = 0,  answer = 0;
  char response[100];
  unsigned long previous;

  memset(response, '\0', 100);    // Initialice the string

  delay(100);

  while ( Serial.available() > 0) Serial.read();   // Clean the input buffer

  Serial.println(ATcommand);    // Send the AT command


  x = 0;
  previous = millis();

  // this loop waits for the answer
  do {
    // if there are data in the UART input buffer, reads it and checks for the asnwer
    if (Serial.available() != 0) {
      response[x] = Serial.read();
      x++;
      // check if the desired answer is in the response of the module
      if (strstr(response, expected_answer) != NULL)
      {
        answer = 1;
      }
    }
    // Waits for the asnwer with time out
  } while ((answer == 0) && ((millis() - previous) < timeout));

  return answer;
}

//compares the incoming call phone number with known phones
byte compareNumber(char* number) {

  for (byte i = 0; i < 9; i++) {

    if (number[i] == number1[i]) {

      if (i == 8) return 1;

    } else i = 9;

  }
  for (byte i = 0; i < 9; i++) {

    if (number[i] == number2[i]) {

      if (i == 8) return 2;

    } else i = 9;

  }
  for (byte i = 0; i < 9; i++) {

    if (number[i] == number3[i]) {

      if (i == 8) return 3;

    } else i = 9;

  }
  return 0;
}
        

Raspberry Pi:

Code:
/*  
 *  GPRS/GSM Quadband Module (SIM900)
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Marcos Martinez
 */
 
#include "arduPi.h"

#define LED1 9
#define LED2 10
#define LED3 11
//phone numbers to do the caller ID check
const char number1[] = {"*********"};
const char number2[] = {"*********"};
const char number3[] = {"*********"};

char pin[] = "******";

int8_t answer;
int onModulePin = 2;
char aux_str[30];
char phone_number[9];
char received[13];

void power_on();
int8_t sendATcommand(const char* ATcommand, const char* expected_answer, unsigned int timeout);
byte compareNumber(char* number);

void setup() {

  pinMode(onModulePin, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
  Serial.begin(115200);

  printf("Starting...\n");
  power_on();

  delay(3000);

  // sets the PIN code
  sprintf(aux_str, "AT+CPIN=%s", pin);
  sendATcommand(aux_str, "OK", 2000);

  delay(3000);
  printf("Connecting to the network...\n");

  while ( (sendATcommand("AT+CREG?", "+CREG: 0,1", 500) ||
           sendATcommand("AT+CREG?", "+CREG: 0,5", 500)) == 0 );
           
  printf("Connected to the network... Waiting for a call\n");
}

void loop() {

  //program is always waiting for a +CLIP to confirm a call was received
  //it will receive a +CLIP command for every ring the calling phone does
  while (answer = sendATcommand("", "+CLIP", 1000)) {
    //answer is 1 if sendATcommand detects +CLIP
    if (answer == 1)
    {
      printf("Incoming call\n");

      for (int i = 0; i < 13; i++) {
        //read the incoming byte:
        while (Serial.available() == 0)
        {
          delay (50);
        }
        //stores phone number
        received[i] = Serial.read();
      }
      Serial.flush();
      byte j = 0;
      //phone number comes after quotes (") so discard all bytes until find'em
      while (received[j] != '"') j++;
      j++;
      for (byte i = 0; i < 9; i++) {

        phone_number[i] = received[i + j];

      }
    }
        
    switch (compareNumber(phone_number)) {

      case 0:

        printf("Unknown number\n");
        break;

      case 1:

        printf("%s is calling\n", number1);
        digitalWrite(LED1, HIGH);
        delay(1000);
        digitalWrite(LED1, LOW);
        break;

      case 2:

        printf("%s is calling\n", number2);
        digitalWrite(LED2, HIGH);
        delay(1000);
        digitalWrite(LED2, LOW);
        break;

      case 3:

        printf("%s is calling\n", number3);
        digitalWrite(LED3, HIGH);
        delay(1000);
        digitalWrite(LED3, LOW);
        break;

    }
  }
}

void power_on() {

  uint8_t answer = 0;

  // checks if the module is started
  answer = sendATcommand("AT", "OK", 2000);
  if (answer == 0)
  {
    // power on pulse
    digitalWrite(onModulePin, HIGH);
    delay(3000);
    digitalWrite(onModulePin, LOW);

    // waits for an answer from the module
    while (answer == 0) {   // send AT every two seconds and wait for the answer
      answer = sendATcommand("AT", "OK", 2000);
    }
  }

}

int8_t sendATcommand(const char* ATcommand, const char* expected_answer, unsigned int timeout) {

  uint8_t x = 0,  answer = 0;
  char response[100];
  unsigned long previous;

  memset(response, '\0', 100);    // Initialice the string

  delay(100);

  //while ( Serial.available() > 0) Serial.read();   // Clean the input buffer

  Serial.println(ATcommand);    // Send the AT command


  x = 0;
  previous = millis();

  // this loop waits for the answer
  do {
    // if there are data in the UART input buffer, reads it and checks for the asnwer
    if (Serial.available() != 0) {
      response[x] = Serial.read();
      printf("%c", response[x]);
      x++;
      // check if the desired answer is in the response of the module
      if (strstr(response, expected_answer) != NULL)
      {
		printf("\n");
        answer = 1;
      }
    }
    // Waits for the answer with timeout
  } while ((answer == 0) && ((millis() - previous) < timeout));

  return answer;
}

//compares the incoming call phone number with known phones
byte compareNumber(char* number) {

  for (byte i = 0; i < 9; i++) {

    if (number[i] == number1[i]) {

      if (i == 8) return 1;

    } else i = 9;

  }
  for (byte i = 0; i < 9; i++) {

    if (number[i] == number2[i]) {

      if (i == 8) return 2;

    } else i = 9;

  }
  for (byte i = 0; i < 9; i++) {

    if (number[i] == number3[i]) {

      if (i == 8) return 3;

    } else i = 9;

  }
  return 0;
}


int main (){
	setup();
	while(1){
		loop();
	}
	return (0);
}

        

Intel Galileo:

Code:
/*  
 *  GPRS/GSM Quadband Module (SIM900)
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Jorge Casanova, Luis Martin
 */

#define LED1 9
#define LED2 10
#define LED3 11
//phone numbers to do the caller ID check
const char number1[] = {"*********"};
const char number2[] = {"*********"};
const char number3[] = {"*********"};

int8_t answer;
int onModulePin = 2;
char aux_string[30];
char phone_number[9];
char received[13];

void setup() {

  pinMode(onModulePin, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  digitalWrite(LED1, HIGH);
  digitalWrite(LED2, HIGH);
  digitalWrite(LED3, HIGH);
  Serial.begin(115200);
  Serial1.begin(115200);

  Serial.println("Starting...");
  power_on();

  delay(3000);

  // sets the PIN code
  sendATcommand("AT+CPIN=****", "OK", 2000);

  delay(3000);
  Serial.println("Connecting to the network...");

  while ( (sendATcommand("AT+CREG?", "+CREG: 0,1", 500) ||
           sendATcommand("AT+CREG?", "+CREG: 0,5", 500)) == 0 );

}

void loop() {

  //program is allways waiting for a +CLIP to confirm a call was received
  //it will receive a +CLIP command for every ring the calling phone does
  while (answer = sendATcommand("", "+CLIP", 1000)) {
    //answer is 1 if sendATcommand detects +CLIP
    if (answer == 1)
    {
      Serial.println("Incoming call");

      for (int i = 0; i < 13; i++) {
        //read the incoming byte:
        while (Serial1.available() == 0)
        {
          delay (50);
        }
        //stores phone number
        received[i] = Serial1.read();
      }
      Serial1.flush();
      byte j = 0;
      //phone number comes after quotes (") so discard all bytes until find'em
      while (received[j] != '"') j++;
      j++;
      for (byte i = 0; i < 9; i++) {

        phone_number[i] = received[i + j];

      }
    }
    for (int i = 0; i < 9; i++) {
      // Print phone number:
      Serial.print(phone_number[i]);
    }

    switch (compareNumber(phone_number)) {

      case 0:

        Serial.print("Unkwon number");

      case 1:

        Serial.print("****** is calling");
        digitalWrite(LED1, LOW);
        delay(1000);
        digitalWrite(LED1, HIGH);
        break;

      case 2:

        Serial.print("****** is calling");
        digitalWrite(LED2, LOW);
        delay(1000);
        digitalWrite(LED2, HIGH);
        break;

      case 3:

        Serial.print("****** is calling");
        digitalWrite(LED3, LOW);
        delay(1000);
        digitalWrite(LED3, HIGH);
        break;

    }
  }
}

void power_on() {

  uint8_t answer = 0;

  // checks if the module is started
  answer = sendATcommand("AT", "OK", 2000);
  if (answer == 0)
  {
    // power on pulse
    digitalWrite(onModulePin, HIGH);
    delay(3000);
    digitalWrite(onModulePin, LOW);

    // waits for an answer from the module
    while (answer == 0) {   // send AT every two seconds and wait for the answer
      answer = sendATcommand("AT", "OK", 2000);
    }
  }

}

int8_t sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout) {

  uint8_t x = 0,  answer = 0;
  char response[100];
  unsigned long previous;

  memset(response, '\0', 100);    // Initialice the string

  delay(100);

  while ( Serial1.available() > 0) Serial1.read();   // Clean the input buffer

  Serial1.println(ATcommand);    // Send the AT command


  x = 0;
  previous = millis();

  // this loop waits for the answer
  do {
    // if there are data in the UART input buffer, reads it and checks for the asnwer
    if (Serial1.available() != 0) {
      response[x] = Serial1.read();
      x++;
      // check if the desired answer is in the response of the module
      if (strstr(response, expected_answer) != NULL)
      {
        answer = 1;
      }
    }
    // Waits for the asnwer with time out
  } while ((answer == 0) && ((millis() - previous) < timeout));

  return answer;
}

//compares the incoming call phone number with known phones
byte compareNumber(char* number) {

  for (byte i = 0; i < 9; i++) {

    if (number[i] == number1[i]) {

      if (i == 8) return 1;

    } else i = 9;

  }
  for (byte i = 0; i < 9; i++) {

    if (number[i] == number2[i]) {

      if (i == 8) return 2;

    } else i = 9;

  }
  for (byte i = 0; i < 9; i++) {

    if (number[i] == number3[i]) {

      if (i == 8) return 3;

    } else i = 9;

  }
  return 0;
}
        

Links and Documentation

Related Tutorials

Datasheets and Manuals



If you are interested in Internet of Things (IoT) or M2M projects check our open source sensor platform Waspmote which counts with more than 100 sensors available to use 'off the shelf', a complete API with hundreds of ready to use codes and a low consumption mode of just 0.7µA to ensure years of battery life.

Know more at:

Get the Starter Kits at: