GSM Module Sim900A and Arduino to Control Relay Module Through SMS

by samiobi in Circuits > Arduino

6442 Views, 3 Favorites, 0 Comments

GSM Module Sim900A and Arduino to Control Relay Module Through SMS

صورة4.png

Home control devices are common these days due to fast life style, moreover it depends on the user's interest which system suits his needs, some prefer to use GSM command control and other uses Wi-Fi internet devices, at the end each one of us has a specific demand for a system. GSM control systems are used for long range communication with devices, additionally GSM network reaches most of the public places this type of connectivity is preferred in many cases.

However in this topic the system will integrate GSM module sim900a with Arduino Uno in order to control a relay module using SMS messages. This system can be used to control any electrical or electronic equipment in a house, farm or any business place. The relay module has a capability to withstand certain current limit depends on the type (note to select a proper one to your application).

Supplies

  1. Power supply (12V DC adapter)
  2. Arduino Uno
  3. GSM Module SIM900A
  4. Relay module
  5. Small Bread board
  6. Links

System Block Diagram

diagram.jpg
table of connections.jpg

The system block diagram shown in the figure shows the interconnection between all units, furthermore the power source is the 12V adapter which supplies the power to the Arduino and then it provides the 5 volt to the rest of the circuit, because SIM900 requires sufficient power to connect to the network the power rating of the adapter shall be in the spec ( 1.5 A or higher ) I used 12V @ 3 Amp adapter and worked well.

The connection between the Arduino and GSM is a soft serial pins 9 and 8 as shown in the table above, mean while the relay IN is connected to pin 6. Remember that all GRD shall be shared for all units. The TX/RX in the sim900 are positioned under 5T/5R in the middle pins.

Concept of Operation

The system controls the relay through SMS messages, each SMS contains a desired request by the user, which can be ON/OFF/STATE. After the system is powered the GSM will try to establish a connection with the network (normally it takes less than one minute). Next the system is ready when the GSM blinks once every two seconds, now the system is ready. The relay changes the state once the GSM is connected to the network, After that send SMS ON to the system the relay will change the state to ON and contact the circuit, then send SMS OFF to switch off the relay. Moreover to know the state of the system send the command STATE the system will repay with ON or OFF. The system can be configured as normally open or normally closed, also the SMS can be configured to add more characters to avoid mistake reception of other SMS.

SMS commands

ON to contact the relay with HIGH

OFF to disconnect the relay with LOW

STATE to check if the system is ON or OFF

Step One Power Connection

صورة1.png
صورة3.png

Initially link the 5V and GND output from Arduino and place both connections on the breadboard lines, after that connect VIN and GND to the reset of the components by connecting them to the breadboard voltage and ground lines.

Step Two Connections and SIM Card

صورة2.png
صورة5.png

The second step it to connect the reset of the links to the circuit, by connecting TX and RX from the sim900a to the Arduino and connect IN from the relay module to the Arduino. Follow the figure as the links are specified in the table in the system block diagram section. After that insert the SIM card in the GSM sim900, make sure the card is properly fit in the slot and it does not have PIN number, also it shall have enough balance to send SMS.

Coding

صورة17.png

The coding process starts by connecting the Arduino Uno to the computer at this point do not connect the SIM900 power, then download the software serial library through scrolling to sketch include library then manage libraries after that type in Software Serial and download the latest version. Finally copy the code below and make the changes on the message and contact number note to include international code.

The code is simple as its shown below, copy and past in the IDE


#include<softwareSerail.h> //software serial library for serial communication between Arduino & sim900 GSM

SoftwareSerial mySerial(8, 9);//connect Tx pin of GSM to pin 8 of Arduino && Rx pin of GSM to pin no 9

int REY = 6; // relay output

String message;

String lampState = "HIGH";// Create a variable to store Lamp state

void setup() {

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

delay(20000);

mySerial.println("AT+CMGF=1"); // set text mode

delay(1000);

mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS

pinMode(REY, OUTPUT);

digitalWrite(REY, LOW);

delay(100);

}

void loop() {

if (mySerial.available() > 0) {

message = mySerial.readString(); }

if (message.indexOf("ON") > -1) {

digitalWrite(REY, HIGH);

lampState = "on"; }

if (message.indexOf("OFF") > -1) {

digitalWrite(REY, LOW);

lampState = "off"; }

if (message.indexOf("STATE") > -1) {

mySerial.println("AT+CMGS=\"+9XXXXXXXXX\"\r"); // replace XXX.. with your number with country code delay(1000);

mySerial.println("Relay is "+ lampState);// Message content

delay(1000);

mySerial.println((char)26);// ASCII code of CTRL+Z

delay(100); }

}

Final Testing

صورة6.png
صورة7.png
صورة8.png
صورة9.png

At this stage the system is ready to be tested, first reconnect the power back to the sim900, then use the adapter to power the Arduino. Then power on the system and wait until the GSM pairs with the network. First send SMS ON to the system and notice the change in behavior on the relay module, then send SMS OFF to the system and check out the change in the relay module. In order to check the state of the system send SMS STATE and the system will relay by relay on or off.

This system is easy to be configured and it is very useful to control remotely any electric or electronic device. I hope you enjoy this topic and if you have any issue please do not hesitate to send.

All the best