bclose

Receive calls and SMS

OBJECTIVES

 

 

    • Receive calls and SMS.
    • Identify who calls us
    • Show the SMS on the serial monitor.
 

BILL OF MATERIALS

Arduino UNO GSM/GPRS Shield
Dupont Wires Arduino Power Source

Receiving calls

 

We saw in the previous session how to connect and start the GPRS module, and if someone tried at that time to call the card that we have placed in the SIM900, you will have seen how it gives tone normally.

However, you will not have seen anything that indicates that you are receiving a call, although if you look we will see how one of the LEDs on the card goes off while it is received. So what we’re going to do is let us know by the serial monitor when you receive them.

In principle the only difference to reach the loop will be that we declare a global variable of type char to save the characters that come from the SIM900.

char incoming_char = 0; // Variable to save the characters sent by the SIM900

In the loop we will check that characters are being sent from the SIM900 and we will show them through the serial monitor.

void loop()
   {
      if (SIM900.available() > 0)
         {
            incoming_char = SIM900.read(); //Save the character that arrives from the SIM900
            Serial.print(incoming_char); //Save the character that arrives from the SIM900
         }
   }

If we try to make a call to the number you have on the SIM900 card you will see that the serial monitor will show the word “RING”, once for each tone, and it will end with a “NO CARRIER”.

monitor serie llamada sim900

But many times it can be very useful to know who is calling us to, for example, take an action only if you call us a certain number (which we will see in the next session). For this we will use the command “AT + CLIP = 1 \ r”. If we want to deactivate it we only have to return it to 0. And with this we would have the complete program to receive calls.

#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8); //10 and 11 for the Mega Arduino. Configure the serial port for the SIM900

char incoming_char = 0; // Variable to store the characters sent by the SIM900

void setup()
   {
      //digitalWrite(9, HIGH); // Uncomment to activate the power of the card by Software
      //digitalWrite(9, LOW);
      delay (5000);  // Wait some time to turn on the GPRS and power the card
      SIM900.begin(19200); // Set serial port speed for the SIM900
      Serial.begin(19200); // Set the serial port speed of the Arduino
      Serial.println("OK");
      delay (1000);
      SIM900.println("AT + CPIN = \"XXXX\""); // AT command to enter the card PIN
      delay(25000); //Time to find the network
      Serial.println("PIN OK");
      SIM900.print("AT+CLIP=1\r"); // Activate the call identification.
      delay(1000);
}

void loop()
   {
      if (SIM900.available() > 0)
         {
             incoming_char = SIM900.read(); //Save character from SIM900
             Serial.print(incoming_char); //Show it in the serial monitor
         }
   }
monitor serie sim900 ring clip

 

RECEIVING SMS

 

To receive SMS messages correctly, we only have to include a couple of AT commands in the setup. We already know it from the previous session, which configures the module to be able to send and receive SMS “AT + CMGF = 1 \ r”. And we will also include the command “AT + CNMI = 2,2,0,0,0 \ r” which configures it so that it sends us the serial SMS messages that arrive to us.

So the complete program to receive calls and SMS would look like this:

#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8); //Configure serial port. 10 and 11 for Arduino Mega

char incoming_char = 0; //Variable to store incoming characters from SIM900

void setup()
   {
      //digitalWrite(9, HIGH); //Uncomment to activate software power on
      //delay(1000); 
      //digitalWrite(9, LOW);
      delay (5000);  // Wait some time to turn on the GPRS and power the card
      SIM900.begin(19200); // Set serial port speed for SIM900
      Serial.begin(19200); // Set serial port speed for Arduino
      Serial.println("OK");
      delay (1000);
      SIM900.println("AT + CPIN = \"XXXX\""); //Comando AT para introducir el PIN de la tarjeta
      delay(25000); //Time to find Network
      Serial.println("PIN OK");
      SIM900.print("AT+CLIP=1\r"); // Activate the identification of calls
      delay(1000);
      SIM900.print("AT+CMGF=1\r"); // Set the text mode to send or receive messages
      delay(1000);
      SIM900.print("AT+CNMI=2,2,0,0,0\r"); // Configure the module to show us the SMS received by serial communication
      delay(1000);
   }

void loop()
   {
      if (SIM900.available() > 0)
         {
            incoming_char = SIM900.read(); // Store the character that arrives from the SIM900
            Serial.print(incoming_char); // Show the character in the serial monitor
         }
   }

And when we receive a message we will be shown by the serial monitor both the number from which it is sent and the content of the SMS, with the date and time of sending. And if we look, unlike the calls, the number will come with the international prefix, in my case the +34 that belongs to Spain.

SMS monitor serie sim900

You can download the full program here: receive_call and SMS.

In the next session we will use what we have learned so that our Arduino can contact us if necessary, and to make certain orders using calls and SMS, and making sure that he only responds to us. In it you will find a more worked program in which, among other things, we are going to use a function to send the AT commands and make sure that the module response is what we are looking for.

Resumen de la sesión

 

In this session we have learned several important things:

 
    • How to receive calls and SMS and display them through the serial port.
    • To identify who is calling us.
    • We already know how to receive and send calls and SMS.
 
 
 

LikeUsOnFacebook_Icon

No Comments

Give a Reply