Tutorial to Interface GSM SIM900A With Arduino

359K117163

Intro: Tutorial to Interface GSM SIM900A With Arduino

Description

SIM900A Modem is built with Dual Band GSM/GPRS based SIM900A modem from SIMCOM. It works on frequencies 900/ 1800 MHz. SIM900A can search these two bands automatically. The frequency bands can also be set by AT Commands. The baud rate is configurable from 1200-115200 through AT command. The GSM/GPRS Modem is having internal TCP/IP stack to enable you to connect with internet via GPRS. SIM900A is an ultra compact and reliable wireless module. This is a complete GSM/GPRS module in a SMT type and designed with a very powerful single-chip processor integrating AMR926EJ-S core, allowing you to benefit from small dimensions and cost-effective solutions.

Specification

  • Dual-Band 900/ 1800 MHz

  • GPRS multi-slot class 10/8GPRS mobile station class B

  • Compliant to GSM phase 2/2+

  • Dimensions: 24*24*3 mm

  • Weight: 3.4g

  • Control via AT commands (GSM 07.07 ,07.05 and SIMCOM enhanced AT Commands)

  • Supply voltage range : 5V

  • Low power consumption: 1.5mA (sleep mode)

  • Operation temperature: -40°C to +85 °

STEP 1: Material Preparation

In this tutorial, you will need :

1. GSM SIM900A (MINI V3.9.2)
2. Arduino Uno Board and USB
3. Jumper Wire
4. Power adapter 5V
5. SIM card
6. Breadboard

STEP 2: Booting Up SIM900A

1. Insert your SIM card to GSM module and lock it. (picture 1 and 2)
2. power up your gsm by connecting it to Arduino's 5V and GND (picture 3)
3. Connect the Antenna (picture 4)
4. Now wait for some time (say 1 minute) and see the blinking rate of ‘status LED’ or ‘network LED’ (D6, refer picture 5) //GSM module will take some time to establish connection with mobile network//
5. Once the connection is established successfully, the status/network LED will blink continuously every 3 seconds. You may try making a call to the mobile number of the sim card inside GSM module. If you hear a ring back, the gsm module has successfully established network connection.

STEP 3: Pin Connection

You can see a TTL pin with 3VR, 3VT, 5Vr, 5VT, VCC and GND on your sim900a near your power supply pin. You have to connect GSM's 5VT to Arduino D9 and GSM's 5VR to Arduino's D10 for serial communication between arduino and sim900a module.

STEP 4: Basic AT Command

1. To change sms sending mode : AT+CMGF=1

mySerial.println("AT+CMGF=1");

2. To read SMS in text mode : AT+CNMI=2,2,0,0,0

mySerial.println("AT+CNMI=2,2,0,0,0");

3. To make a call : ATD+60XXXXXXXXX; //replace X with number you want to call, change +60 to your country code

mySerial.println("ATD+60XXXXXXXXX;"); 

4. To disconnect / hangup call : ATH

mySerial.println("ATH");

5. To redial : ATDL

mySerial.println("ATDL");

6. To receive a phone call : ATA

mySerial.println("ATA");

STEP 5: Library

SoftwareSerial is a library of Arduino which enables serial data communication through other digital pins of Arduino. The library replicates hardware functions and handles the task of serial communication. To be able to interface gsm module with arduino, you will have to download this library and extract it into your Arduino's libraries.

STEP 6: Sample Source Code

Download the sample source code below and open it on your Arduino IDE. Select the correct board and port and upload it into your Arduino Uno Board.

STEP 7: Serial Monitor

After you has succesfully uploaded your source code, open your serial monitor. Serial monitor will display as shown in the picture above.

STEP 8: Result : Call / Redial

1. As you key-in c : to make a call, gsm will read the ATD command and make a call to a phone number you have upload in your source code. (Picture 1 and 2)

2. When you key-in h : to disconnect/hangup call, gsm will read the ATH command and disconnect the connection. (Picture 3)

3. When you key-in e : to redial, gsm will read the ATDL command and redialing previous number it has called.(Picture 4)

4. When there is an incoming call, you can see RING printed on serial monitor and you can click i : to receive a call and GSM's ATA command will be carried out and you will be connected to a call connection. (Picture 5)

STEP 9: Result : Send and Receive SMS

1. Key-in s to send SMS. Recepient's number and text message printed on serial monitor. NOTE : You can edit the recepient's phone number and text message on your source code.

2. When gsm receive a message, text message and number will be printed on serial monitor.

STEP 10: Video Demonstration


This video shows how SIM900A MINI make a call, receive a call, send sms, receive sms, redial and hangup call based on the sample source code uploaded in this tutorial.

77 Comments

Apakah bisa telepon berbicara 2 arah ? Tolong jawab saya please
Hi, i used your code as it is, but hangup and receive calls successfully have done but not sending sms and other. Shall i know whats the cause. please help me in this.

/*THIS TUTORIAL USED GSM SIM900A MINI V3.9.2
Connect 5VT to D9 and 5VR to D10
Feed GSM SIM900A with Arduino's 5V
Code by IDAYU SABRI - MYBOTIC
*/
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 10);//tx, rx
char msg;
char call;
void setup()
{
mySerial.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
Serial.println("GSM SIM900A BEGIN");
Serial.println("Enter character for control option:");
Serial.println("h : to disconnect a call");
Serial.println("i : to receive a call");
Serial.println("s : to send message");
Serial.println("r : ReceiveMessage");
Serial.println("c : to make a call");
Serial.println("e : to redial");
Serial.println();
delay(100);
}
void loop()
{
if (Serial.available()>0)
switch(Serial.read())
{
case 's':
SendMessage();
break;
case 'r':
ReceiveMessage();
break;
case 'c':
MakeCall();
break;
case 'h':
HangupCall();
break;
case 'e':
RedialCall();
break;
case 'i':
ReceiveCall();
break;
}
if (mySerial.available()>0)
Serial.write(mySerial.read());
}
void SendMessage()
{
Serial.println("Sending Message");
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"+917799036041\"\r"); // Replace x with mobile number +91
delay(1000);
mySerial.println("sim900a sms");// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void ReceiveMessage()
{
Serial.println("Received Message");
mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to recieve a live SMS
delay(1000);
if (mySerial.available()>0)
{
msg=mySerial.read();
Serial.print(msg);
}
}
void MakeCall()
{
mySerial.println("ATD+917799036041;"); // ATDxxxxxxxxxx; -- watch out here for semicolon at the end!!
Serial.println("Calling "); // print response over serial port
delay(5000);
}
void HangupCall()
{
mySerial.println("ATH");
Serial.println("Hangup Call");
delay(1000);
}
void ReceiveCall()
{
mySerial.println("ATA");
Serial.println("Received Call");
delay(1000);
{
call=mySerial.read();
Serial.print(call);
}
}
void RedialCall()
{
mySerial.println("ATDL");
Serial.println("Redialing");
delay(1000);
}

Bro please explain the following coding
#define trigPin1 A5////right
#define echoPin1 A4
#define irs A0
#define m1 2
#define m2 3

#define buzzer A2

long duration, distance,sensor1,sensor2;
String latitude ="28.6759786";//28.6759786,77.4357733
String longitude="";
int temp=0,i,ir=0;
boolean Serial_status=0;
int counter =0;
void setup()
{
Serial.begin(9600); ///baudrate bps
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(buzzer, OUTPUT);
pinMode(m1, OUTPUT);
pinMode(m2, OUTPUT);
//digitalWrite(buzzer,HIGH);
delay(10000);
digitalWrite(buzzer,HIGH);
delay(1000);
digitalWrite(buzzer,LOW);
delay(1000);
// tracking();
}

void loop()
{
ir=digitalRead(irs);
ultrasensor(trigPin1, echoPin1);
sensor1 = distance;
Serial.println(sensor1);
//delay(50);
if(ir==LOW)
{
digitalWrite(buzzer, HIGH);
digitalWrite(m1, LOW);
digitalWrite(m2, LOW);
tracking();
}
else if ((sensor1=2))
{
digitalWrite(buzzer, HIGH);
digitalWrite(m1, LOW);
digitalWrite(m2, LOW);
tracking1();
}

else
{
digitalWrite(buzzer,LOW);
digitalWrite(m1, HIGH);
digitalWrite(m2, HIGH);
}
delay(100);
}

void init_sms()
{
Serial.println("AT+CMGF=1");
delay(400);
Serial.println("AT+CMGS=\"+918742960961\""); // use your 10 digit cell no. here
delay(400);
}
void init_sms1()
{
Serial.println("AT+CMGF=1");
delay(400);
Serial.println("AT+CMGS=\"+919368389316\""); // use your 10 digit cell no. here
delay(400);
}

void send_data(String message)
{
Serial.println(message);
delay(200);
}

void send_sms()
{
Serial.write(26);
}

void tracking()
{
init_sms();
send_data("Track fault");
//send_data(latitude);
//send_data("Longitude:");
//send_data(longitude);
send_sms();
delay(5000);
init_sms1();
send_data("Track fault");
//send_data(latitude);
//send_data("Longitude:");
//send_data(longitude);
send_sms();
delay(5000);
}

void tracking1()
{
init_sms();
send_data("Obstraction Ahead");

send_sms();
delay(5000);
init_sms1();
send_data("Obstraction Ahead");
send_sms();
delay(5000);
}

void ultrasensor(int trigPin,int echoPin)
{
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
}
Hey Guy
I work with you it but it does not work my predefined number such as sms sent call phone, anything . Please explain me are you ok
I am making the project 'railway track detection system using Arduino '
Here is the coding of Arduino
#define trigPin1 A5////right
#define echoPin1 A4
#define irs A0
#define m1 2
#define m2 3

#define buzzer A2

long duration, distance,sensor1,sensor2;
String latitude ="28.6759786";//28.6759786,77.4357733
String longitude="";
int temp=0,i,ir=0;
boolean Serial_status=0;
int counter =0;
void setup()
{
Serial.begin(9600); ///baudrate bps
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(buzzer, OUTPUT);
pinMode(m1, OUTPUT);
pinMode(m2, OUTPUT);
//digitalWrite(buzzer,HIGH);
delay(10000);
digitalWrite(buzzer,HIGH);
delay(1000);
digitalWrite(buzzer,LOW);
delay(1000);
// tracking();
}

void loop()
{
ir=digitalRead(irs);
ultrasensor(trigPin1, echoPin1);
sensor1 = distance;
Serial.println(sensor1);
//delay(50);
if(ir==LOW)
{
digitalWrite(buzzer, HIGH);
digitalWrite(m1, LOW);
digitalWrite(m2, LOW);
tracking();
}
else if ((sensor1=2))
{
digitalWrite(buzzer, HIGH);
digitalWrite(m1, LOW);
digitalWrite(m2, LOW);
tracking1();
}

else
{
digitalWrite(buzzer,LOW);
digitalWrite(m1, HIGH);
digitalWrite(m2, HIGH);
}
delay(100);
}

void init_sms()
{
Serial.println("AT+CMGF=1");
delay(400);
Serial.println("AT+CMGS=\"+918742960961\""); // use your 10 digit cell no. here
delay(400);
}
void init_sms1()
{
Serial.println("AT+CMGF=1");
delay(400);
Serial.println("AT+CMGS=\"+919368389316\""); // use your 10 digit cell no. here
delay(400);
}

void send_data(String message)
{
Serial.println(message);
delay(200);
}

void send_sms()
{
Serial.write(26);
}

void tracking()
{
init_sms();
send_data("Track fault");
//send_data(latitude);
//send_data("Longitude:");
//send_data(longitude);
send_sms();
delay(5000);
init_sms1();
send_data("Track fault");
//send_data(latitude);
//send_data("Longitude:");
//send_data(longitude);
send_sms();
delay(5000);
}

void tracking1()
{
init_sms();
send_data("Obstraction Ahead");

send_sms();
delay(5000);
init_sms1();
send_data("Obstraction Ahead");
send_sms();
delay(5000);
}

void ultrasensor(int trigPin,int echoPin)
{
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
}
Anyone please can explain the circuit diagram of
Hey!!!
Can u plez help me out????
what does "No Dial Tone" error means????
Is it necessary to use 2G sim or okay with any generation????
Can I make this module to send and receive message simultaneously? I want my project to send and receive in real-time.
I've tried this project but how come the readings I get from the arduino to the gsm is like this H⸮⸮⸮⸮B⸮i H⸮⸮⸮⸮B⸮i. Can anyone help me?
I have succeeded in this project using Arduino Mega.
To those whom not yet get it, here is the tips.
1. Coding is Good. No need to Worry about That.
2. Need Extra power Supply. For me, I use power supply unit of 5V to Vin (Arduino Mega)
3. I use pin 2 and 3 for 5VT and 5VR (remember to change it in coding).
Remember, TX (Arduino) goes to RX (sim900a) and vice versa. (i think they don't mention that in here)

Done.
Email me if you guys don't understand. Ill help.

Hi there. May i check if there any different thing i need to do if i am using Arduino Mega instead? i am not able to get it working despite following the setup..
can i use a nano sim card on the gsm sim900a?? PLEASE HELP!

u can't. need to use the original size. gsm sim900a do not support nano sim card. u need to use sim card adapter if you have nano sim card.
I connected the gsm with arduino as stated, it responds to commands like AT+CFUN and some other than relating to sim card functionality, i have inserted a working simcard and still brings up CME ERROR 10, I tried enabling the sim detection command AT+CSDT and inserted sim, still same error for calling. When i unplug and power on the module again AT+CSDT goes back to 0. Is there something I'm missing
Hi, may i know how can i use the message function to send a text to multiple contact?
Hi, I have been trying to run DTMF commands on SIM900A. My firmware version is Revision:1137B10SIM900A32_ST_2012
It rejects AT+DDET commands. I looked into AT command set for SIM900 and it lacks a mention of DDET commands.
People have written about using AT+DDET on SIM900 without any issues.
Can you guide me how can I use incoming DTMF on SIM900A
Hye. I also get the same output.. if I send "AT" so gsm it responds "4", supposedly "OK" or "Error".

3 days stuck on this problem. HELP!!!!
Doesn't nodemcu works on 3.3v levels and gsm on 5v levels. How did you integrate the two, because you haven't told about that.
SIM900A mini module has seperate Rx,Tx pins for both 3.3V and 5V.
Namely:
5VT -> 5V Tx
5VR -> 5V Rx
3VT -> 3.3V Tx
3VR -> 3.3V Rx
More Comments