SMS Controller by Using SIM800L V2

Introduction: SMS Controller by Using SIM800L V2

About: Electronics Component - PCB [Design, Printing, Inserting] - Electronic Programming

SIMCOM SIM800L V2.0 GSM/GPRS Module is a QUAD BAND GSM/GPRS module which compatible with Arduino. The module works to add both of GSM features (voice call or SMS) and GPRS features. The advantages of these modules are the VCC and TTL serial levels that have 5V voltage, so you can directly connect it to Arduino or other minimum system with 5V of voltage level. There are so many GPRS/GSM modules on the market which need to add 5V regulator and level converter circuit, while SIM800L V.2 GSM/GPRS module already has a built-in regulator circuit and TTL level converter on the board.

Here is just an example project using SIM800L V.2. It’s about how to control relay using SMS controller. You can easily turn-on or turn-off many objects in your house, such as lamp, fan, and etc.

Specification of SIM800L V2.0 GSM/GPRS Module

SIM800L V2.0 GSM/GPRS Module have many specs, you can check it below:

  • TTL serial interface compatible with 3.3V and 5V Microcontrollers, compatible with arduino.
  • This SIM800L module has a set of TTL level serial interface, a set of power supply interface.
  • Besides, there are a set of antenna interface on this module.
  • Network support: Quad-Band 850 / 900/ 1800 / 1900 MHz, it can transmit Voice, SMS and data information with low power
  • VDD TTL UART interface The TTL UART serial interface, you can connect the MCU like 51MCU or ARM or MSP430 directly. The pin of VDD is used to match voltage of the TTL.
  • Model: SIMCOM SIM800L
  • Work voltage: 3.7V to 5V- Size: 40mm x 28mm x 3mm
  • GPRS multi-slot class 12/10
  • GPRS mobile station class B
  • Compliant to GSM phase 2/2+
  • Class 4 (2 W @ 850/900MHz)
  • Class 1 (1 W @ 1800/1900MHz)

Step 1: Materials You Need

You will need:

  1. SIM800L V2.0 GSM/GPRS Module
  2. Arduino Uno
  3. 4 Channel 5 Volt Relay Module
  4. Jumper Wire

Step 2: Setup

Once each component is connected, create a program, and then upload it on your arduino. But first, you must install GPRS library files that you can download in here.

Step 3: Code

Once you've plugged in your SIM800L, 4 Channel Relay Module, and ARduino to your computer, run the code below and you're finished.

#include

#include

#define TIMEOUT 5000

#define ACTIVE LOW

#define OFF HIGH

byte Relay[] = {A0,A1,A2,A3};

byte StatRelay[4];

char buffNumber[20];

char currentLine[500] = "";

int currentLineIndex = 0;

bool nextLineIsMessage = false;

String replyNumber = "089510863958";

GPRS gprs;

void setup() {

for(int i=0; i < 4; i++) {

pinMode (Relay[i] , OUTPUT);

digitalWrite (Relay[i], MATI);

StatRelay[i] = MATI;

}

Serial.begin(9600);

while (!Serial);

Serial.println("Activate SIM800L V2 >>> Automatically Read SMS");

gprs.preInit();

delay(1000);

while (0 != gprs.init()) {

delay(1000);

Serial.print("init errorrn");

}

// Manage message to mode ASCII

if (0 != gprs.sendCmdAndWaitForResp("AT+CMGF=1rn", "OK", TIMEOUT)) {

ERROR("ERROR:CNMI");

return;

}

// Read Incoming SMS

if (0 != gprs.sendCmdAndWaitForResp("AT+CNMI=1,2,0,0,0rn", "OK", TIMEOUT)) {

ERROR("ERROR:CNMI");

return;

}

int pjg = replyNumber.length() + 1;

buffNumber[pjg];

replyNumber.toCharArray(buffNumber,pjg);

Serial.print("Send reply to number = > ");

Serial.println(buffNumber);

Serial.println("Initialization Done");

Serial.println("=============================================================");

}

void loop() {

// Change status Relay ON / OFF

for(int i=0; i < 4; i++) {

digitalWrite(Relay[i], StatRelay[i]);

}

// If there is input data from SIM800

if (gprs.serialSIM800.available()) {

char lastCharRead = gprs.serialSIM800.read();

// Save all data on lastCharRead, then if there is r or n, as a final signal of incoming message

if (lastCharRead == 'r' || lastCharRead == 'n') {

String lastLine = String(currentLine);

// If the last message +CMT indicates new message arrive

if (lastLine.startsWith("+CMT:")) {

Serial.println(lastLine);

nextLineIsMessage = true;

} else if (lastLine.length() > 0) {

if (nextLineIsMessage) {

Serial.println(lastLine);

// ================================================================>> Function of Relay Controller

//Relay 1 Controller

if (lastLine.indexOf("Relay 1 ON") >= 0) {

StatRelay[0] = AKTIF;

Serial.print("Reply====>>>> ");

Serial.println("Relay 1 Status Active");

gprs.sendSMS (buffNumber, "Relay 1 Status Active");

}

else if (lastLine.indexOf("Relay 1 OFF") >= 0) {

StatRelay[0] = MATI;

Serial.print("Reply====>>>> ");

Serial.println("Relay 1 Status Off");

gprs.sendSMS (buffNumber, "Relay 1 Status Off");

}

//Relay 2 Controller

if (lastLine.indexOf("Relay 2 ON") >= 0) {

StatRelay[1] = AKTIF;

Serial.print("Reply====>>>> ");

Serial.println("Relay 2 Status Active");

gprs.sendSMS (buffNumber, "Relay 2 Status Active");

}

else if (lastLine.indexOf("Relay 2 OFF") >= 0) {

StatRelay[1] = MATI;

Serial.print("Reply====>>>> ");

Serial.println("Relay 2 Status Off");

gprs.sendSMS (buffNumber, "Relay 2 Status Off");

}

//Relay 3 Controller

if (lastLine.indexOf("Relay 3 ON") >= 0) {

StatRelay[2] = AKTIF;

Serial.print("Reply====>>>> ");

Serial.println("Relay 3 Status Active");

gprs.sendSMS (buffNumber, "Relay 3 Status Active");

}

else if (lastLine.indexOf("Relay 3 OFF") >= 0) {

StatRelay[2] = MATI;

Serial.print("Reply====>>>> ");

Serial.println("Relay 3 Status Off");

gprs.sendSMS (buffNumber, "Relay 3 Status Off");

}

//Relay 4 Controller

if (lastLine.indexOf("Relay 4 ON") >= 0) {

StatRelay[3] = AKTIF;

Serial.print("Reply====>>>> ");

Serial.println("Relay 4 Status Active");

gprs.sendSMS (buffNumber, "Relay 1 Status Active");

}

else if (lastLine.indexOf("Relay 4 OFF") >= 0) {

StatRelay[3] = MATI;

Serial.print("Reply====>>>> ");

Serial.println("Relay 4 Status Off");

gprs.sendSMS (buffNumber, "Relay 4 Status Off");

}

nextLineIsMessage = false;

}

// ==================================================================>>

}

//Clear char array for next line of read

for ( int i = 0; i < sizeof(currentLine); ++i ) {

currentLine[i] = (char)0;

}

currentLineIndex = 0;

}

else {

currentLine[currentLineIndex++] = lastCharRead;

}

}

}

Step 4: Try It!

This tool works by sending SMS on SIM800L with certain keywords. Here, to turn on relay 1 use the command "Relay 1 ON" and to turn it off by using "Relay 1 OFF" command. For other relay commands almost the same, simply by replacing the numbers according to the serial number of the controlled relay. After the message is sent automatically, SIM800 will send a reply in the form of status message of each SIM.

Step 5: Check the Video to Know More

Be the First to Share

    Recommendations

    • Microcontroller Contest

      Microcontroller Contest
    • Automation Contest

      Automation Contest
    • Make it Glow Contest

      Make it Glow Contest

    26 Comments

    0
    mahdikarimimk58
    mahdikarimimk58

    4 months ago

    I wanted to know if this project only works on the sim800l v2 module.
    Or can the project be done on a normal sim800l module ???????

    0
    mahdikarimimk58
    mahdikarimimk58

    4 months ago

    Hi, I wanted to know if my sim800l module is connected to the network, but I want to send a message (the relay does not turn on), if you can help me !!!!!!!! ?????

    1
    resende321
    resende321

    3 years ago

    What does "MATI" means in the code ?

    0
    sfeelectronics
    sfeelectronics

    Reply 3 years ago

    Hi, sorry for the late reply, "MATI" means "OFF" :)

    0
    Babru Bahan Das
    Babru Bahan Das

    Reply 4 months ago

    "AKTIF" means "ACTIVE"

    0
    markee010781
    markee010781

    1 year ago

    #include ??
    What to include?

    0
    Babru Bahan Das
    Babru Bahan Das

    Reply 4 months ago

    #include <gprs.h> and #include <SoftwareSerial.h>, " MATI" means "OFF" and "AKTIF" means "ACTIVE"

    3
    zamany
    zamany

    Question 11 months ago

    Hi there is a problem with the project code

    0
    valdehuezaphilip
    valdehuezaphilip

    Question 1 year ago

    Sir can I replace "MATI" with "OFF"?
    and what to put in the #include sir.. i really need your help sir

    0
    janvierArt
    janvierArt

    Question 1 year ago

    how can add another numbers

    0
    marcowageeh0000
    marcowageeh0000

    1 year ago

    I need help please sim800l start working but power led off after 10 second and no communication to net

    0
    silvercarph
    silvercarph

    Question 1 year ago

    I am afraid this sketch is ONLY for the Seeeduino GPRS modul. I inserted #include <gprs.h> and #include <SoftwareSerial.h> and the sketch compiled. Wired my SIM800L to the Nano, uploaded sketch - and the error message came on Serial: "Power check failed".
    Where can I connect pin 9 // power key and pin 12 // power status pin?
    No surprise no one could build this project.
    I regret the time I spent on building this.

    0
    kojotpera
    kojotpera

    1 year ago

    CODE does not working... What is going on???

    0
    ismail hossen
    ismail hossen

    Question 2 years ago on Step 3

    sir
    i want code for 8 channel relay control by sms and i have 900 sim module also i have sim 800L
    please you can send me the code

    0
    Glenn Wangjaya
    Glenn Wangjaya

    2 years ago

    ERROR CNMI? Please help me. the problem is where ?

    0
    ahmeda860
    ahmeda860

    2 years ago

    I have error CNMI

    0
    SriW7
    SriW7

    2 years ago

    Is this code works with Arduino mega 2560

    1
    ReshadR1
    ReshadR1

    2 years ago

    Hello, Thanks for your tutorial. I think it's very helpful to others.

    But when I try verify this code it shows error. Error message is given bellow. Would you please help me?

    --------------------------------------------------------------------------------------------------------
    SIM800L_Relay_Controller:1: error: #include expects "FILENAME" or <FILENAME>

    #include

    ^

    SIM800L_Relay_Controller:3: error: #include expects "FILENAME" or <FILENAME>

    #include

    ^

    exit status 1
    #include expects "FILENAME" or <FILENAME>

    -----------------------------------------------------------------------------------------------------------

    1
    OriolB6
    OriolB6

    3 years ago

    not working ..,,