My Cart

How to Make a Call with Push Buttons Using Tracking Kit (GPRS + GPS)

Difficulty Level: Beginner -

1. Introduction

This tutorial allows the user to make a call to different numbers. Each button can be assigned to a number and originate a voice call. Pushing other button, you can end that voice call.

Ingredients:

    - 1 x Tracking Kit (GPRS + GPS):
    • 1x Platform
    • 1x GPRS+GPS Quadband Module (SIM908)
    • 1x GPRS antenna
    • 4x Buttons
    • 4x 10kΩ resistors
    • 1x Potentiometer
    • 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+GPS (SIM908) Shield, consult the main tutorial.

Step 1: Connection

Connect the GPRS antenna to the shield and then, connect the shield to the Arduino or to Raspberry Pi connection bridge. Connect the buttons and the resistors 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 3, 4, 5 and 6 to one leg of each pushbutton. That same leg of the button connects through a pull-down resistor (10kΩ) to ground. The other leg of the button connects to VCC supply.

When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to ground (through the pull-down resistor) and reads as LOW, or 0. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to VCC, so that the pin read as HIGH, or 1.

Step 2: The Code

Arduino:

Code:
/*  
 *  GPRS+GPS Quadband Module (SIM908)
 *  
 *  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. 
 *  a
 *  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:    Victor Boria
 */

//Enter here you data
const char pin_number[] = "****";         // Write the pin number of the SIM card
const char phone_numberA[] = "*********"; // Write here the number A to call
const char phone_numberB[] = "*********"; // Write here the number B to call
const char phone_numberC[] = "*********"; // Write here the number C to call

//Digital pin definitions
int onModulePin = 2; 
int buttonA = 3;
int buttonB = 4;
int buttonC = 5;
int endbutton = 6;

int8_t answer;
char aux_string[30];


void setup() {
  pinMode(onModulePin, OUTPUT);
  pinMode(buttonA, INPUT);
  pinMode(buttonB, INPUT);
  pinMode(buttonC, INPUT);
  pinMode(endbutton, INPUT);
  Serial.begin(115200);

  Serial.println("Starting...");
  power_on(); // Powering the module

  delay(3000);

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

  delay(3000);

  Serial.println("Connecting to the network...");
  
  //Check network registration
  while ( (sendATcommand("AT+CREG?", "+CREG: 0,1", 1000) ||
           sendATcommand("AT+CREG?", "+CREG: 0,5", 1000)) == 0 );

  Serial.println("Connected to the network!!");
  delay(1000);
  
  Serial.println("Press a button to call");
}

void loop() {
  //If button A is pressed call to number A
  if (digitalRead(buttonA) == 1) {
    sprintf(aux_string, "ATD%s;", phone_numberA); 
    sendATcommand(aux_string, "OK", 10000);
    delay(100);
  }
  //If button B is pressed call to number B
  if (digitalRead(buttonB) == 1) {
    sprintf(aux_string, "ATD%s;", phone_numberB);
    sendATcommand(aux_string, "OK", 10000);
    delay(100);
  }
  //If button C is pressed call to number C
  if (digitalRead(buttonC) == 1) {
    sprintf(aux_string, "ATD%s;", phone_numberC); //calls to number C
    sendATcommand(aux_string, "OK", 10000);
    delay(100);
  }

  //If endbutton is pressed disconnects the existing call
  if (digitalRead(endbutton) == 1) {
    Serial.println("ATH");   
    delay(100);
  }
}


/************************************************************************
 ****               Definition of functions                          ****
 ************************************************************************/

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);    // Initialize 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 (Serial.available() != 0) {
      // if there are data in the UART input buffer, reads it and checks for the asnwer
      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;
}

        

Raspberry Pi:

Code:
/*  
 *  GPRS+GPS Quadband Module (SIM908)
 *  
 *  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. 
 *  a
 *  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 MartĂ­nez
 */

//Include arduPi library
#include "arduPi.h"

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

//Enter here you data
const char pin_number[] = "****";         // Write the pin number of the SIM card
const char phone_numberA[] = "*********"; // Write here the number A to call
const char phone_numberB[] = "*********"; // Write here the number B to call
const char phone_numberC[] = "*********"; // Write here the number C to call

//Digital pin definitions
int onModulePin = 2; 
int buttonA = 3;
int buttonB = 4;
int buttonC = 5;
int endbutton = 6;

int8_t answer;
char aux_string[30];


void setup() {
  pinMode(onModulePin, OUTPUT);
  pinMode(buttonA, INPUT);
  pinMode(buttonB, INPUT);
  pinMode(buttonC, INPUT);
  pinMode(endbutton, INPUT);
  Serial.begin(115200);

  printf("Starting...\n");
  power_on(); // Powering the module

  delay(3000);

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

  delay(3000);

  printf("Connecting to the network...\n");
  
  //Check network registration
  while ( (sendATcommand("AT+CREG?", "+CREG: 0,1", 1000) ||
           sendATcommand("AT+CREG?", "+CREG: 0,5", 1000)) == 0 );

  printf("Connected to the network!!\n");
  delay(1000);
  
  printf("Press a button to call\n");
}

void loop() {
  //If button A is pressed call to number A
  if (digitalRead(buttonA) == 1) {
    sprintf(aux_string, "ATD%s;", phone_numberA); 
    sendATcommand(aux_string, "OK", 10000);
    delay(100);
  }
  //If button B is pressed call to number B
  if (digitalRead(buttonB) == 1) {
    sprintf(aux_string, "ATD%s;", phone_numberB);
    sendATcommand(aux_string, "OK", 10000);
    delay(100);
  }
  //If button C is pressed call to number C
  if (digitalRead(buttonC) == 1) {
    sprintf(aux_string, "ATD%s;", phone_numberC); //calls to number C
    sendATcommand(aux_string, "OK", 10000);
    delay(100);
  }

  //If endbutton is pressed disconnects the existing call
  if (digitalRead(endbutton) == 1) {
    Serial.println("ATH");   
    printf("Call disconnected\n");
    delay(500);
  }
}


/************************************************************************
 ****               Definition of functions                          ****
 ************************************************************************/

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);    // Initialize 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(Serial.available() != 0){    
            // if there are data in the UART input buffer, reads it and checks for the asnwer
            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 asnwer with time out
    while((answer == 0) && ((millis() - previous) < timeout));    

        return answer;
}

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

        

Intel Galileo:

Code:
/*  
 *  GPRS+GPS Quadband Module (SIM908)
 *  
 *  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. 
 *  a
 *  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 MartĂ­n
 */

//Enter here you data
const char pin_number[] = "****";         // Write the pin number of the SIM card
const char phone_numberA[] = "*********"; // Write here the number A to call
const char phone_numberB[] = "*********"; // Write here the number B to call
const char phone_numberC[] = "*********"; // Write here the number C to call

//Digital pin definitions
int onModulePin = 2; 
int buttonA = 3;
int buttonB = 4;
int buttonC = 5;
int endbutton = 6;

int8_t answer;
char aux_string[30];


void setup() {
  pinMode(onModulePin, OUTPUT);
  pinMode(buttonA, INPUT);
  pinMode(buttonB, INPUT);
  pinMode(buttonC, INPUT);
  pinMode(endbutton, INPUT);
  Serial.begin(115200);
  Serial1.begin(115200);

  Serial.println("Starting...");
  power_on(); // Powering the module

  delay(3000);

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

  delay(3000);

  Serial.println("Connecting to the network...");
  
  //Check network registration
  while ( (sendATcommand("AT+CREG?", "+CREG: 0,1", 1000) ||
           sendATcommand("AT+CREG?", "+CREG: 0,5", 1000)) == 0 );

  Serial.println("Connected to the network!!");
  delay(1000);
  
  Serial.println("Press a button to call");
}

void loop() {
  //If button A is pressed call to number A
  if (digitalRead(buttonA) == 1) {
    sprintf(aux_string, "ATD%s;", phone_numberA); 
    sendATcommand(aux_string, "OK", 10000);
    delay(100);
  }
  //If button B is pressed call to number B
  if (digitalRead(buttonB) == 1) {
    sprintf(aux_string, "ATD%s;", phone_numberB);
    sendATcommand(aux_string, "OK", 10000);
    delay(100);
  }
  //If button C is pressed call to number C
  if (digitalRead(buttonC) == 1) {
    sprintf(aux_string, "ATD%s;", phone_numberC); //calls to number C
    sendATcommand(aux_string, "OK", 10000);
    delay(100);
  }

  //If endbutton is pressed disconnects the existing call
  if (digitalRead(endbutton) == 1) {
    Serial1.println("ATH");   
    delay(100);
  }
}


/************************************************************************
 ****               Definition of functions                          ****
 ************************************************************************/

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);    // Initialize 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 (Serial1.available() != 0) {
      // if there are data in the UART input buffer, reads it and checks for the asnwer
      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;
}