$USD
  • EUR€
  • £GBP
  • $USD
TUTORIALS Arduino

Using the SIM900A GSM Module with the Arduino

DFRobot Apr 09 2018 1730

The SIM900A is that other module from SIMCOM popularly used as a GSM shield for sending and receiving SMS. I’ve already covered the SIM800L, now let’s look at the SIM900A breakout board.

 

The SIM900A Breakout Board

Similar to the SIM800L module, the SIM900A breakout board has eight pinouts. They don’t have labels so allow me to provide them for you:


 

The primary difference between the SIM900A and the SIM800L is that this board doesn’t have Bluetooth and FM support. But the AT command set for both are identical which means we can use the same library!

The SIM900A breakout board has a 5V and a 4.2V version. Mine is the 5V version with the “V5.1” print near the VCC pin. This version can be powered by a 4.5 V to 5.5V source. There’s no information on what the 4.2V version looks like. I will update this post once the information is found.

 

Arduino Connection

The module has 3.3V TTL levels which means connecting its Rx pin directly to an Arduino’s Tx pin is a no-no. Here’s a diagram you can use to connect the breakout board to an Arduino UNO:

We can then use the same sketches we used in the SIM800L tutorial.

 

Sending SMS

For the sketch explanation, refer to the SIM800L article.

#include <SoftwareSerial.h> #include "Adafruit_FONA.h" #define FONA_RX 2 #define FONA_TX 3 #define FONA_RST 4 char replybuffer[255]; SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX); Adafruit_FONA fona = Adafruit_FONA(FONA_RST); uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0); void setup() {    while (!Serial);    Serial.begin(115200);    Serial.println(F("FONA basic test"));    Serial.println(F("Initializing....(May take 3 seconds)"));    fonaSS.begin(4800);    if (! fona.begin(fonaSS)) {        Serial.println(F("Couldn't find FONA"));    while (1);    }    Serial.println(F("FONA is OK"));    char sendto[21], message[141];    flushSerial();    Serial.print(F("Send to #"));    readline(sendto, 20);    Serial.println(sendto);    Serial.print(F("Type out one-line message (140 char): "));    readline(message, 140);    Serial.println(message);    if (!fona.sendSMS(sendto, message)) {    Serial.println(F("Failed"));    } else {        Serial.println(F("Sent!"));    } } void loop() {} void flushSerial() {    while (Serial.available())    Serial.read(); } uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout) {    uint16_t buffidx = 0;    boolean timeoutvalid = true;    if (timeout == 0) timeoutvalid = false;    while (true) {        if (buffidx > maxbuff) {        break;    }    while(Serial.available()) {        char c = Serial.read();        if (c == '\r') continue;        if (c == 0xA) {            if (buffidx == 0) // the first 0x0A is ignored            continue;            timeout = 0; // the second 0x0A is the end of the line            timeoutvalid = true;            break;        }        buff[buffidx] = c;        buffidx++;        }    if (timeoutvalid && timeout == 0) {        break;    }    delay(1);  }  buff[buffidx] = 0; // null term  return buffidx; }
 

Reading SMS

#include &lt;SoftwareSerial.h&gt; #include "Adafruit_FONA.h" #define FONA_RX 2 #define FONA_TX 3 #define FONA_RST 4 char replybuffer[255]; SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX); Adafruit_FONA fona = Adafruit_FONA(FONA_RST); uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0); void setup() {    while (!Serial);    Serial.begin(115200);    Serial.println(F("FONA basic test"));    Serial.println(F("Initializing....(May take 3 seconds)"));    fonaSS.begin(4800);    if (! fona.begin(fonaSS)) {        Serial.println(F("Couldn't find FONA"));        while (1);    }    Serial.println(F("FONA is OK"));    char sendto[21], message[141];    flushSerial();    Serial.print(F("Read #"));    uint8_t smsn = readnumber();    Serial.print(F("\n\rReading SMS #")); Serial.println(smsn);    // Retrieve SMS sender address/phone number.    if (! fona.getSMSSender(smsn, replybuffer, 250)) {        Serial.println("Failed!");        break;    }    Serial.print(F("FROM: ")); Serial.println(replybuffer);    // Retrieve SMS value.    uint16_t smslen;    if (! fona.readSMS(smsn, replybuffer, 250, &amp;smslen)) { // pass in buffer and max len!        Serial.println("Failed!");        break;    }    Serial.print(F("***** SMS #")); Serial.print(smsn);    Serial.print(" ("); Serial.print(smslen); Serial.println(F(") bytes *****"));    Serial.println(replybuffer);    Serial.println(F("*****")); } void loop() {} void flushSerial() {    while (Serial.available())    Serial.read(); } uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout) {    uint16_t buffidx = 0;    boolean timeoutvalid = true;    if (timeout == 0) timeoutvalid = false;    while (true) {        if (buffidx &gt; maxbuff) {        break;    }    while(Serial.available()) {        char c = Serial.read();        if (c == '\r') continue;        if (c == 0xA) {        if (buffidx == 0) // the first 0x0A is ignored        continue;        timeout = 0; // the second 0x0A is the end of the line        timeoutvalid = true;        break;    }    buff[buffidx] = c;    buffidx++;  }  if (timeoutvalid &amp;&amp; timeout == 0) {     break;  }  delay(1);  } buff[buffidx] = 0; // null term return buffidx; } char readBlocking() {    while (!Serial.available());    return Serial.read(); } uint16_t readnumber() {    uint16_t x = 0;    char c;    while (! isdigit(c = readBlocking())) {;}    Serial.print(c);    x = c - '0';    while (isdigit(c = readBlocking())) {        Serial.print(c);        x *= 10;        x += c - '0';    } return x; }
 

For making and receiving a call, attach the positive terminal of a speaker on the SPEAKER pin and the negative terminal to the GND pin. You can then use the same sketch used with the SIM800L.

Thanks for Teachmemicro.com. 
 


REVIEW