My Cart

How to Make Calls with Buttons Using 3G+GPS Mobile Kit

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 the voice call.

Ingredients:

    - 1 x 3G+GPS Mobile Kit:
    • 1x Platform
    • 1x 3G + GPS shield
    • 1x GPRS antenna
    • 4x Buttons
    • 4x 10kΩ 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 3G + GPS Shield, consult the main tutorial.

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 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 the VCC.

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.

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 2: The Code

Arduino:

Code:
/*  
 *  3G + GPS shield
 *  
 *  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:    Alejandro Gallego & 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);

  //Enables the use of command ATH
  sendATcommand("AT+CVHU=0", "OK", 10000);

  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:
/*  
 *  3G + GPS shield
 *  
 *  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:    Alejandro Gallego & Victor Boria
 */
 
//Include ArduPi library
#include "arduPi.h"

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

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

int8_t answer;
int onModulePin = 2;
int buttonA = 3;
int buttonB = 4;
int buttonC = 5;
int endbutton = 6;
char aux_str[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();
    
    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!!\n");
    delay(1000);
    
    //Enables the use of command ATH
    sendATcommand("AT+CVHU=0", "OK", 10000);
    
    printf("Press a button to call\n");
}

void loop(){ 

	if (digitalRead(buttonA)==1){
		printf("Calling phone number A: %s\n", phone_numberA);
		sprintf(aux_str, "ATD%s;", phone_numberA);
		sendATcommand(aux_str, "OK", 10000);
		delay(300);
	}

	if (digitalRead(buttonB)==1){
		printf("Calling phone number B: %s\n", phone_numberB);
		sprintf(aux_str, "ATD%s;", phone_numberB);
		sendATcommand(aux_str, "OK", 10000);
		delay(300);
	}

	if (digitalRead(buttonC)==1){
		printf("Calling phone number C: %s\n", phone_numberC);
		sprintf(aux_str, "ATD%s;", phone_numberC);
		sendATcommand(aux_str, "OK", 10000);
		delay(300);
	} 
	if (digitalRead(endbutton)==1){
		printf("Call disconnected\n");
		Serial.println("ATH");    // disconnects the existing call
		delay(300);
		}
}

/************************************************************************
 ****               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_answer1, 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) {
      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_answer1) != 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:
/*  
 *  3G + GPS shield
 *  
 *  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
 */

//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(" ");
  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);

  //Enables the use of command ATH
  sendATcommand("AT+CVHU=0", "OK", 10000);

  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");  
    Serial.println("Disconnectiong call");    
    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();
      Serial.print(response[x]);
      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;
}


        

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: