How to use UNO board to control SIM900 module

How to use UNO board to control SIM900 module

Introduction

Today we will use UNO to control SIM900A module to send text message to our phone or make a call.

https://youtube.com/watch?v=T1jGzEhGAuY%3Frel%3D0

Required materials
1X  Adeept UNO Board
1X  SIM900A Module
1X  SIM card
1X  DC5V 1A Power
1X  Breadboard
Several jumper wires

The introduction of SIM900A Module
The GSM module employs SIM900 high-precision wireless GSMGPRS full four-frequency chip from SIM com Company and SMT packaging, and it combines with high-powered ARM926EJ-S core. It is suitable for cost-effective solution of mini-type equipment.

The module employs standard industrial interface, SIM900 is equipped with 850MHZ、900MHZ、1800MHZ、1900MHz four-frequency voice, text message, data and fax of GSM and GPRS, it is of high cohesiveness and low power consumption.

Technical specifications
full four frequency: 850、 900、 1800 、1900 MHz
GPRS multi-hotspot type 108
GPRS conforms to type B base station
GSM 22+ criterion
Type 4 (2 W @850 900 MHz)
Type 1 (1 W @ 18001900MHz)
Support SAIC (Single Antenna Interference Cancellation)
Controlled by compatible AT command (GSM 07.07, 07.05 and SIMCOM enhanced command)
Running at low power 0.1mA
Operating temperature  -40°C to +85 °C
AT reference command

Use any serial port to debug terminal and check “add new rows” or similar one. The serial windows above Arduino IDE 1.0 need to choose “Both NL& CR”,the lower IDE version can’t support this function.
As for AT command, it is a command used by communication module, which starts with “AT”, after the sending of AT command, it will return to the operating result which starts with “+”,  and if it goes wrong, it will return to “ERROR” , and if it is normal , it will send “OK” at the end of the message.
Next we will make examples of frequently used functions, the complex functions refer to SIM900_ATC document.
Testify the signal quality, use serial port to send the following instruction:
AT+CSQ
Now we can see the reply message as the following:
+CSQ: 11, 0
OK
Making a call (the semicolon after the instruction is necessary), you can change 10086(here 10086 is China Unicom) in the following instruction into the other phone numbers in your local area.
ATD10086;(carriage return)
Ring off
ATH
Answer the phone
ATA
Send text message
first, set as text mode:
AT+CMGF=1

set as using default International standard alphabetic character set of module to send text message

AT+CSCS?
Send to target phone number
AT+CMGS=”10086″(carriage return)
now the system will prompts “>”, input the text message directly.
> YE
The purpose of this text message is to send to 10086 for checking balance
0x1A ( sending in hexadecimal notation)
After sending, the system will display the following prompt, the number means the serial number of sending text messages
+CMGS: 115
OK
Receive the text message
if you receive the text message, the system will show the following prompt, the latter number means the amount of text messages in the SMS inbox:
+CMTI: “SM”,2
Sending the following AT command, the latter number is the SMS reference number. As we are using IRA encoding, the Chinese messages can’t be displayed, we can send English text message to test.
AT+CMGR=2

Connection diagram

Procedure code

/***********************************************************
File name:   AdeeptISM900A.ino
Website: www.adeept.com
E-mail: support@adeept.com
Author: Tom
Date: 2018/06/01
***********************************************************/
int val;           //Define variablesval
#define MAXCHAR 81 //recive buff max char
char aa[MAXCHAR];  //recive gsm model back signal
int j=0;           //recive index
int g_timeout=0;   //handing time
////////////////////////////////////////////////////
char ATE0[]="ATE0";
char CREG_CMD[]="AT+CREG?";
char SMS_send[]="AT+CMGS=18";
char ATCN[]="AT+CNMI=2,1";
char CMGF0[]="AT+CMGF=0";
char CMGF1[]="AT+CMGF=1";
char CMGR[12]="AT+CMGR=1";
char CMGD[12]="AT+CMGD=1";
/*************************************************/
#define SEND_MESSA_TO_YOUR "at+cmgs=\"180****1390\"\r\n"    //Send a text message to receive the mobile phone number
#define SEND_MESSA_CONTENT "Hello!  \n www.adeept.com "  //SMS content
#define CALL_YOU_TELNUMBER "ATD180****1390;\r\n"    //Call to accept the phone number
/*************************************************/
int readSerial(char result[]){
    int i = 0;
    while (Serial.available() > 0)
    {
        char inChar = Serial.read();
        if (inChar == '\n'){
            result[i] = '\0';
            Serial.flush();
            return 0;
         }
         if(inChar!='\r'){
            result[i]= inChar;
            i++;
            }
      }
}
void clearBuff(void){//Call texting to clear instructions
    for(j=0;j<MAXCHAR;j++)
        {
            aa[j]=0x00;
        }
        j=0;
}
int Hand(char *s){//Texting, calling, texting, calling instructions
    delay(200);
    clearBuff();
    delay(300);
    readSerial(aa);
    if(strstr(aa,s)!=NULL)     //Detecting the connection between the microcontroller and the module
        {
            g_timeout=0;
            clearBuff();
            return 1;
        }
    if(g_timeout>50)
        {
            g_timeout=0;
            return -1;
        }
    g_timeout++;
    return 0;
}
void send_english(void){   //Texting
    clearBuff();
    Serial.println(CMGF1);
    delay(500);
    while(Hand("OK")==0);
      
    clearBuff();
    Serial.println(SEND_MESSA_TO_YOUR);
    delay(500);
    while(Hand(">")==0);
      
    Serial.println(SEND_MESSA_CONTENT);  //Send text messages
    delay(100);
    Serial.print("\x01A");      //Send end symbol
    delay(10);
      
    delay(1000);
    while(Hand("OK")==0);
}
void send_call(void){ //Make a call
    clearBuff();
    Serial.println(CALL_YOU_TELNUMBER); //Make a call
    delay(2000);
    while(Hand("OK")==0);
}
void setup (void) { 
         
    Serial.begin(115200);//Set the baud rate is 115200
} 
void loop (void)
{ 
    send_english();  //Texting
    delay(5000);
    send_call();     //Make a call
    while(1);
}  Experimental phenomenon
Press on the reset button on UNO, our phone will receive text message “Hello! www.adeept.com”and gets a phone call from SIM900A module.
Notice: sometimes it may goes wrong in sending text message and making a call with SIM900A module, the reason is the power supply isn’t enough, or you use the incompatible SIM card, or the signal of the phone is poor or not covered.

 

Leave a Reply