Simple Phone - Call & SMS Using GSM Module & Arduino
Simple Phone - Call & SMS Using GSM Module & Arduino
Simple Phone - Call & SMS Using GSM Module & Arduino
Arduino Projects
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 1/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
8 Video Tutorial: Call & SMS using GSM Module & Arduino
incoming or outgoing call, SMS sent received status, and also time
elapsed. The 4x4 Keypad is used to enter the number or type an
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 2/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
You can check the advance version of this project here: Nextion
Display Based Mobile Phone using GSM & Arduino
This simple homemade phone can be useful for final year projects
and also for understanding the functioning of the GSM module
using some AT Commands functions. The components can be
purchased from the link given below. All the circuit diagram
connections, as well as every explanation, is included below.
You can check one of our earlier project based on GSM Module:
Gas Leakage Detector with SMS Alert using GSM Module &
Arduino
Bill of Materials
Following are the list of components required for the project:
Simple Homemade Phone- Call & SMS using GSM Module &
Arduino
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 3/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
COMPONENTS
S.N. DESCRIPTION QUANTITY
NAME
R3
Development
Board
Module
6 Improve
Speaker delivery
8 ohm 0.2 1 accuracy
https://amz Lear
watt Speaker
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 4/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
7 Mic
COMPONENTS Condenser 1 https://amz
S.N. DESCRIPTION QUANTITY
NAME Phone Mic
Supply Adapter
Supply Adapter
11 Breadboard - 1 https://amz
class 12/ class 10 (optional) and supports the GPRS coding schemes
CS-1, CS-2, CS-3 and CS-4. With a tiny configuration of 24243mm,
devices.
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 5/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
and extended TCP/IP AT commands which are very useful for data
transfer applications.
Features
synchronously.
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 6/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
Accelerate sign
Improve accuracy for billin
delivery on your app or site
connect the 16x2 LCD to Arduino analog pins A0, A1, A2, A3, A4,
A5. Similarly connect 4x4 Keypad to Arduino digital pins 11, 10, 9, 8,
1. Make calls
2. Receive calls
3. Send SMS
4. Receive SMS
the number)
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 8/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
By pressing button ‘A’ you will be in Send call mode. LCD will
To Send SMS
Press ‘B’ key for configuring shield in send message mode. ‘Enter
digit number
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 9/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
Source Code/Program:
The code for making Call & SMS using GSM Module & Arduino is
given below. The code is developed by Agam Tyagi. The full code
credit goes to him and Mr. Devvrat Arya as well as Mr. Harsha Deva
Boley Shetty.
#include <SoftwareSerial.h>
#include<String.h>
#include <LiquidCrystal.h>
SoftwareSerial mySerial(2,3); // These pins are connected to
Improve delivery accuracy
LiquidCrystal lcd(14, 15, 16, 17, 18, 19); // These are conn Lear
String number= "";
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 10/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
String action= "WT"; //String codes: RC =Receive call, RM= R
// Receive sms Strings
String Response ="";
String sms="";
String Type;
String Caller_id;
String Text;
String SP_name="";
char character;
char quote= 0x22;
// Global Flags
bool Send_m=false;
bool sms_Receive_mode_off=true;
bool Receive_mode=false;
bool msg_Receive=false;
bool time_registered=false;
bool msg_fetched=false;
bool on_call=false;
bool start_Receive=false;
bool flag=true;
int sec,minutes; // Clock variables
long c_start;
long c_time;
int i=0;
int indexOfQuotes[10];
double time_start;
double time_current;
double operational_time;
/********* Keypad Variables**********/
int r1=11;
int r2=10;
int r3=9;
int r4=8;
int c1=7;
int c2=6;
int c3=5;
int c4=4;
Improve delivery accuracy Lear
int colm1;
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 11/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
int colm2;
int colm3;
int colm4;
char value;
//
char num1;
void setup()
{
Serial.begin(9600);
Serial.println("GSM startrd");
mySerial.begin(9600);
mySerial.setTimeout(2000);
Serial.setTimeout(2000);
initilise();
lcd.begin(16, 2);
get_SP();
}
void loop()
{
Serial.println("Action: "+ action); //Reports it current mod
while(action=="WT") // Its wait for SMS and Calls in this lo
{
if(sms_Receive_mode_off) //So, This turns on the SMS recieve
{ delay(1000);
On_sms_Receive_mode();
}
if(flag)
{
Serial.println("Receive_ready");
flag=false;
print_head("Connected to:"); // Service provide name is prin
print_content(SP_name);
clear_Serial();
}
if(Receiving_on()) // FINALLY, the module is set to receive,
{
Extract_type();
}
Improve delivery accuracy Lear
else
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 12/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 13/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 14/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
}
}
// Extracton process
SP_name= (SP_name.substring(SP_name.indexOf('"')+1,SP_name.l
Serial.println("Connected to: "+ SP_name);
}
// Fuciton to print current signal strength on lcd
void update_signal_strength (void)
{ String Network;
long Strength;
mySerial.println("AT+CSQ");
mySerial.println();
delay(500);
while(mySerial.available())
{
char character=mySerial.read();
Network.concat(character);
}
Network=Network.substring(Network.indexOf(':')+2,Network.ind
Strength= Network.toInt(); // Strength Int value here
Strength=(Strength*100/31); // MAX strength= 31
lcd.setCursor(13,2);
lcd.print(int(Strength));
lcd.print('%');
}
//It recives a the char value of key pressed and stores it i
void get_request (void)
{
value=Return_Keypad_Values();
event(value);
}
// Select the apt mode as per the input
void event(char func)
{
switch (func)
{
Improve delivery accuracy Lear
case 'A':
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 15/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
Improve delivery accuracy
Serial.println("SMS sent");
Lear
print_head("SMS Sent to");
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 16/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
print_content(number);
delay(2000);
return(true); //SMS sent succussfuly
}
return(false); // Failed attempt
}
/*
* Input: (string:num,)
* Output bool( t=sent f=failed)
* Function to send call to number
*/
bool send_call (String number)
{
mySerial.println("AT");
delay(500);
if(GSM_operational())
{
//Number dialing
Serial.println("Calling to :" +number);
print_head("Calling to");
print_content(number);
mySerial.println("ATD"+ number +";"); // AT command for dial
mySerial.println();
on_call=true;
return(true);
}
return(false);
}
// This is to switch on the messaging mode of Gsm
void On_sms_Receive_mode (void)
{
mySerial.print("ATE0");
delay(500);
if(GSM_operational())
mySerial.print("AT");
delay(500);
if(GSM_operational())
delay(500);
Improve delivery accuracy
mySerial.print("AT+CMGF=1"); // Setup in msging mode
Lear
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 17/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
if (GSM_operational())
{
mySerial.print("AT+CNMI=2,2,0,0,0\r" ); //Prints the msg on
delay(500);
while(mySerial.available())
{
char response = mySerial.read();
Serial.println(response);
}
Serial.println("Receive mode On");
sms_Receive_mode_off=false; //turn it on off
}
}
/*
* Input: none
* Output: True: A response( call or sms) incoming, Or false
*
*/
bool Receiving_on (void)
{
bool Response_available=false;
if(mySerial.available())
{
while(!halt_fetch()) //In case of incoming recieve until hal
{
while(mySerial.available())
{
if(!time_registered) //Capture the time of start of message
{
time_start=millis();
time_registered=true;
}
char character=mySerial.read();
Response.concat(character);
Serial.print(character); // Store as a string
}
}
Serial.println("Response Received"); //Looks like we got som
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 18/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
}
return (Response_available);
}
/*
*The function is created to halt or to indicate the end of r
*It does that by a timeout of 3sec or Response Text limit of
*Input: none
*Output: Boolean, T= halt fetching F= Wait for message
*/
bool halt_fetch (void)
{
bool halt=false;
if(time_registered)
{
time_current=millis();
operational_time=time_current-time_start;
}
if(operational_time>3000 || Response.length()==200 ) // Halt
{
halt=true;
operational_time=0;
}
return halt;
}
/*
* It extracts the Response and caller id
* It does that by quotes position.
* Caller id is between first and second quotes
* While, Text message is after last quotes
*/
void Extract_type (void)
{
if(valid_input())
{
Serial.println("Valid respone");
extract();
Improve delivery accuracy
Serial.println(Response); //In case u want to see everything
Lear
Serial.println("Type: ");
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 19/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
Serial.print(Type);
Serial.println("Caller id : ");
Serial.println(Caller_id);
Serial.println("Text: ");
Serial.println(Text);
callORsms();
Serial.print(Caller_id);
}
time_registered=false;
Response=""; //Clear string for refresh incoming
}
/*
* Checks the validity condition,
* True: Its call or msg Resonse
* False: it is some junk
*/
bool valid_input (void)
{
bool validity;
validity=(( Response.indexOf('+') > 0) && (Response.indexOf(
if(!validity)
{
Serial.println("invalid input");
}
return (validity);
}
// Find the indexes of all the quotes in the stirng and sets
void extract(void)
{
int Length,i,index=0;
Length=Response.length();
for(i=0;i<=Length;i++)
{
{
Improve delivery accuracy
if(Response.charAt(i)==quote)
Lear
indexOfQuotes[index]=i;
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 20/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
index++;
}
}
Type=Response.substring(1,indexOfQuotes[0]);
Caller_id=Response.substring(indexOfQuotes[0]+1,indexOfQuote
Text=Response.substring(indexOfQuotes[5]+3);
Serial.println("Extracted");
}
// Determine weather the response is of call or sms
void callORsms (void)
{
if( Type.indexOf("LIP")>0) //Call string consist this( +CLIP
{ action="RC";
Serial.println("Call from: ");}
else if(Type.indexOf("MT")>0 ) // Msg stirng consist (+CMT)
{ action="RM";
Serial.println("Message from: ");}
}
// Waits till customer press * or #
void WaitForPickup (void)
{
char key;
bool user_wait = true; //default state
while(user_wait)
{ user_wait=check_termination();
key=Return_Keypad_Values();
if(key=='*') //picking up reponse
{
mySerial.println("ATA");
mySerial.println();
Serial.println("Call picked up");
print_head("Call picked up");
print_content(Caller_id);
delay(1000);
user_wait=false;
on_call=true;
}
if(key=='#') //Termination action
{
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 21/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
print_head("Call Terminated");
delay(1000);
print_content(Caller_id);
on_call=false;
user_wait=false;
}
}
}
/*
* This function is used after two user get connected on a ca
* It waits '#' to terminate or 'NO CARRIER' on serial monito
* It updates clock untill waiting
* */
void terminate_call (void)
{
char key;
bool user_wait = true; //default state
start_clock();
while(user_wait)
{
user_wait=check_termination();
key=Return_Keypad_Values();
if(key=='#')
{
mySerial.println("ATH"); //Termination action
mySerial.println();
Serial.println("Call Terminated");
print_head("Call Terminated");
delay(1000);
print_content(Caller_id);
user_wait=false;
}
else
{
update_clock();
}
}
Improve delivery accuracy Lear
on_call=false;
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 22/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
}
// Function to start a clock
void start_clock (void)
{
lcd.clear();
c_start=millis();
sec=0;
minutes=0;
lcd.print("On call");
}
// Function to update the value as arduino internal clock
void update_clock (void)
{
long current= millis();
if(current-c_start>1000)
{
sec++;
c_start=current;
}
if(sec>59)
{
minutes++;
sec=-0;
}
lcd.setCursor(0,1);
if(minutes<10)
{lcd.print('0');}
lcd.print(minutes);
lcd.print(':');
if(sec<10)
{lcd.print('0');}
lcd.print(sec);
}
// Fuction to Show sms on a LCD
void Show_sms (void)
{
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 23/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
// Enhance modularity
bool user_wait = true;
while(user_wait)
{key=Return_Keypad_Values();
if(key=='*')
{
print_head(Text.substring(0,16)); // This can scroll SMS
print_content(Text.substring(16,32));
delay(2000);
print_head(Text.substring(16,32));
print_content(Text.substring(32,48));
delay(2000); //A scroll fuction can be made
Serial.println(Text);
user_wait=false;
}
if(key=='#')
{
print_head("OK");
Serial.println("MSG Terminated");
delay(500);
user_wait=false;
}
}
}
//True if starkey is pressed
bool Starkey_pressed (void)
{ char key;
key=Return_Keypad_Values();
return (key=='*');
}
//True if Hashkey is pressed
bool Hashkey_pressed (void)
{ char key;
key=Return_Keypad_Values();
return (key=='#');
}
//Check if 'NO CARRIER' is printer on Serial monitor
Improve delivery accuracy
bool check_termination (void)
Lear
{
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 24/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
bool check=true;
String listen_no="";
while(mySerial.available())
{
char data= mySerial.read();
Serial.print(data);
listen_no.concat(data);
}
if(listen_no.indexOf("CAR")>0) // I check for only CAR
{ check=false; }
return check;
}
// A Fuciton to check the lenth of number calling should be
bool valid_number (void)
{
bool valid=false;
if(number.length()==13) // condition here
{valid=true;}
else
{print_head("Invalid input");
delay(1000);
}
return valid;
}
//Essential command to determine the state of GSM module
bool GSM_operational(void)
{
int count =0;
bool Status=false;
mySerial.println();
while(1)
{
if (mySerial.available()>0)
{
char data = mySerial.read();
if( data == 'O' || data == 'K') //Its working properly
{
Serial.println("OK");
Status=true;
break;
}
Improve delivery accuracy Lear
if( data == 'E' || data == 'R' || data== 'O') // Working yet
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 25/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
{
Serial.println("GSM not functional");
Status=false;
break;
}
}
count++;
delay(10);
if (count == 100)
{
Serial.println("GSM not connected"); // No reponse for AT co
Status=false;
break;
}
}
return Status;
}
void clear_Serial (void)
{
while(mySerial.available())
{
char character=mySerial.read();
Serial.print(character);
}
}
/***********************************************************
* Keypad Firmware Ahead *
************************************************************
/*
* input: none
* Output: A 13 digit number
* Waits till user enter a ten Digit number
*/
String Take_input (void)
{ String num="+91";
int len=0;
int len2;
while (len <= 13)
{
len=num.length();
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 26/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 27/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
digitalWrite(r1,LOW);
digitalWrite(r2,HIGH);
digitalWrite(r3,HIGH);
digitalWrite(r4,HIGH);
}
void row2()
{
digitalWrite(r1,HIGH);
digitalWrite(r2,LOW);
digitalWrite(r3,HIGH);
digitalWrite(r4,HIGH);
}
void row3()
{
digitalWrite(r1,HIGH);
digitalWrite(r2,HIGH);
digitalWrite(r3,LOW);
digitalWrite(r4,HIGH);
}
void row4()
{
digitalWrite(r1,HIGH);
digitalWrite(r2,HIGH);
digitalWrite(r3,HIGH);
digitalWrite(r4,LOW);
}
void ReadRows()
{
colm1=digitalRead(c1);
colm2=digitalRead(c2);
colm3=digitalRead(c3);
colm4=digitalRead(c4);
}
char Return_Keypad_Values(void)
{
row1();
ReadRows();
delay(100);
if(colm1==LOW)
{
Serial.println("1");
delay(200);
return '1';
}
{
Improve delivery accuracy
else if(colm2==LOW)
Lear
Serial.println("2");
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 28/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
delay(200);
return '2';
}
else if(colm3==LOW)
{
Serial.println("3");
delay(200);
return '3';
}
else if(colm4==LOW)
{
Serial.println("A");
delay(200);
return 'A';
}
row2();
ReadRows();
delay(100);
if(colm1==LOW)
{
Serial.println("4");
delay(200);
return '4';
}
else if(colm2==LOW)
{
Serial.println("5");
delay(200);
return '5';
}
else if(colm3==LOW)
{
Serial.println("6");
delay(200);
return '6';
}
else if(colm4==LOW)
{
Serial.println("B");
delay(200);
return 'B';
}
row3();
ReadRows();
delay(100);
Improve delivery accuracy Lear
if(colm1==LOW)
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 29/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
{
Serial.println("7");
delay(200);
return '7';
}
else if(colm2==LOW)
{
Serial.println("8");
delay(200);
return '8';
}
else if(colm3==LOW)
{
Serial.println("9");
delay(200);
return '9';
}
else if(colm4==LOW)
{
Serial.println("C");
delay(200);
return 'C';
}
row4();
ReadRows();
delay(100);
if(colm1==LOW)
{
Serial.println("*");
delay(200);
return '*';
}
else if(colm2==LOW)
{
Serial.println("0");
delay(200);
return '0';
}
else if(colm3==LOW)
{
Serial.println("#");
delay(200);
return '#';
}
{
Improve delivery accuracy
else if(colm4==LOW)
Lear
Serial.println("D");
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 30/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
delay(200);
return 'D';
}
return 'a';
}
/***********************************************************
* LCD functions Ahead *
************************************************************
//Print out the Heading On lCD
void print_head (String str)
{ lcd.clear();
lcd.setCursor(0,0);
lcd.print(str);
}
//Print secondary content on LCD
void print_content (String str)
{
lcd.setCursor(0,1);
lcd.print(str);
}
Improve
Video Tutorial: Calldelivery accuracy
& SMS using GSM Lear
Module & Arduino
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 31/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
DIY Phone - Incoming/Outgoing Call & SMS Using GSM Module &
Arduino
You can check the advance version of this project here: Nextion
3 Comments
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 32/33
11/29/22, 9:18 PM Simple Phone: Call & SMS using GSM Module & Arduino
hustensaftholga
June 16, 2020 at 12:21 AM
Loading...
Reply
sara
September 30, 2020 at 3:07 AM
Loading...
Reply
manuel
June 30, 2021 at 7:07 PM
hi, i’m also interested of doing this kind of project. Can you be
contacted for this stuff to provide technical help?
Loading...
Reply
https://how2electronics.com/call-sms-using-gsm-module-arduino/ 33/33