top of page

GSM : Part 2 (Controlling GSM using Arduino's Serial Monitor)

In this video, I will be showing how to control a SIM900 Mini GSM Module by using Arduino's Serial Monitor alongside with some tips on how we can improvise GSM's responses to our need.

By using the below code, you can avoid the purchase of UART modules to communicate directly to your GSM. In this scenario, Arduino acts like the terminal to communicate with GSM.

Simply upload the below code into your Arduino. The setup has already been shown in Part 1 of GSM.



 

#include <SoftwareSerial.h>

SoftwareSerial SIM900A(7,8);

String msg;

void setup() {

// put your setup code here, to run once:

SIM900A.begin(9600); // Setting the baud rate of GSM Module

Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)

Serial.println ("SIM900A Ready");

delay(100);

}

void loop() {

// put your main code here, to run repeatedly:

while (Serial.available()==0){

}

msg=Serial.readString();

SIM900A.println(msg);

delay(1000);

while (SIM900A.available()==0){

}

msg=SIM900A.readString();

//msg.replace("\n", "");

Serial.println(msg);

delay(1000);

msg = "";

}

 

Once uploaded, just type in your preferred AT command in Arduino's Serial Monitor. Examples are shown as below :



The next code shows we can use of the GSM response to produce more meaningful and comprehensible outputs.

 

#include <SoftwareSerial.h>

SoftwareSerial SIM900A(7, 8);

String msg;

String gsmmsg;

void setup() {

// put your setup code here, to run once:

SIM900A.begin(9600); // Setting the baud rate of GSM Module

Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)

Serial.println ("SIM900A Ready");

delay(100);

}

void loop() {

while (Serial.available() != 0) {

msg = Serial.readString();

SIM900A.println(msg);

}

while (SIM900A.available() != 0) {

gsmmsg = SIM900A.readString();

gsmmsg.replace("\n", "");

if (gsmmsg.indexOf('OK') >= 1) {

Serial.println("AT Command is OK");

gsmmsg = "";

}

}

}
 

Sample output by using the above is shown below :


To understand better on the above instruction, feel free to check out my step by step video :




Comments


bottom of page