Cara kontrol Relay 4 Channel dengan SMS menggunakan SIM800L GSM Module dan arduino

Author : Ila MulyandiNo comments

Control Relay 4 Channel Menggunakan SMS
Yang dimaksud disini adalah mengontrol 4 buah beban (misal lampu atau motor ata Home electric device) melalui Relay dan dikendalikan melalui SMS yang sudah ter-Otentikasi Nomor Pengirimnya,
artinya Relay hanya mau mengikuti instruksi dari SMS dengan Nomor yang sudah terdaftar di sistem dan mengabaikan Instruksi SMS dari Nomor yang tidak terdaftar pada sistem program.





Module yang dibutuhkan :
1pc Arduino UNO Rev.3
1pc Relay Module 4 Channel Low Active
1pc SIM800L GSM Module
1pc DC StepDown Buck Converter
+Beberapa pcs kabel dupon/jumper untuk wiring


Wiring SIM800L <--> Arduino Uno
RXD <--> D8
TXD <--> D7
VCC <--> 3.7V melalui stepdown dari 5V Arduino
GND <--> GND

Wiring Relay 4 Channel <--> Arduino Uno
GND <--> GND
CH1 <--> D2
CH2 <--> D3
CH3 <--> D4
CH4 <--> D5   
VCC <--> 5V

Wiring DC StepDown Buck Converter 
(-) IN <--> GND Arduino 
(+) IN <--> 5V Arduino  
(-) OUT <--> GND SIM800L
(+) OUT <--> VCC SIM800L

Atur VR/Trimpot pada Stepdown sampai mendapatkan tegangan 3,7VDC dan Ukur dengan Voltmeter
Sebelum disambungkan dengan Vcc pada Module SIM800L
Warning: Jangan Memberi tegangan di atas 4,2VDC pada Vcc Module SIM800L karena dapat menyebabkan kerusakan pada Module

Library GSM Seeeduino silahkan download disini

Berikut Sketch Coding yang Harus dimasukan pada Arduino Uno :



  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <gprs.h>
#include <softwareserial.h>
 
#define TIMEOUT    5000
#define LED_PIN    13
#define ON LOW
#define OFF HIGH

const int Relay1 = 2;
const int Relay2 = 3;
const int Relay3 = 4;
const int Relay4 = 5;
 
int StatRelay1;
int StatRelay2;
int StatRelay3;
int StatRelay4;

GPRS gprs;
 
void setup() {
  pinMode (Relay1 , OUTPUT); digitalWrite (Relay1, HIGH);
  pinMode (Relay2 , OUTPUT); digitalWrite (Relay2, HIGH);
  pinMode (Relay3 , OUTPUT); digitalWrite (Relay3, HIGH);
  pinMode (Relay4 , OUTPUT); digitalWrite (Relay4, HIGH);
  Serial.begin(9600);
  while(!Serial);
 
  Serial.println("Starting SIM800 Auto Read SMS");
  gprs.preInit();
  delay(1000);
 
  while(0 != gprs.init()) {
      delay(1000);
      Serial.print("init error\r\n");
  } 
 
  //Set SMS mode to ASCII
  if(0 != gprs.sendCmdAndWaitForResp("AT+CMGF=1\r\n", "OK", TIMEOUT)) {
    ERROR("ERROR:CNMI");
    return;
  }
   
  //Start listening to New SMS Message Indications
  if(0 != gprs.sendCmdAndWaitForResp("AT+CNMI=1,2,0,0,0\r\n", "OK", TIMEOUT)) {
    ERROR("ERROR:CNMI");
    return;
  }
 
  Serial.println("Init success");
}
 
//Variable to hold last line of serial output from SIM800
char currentLine[500] = "";
int currentLineIndex = 0;
 
//Boolean to be set to true if message notificaion was found and next
//line of serial output is the actual SMS message content
bool nextLineIsMessage = false;
 
void loop() {
  //Write current status to LED pin
  digitalWrite(Relay1, StatRelay1);
  digitalWrite(Relay2, StatRelay2);
  digitalWrite(Relay3, StatRelay3);
  digitalWrite(Relay4, StatRelay4);
   
  //If there is serial output from SIM800
  if(gprs.serialSIM800.available()){
    char lastCharRead = gprs.serialSIM800.read();
    //Read each character from serial output until \r or \n is reached (which denotes end of line)
    if(lastCharRead == '\r' || lastCharRead == '\n'){
        String lastLine = String(currentLine);
         
        //If last line read +CMT, New SMS Message Indications was received.
        //Hence, next line is the message content.
        if(lastLine.startsWith("+CMT:")){
           
          Serial.println(lastLine);
          nextLineIsMessage = true;
           
        } else if (lastLine.length() > 0) {
           
          if(nextLineIsMessage) {
            Serial.println(lastLine);
             

// ########## MEMBACA KONTEN SMS DAN MENCARI+MENGARTIKAN KONTEN SMS KE PROGRAM #########
            //Kendali Relay
              if(lastLine.indexOf("Relay1 ON") >= 0){
              StatRelay1 = ON;
              Serial.println("Relay1 DINYALAKAN");
              gprs.sendSMS ("08xxxxxxxxxx","Relay1 DINYALAKAN");} 
              else if(lastLine.indexOf("Relay1 OFF") >= 0) {
              StatRelay1 = OFF;
              Serial.println("Relay1 DIMATIKAN");
              gprs.sendSMS ("08xxxxxxxxxx","Relay1 DIMATIKAN");}
              
              if(lastLine.indexOf("Relay2 ON") >= 0){
              StatRelay2 = ON;
              Serial.println("Relay2 DINYALAKAN");
              gprs.sendSMS ("08xxxxxxxxxx","Relay2 DINYALAKAN");} 
              else if(lastLine.indexOf("Relay2 OFF") >= 0) {
              StatRelay2 = OFF;
              Serial.println("Relay2 DIMATIKAN");
              gprs.sendSMS ("08xxxxxxxxxx","Relay2 DIMATIKAN");}

              if(lastLine.indexOf("Relay3 ON") >= 0){
              StatRelay3 = ON;
              Serial.println("Relay3 DINYALAKAN");
              gprs.sendSMS ("08xxxxxxxxxx","Relay3 DINYALAKAN");} 
              else if(lastLine.indexOf("Relay3 OFF") >= 0) {
              StatRelay3 = OFF;
              Serial.println("Relay3 DIMATIKAN");
              gprs.sendSMS ("08xxxxxxxxxx","Relay3 DIMATIKAN");}

              if(lastLine.indexOf("Relay4 ON") >= 0){
              StatRelay4 = ON;
              Serial.println("Relay4 DINYALAKAN");
              gprs.sendSMS ("08xxxxxxxxxx","Relay4 DINYALAKAN");} 
              else if(lastLine.indexOf("Relay4 OFF") >= 0) {
              StatRelay4 = OFF;
              Serial.println("Relay4 DIMATIKAN");
              gprs.sendSMS ("08xxxxxxxxxx","Relay4 DIMATIKAN");}
            
             
            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;
    }
  }
}

Posted On : Sunday, January 22, 2017Time : 11:16 PM
SHARE TO :
| | Template Created By : Rajendroid | CopyRigt By : ARDUINO | |