Translate

Monitoring Input Relay LDR dan SMS Gateway + RTC

 Monitoring Input Relay LDR dan SMS Gateway + RTC


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang menggunakan relay sebagai input untuk mengaktifkan sms, jadi jika sensor ldr terkena suatu kondisi tertentu maka akan melakukan sms ke nomer yang dituju. untuk lebih jelasnya berikut adalah program dan komponenya. 
 
 
 
a. Minimum System ATMega328 / Arduino Uno




b. Modul SIM900A




c. Relay Input LDR





d. Program Arduino IDE

#include <SD.h>
#include <SPI.h>
#include <DS3231.h>
#include <Wire.h>
#include "SIM900.h"
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>
#include <stdlib.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <stdlib.h>
#define DS3231_I2C_ADDRESS 0x68
#include "sms.h"
SMSGSM sms;
File myFile;

DS3231  rtc(SDA, SCL);
int pinCS = 5; // Pin 10 on Arduino Uno

int pinin1 = 8;
int pinin2 = 9;
int pinin1x;
int pinin2x;
int tanda1 = 0;
int tanda2 = 0;
int cek = 0;
const int chipSelect = 10;
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];

void setup() {
   if (gsm.begin(2400)) {
          //Serial.println("\nstatus=READY");
          started = true;
     } else //Serial.println("\nstatus=IDLE");
     
     if(started) {
          //Enable this two lines if you want to send an SMS.
          if (sms.SendSMS("085123123123", "Alat Ready"));
     }
 
  lcd.begin(); //set lcd i2c
  lcd.noCursor(); //biar gak ada cursor di lcd
  lcd.clear(); //clear lcd
  lcd.setCursor(0, 0);
  lcd.print("LOADING...");
  Serial.begin(9600);
  pinMode(pinCS, OUTPUT);
   pinMode(pinin1,INPUT_PULLUP);
  pinMode(pinin2,INPUT_PULLUP);
 
  Serial.println("GSM Shield testing.");
     //Start configuration of shield with baudrate.
     //For http uses is raccomanded to use 4800 or slower.
     // SD Card Initialization
 
  if (SD.begin())
  {
    Serial.println("SD card is ready to use.");
  } else
  {
    Serial.println("SD card initialization failed");
    return;
  }
     lcd.clear();
  rtc.begin();    
}

void loop() {
rtc.begin();
    
pinin1x = digitalRead(pinin1);
pinin2x = digitalRead(pinin2);

lcd.setCursor(0, 0);
lcd.print(rtc.getTimeStr());
lcd.print("                           ");

lcd.setCursor(0, 1);
lcd.print(pinin1x);
lcd.print("/");
lcd.print(pinin2x);

if((pinin1x == 0)&&(tanda1 == 0)){
gsm.begin(2400);  
if (sms.SendSMS("085123123123", "switch status relay1 ON"));
tanda1 = 1;
//simpan();
}

if((pinin1x == 1)&&(tanda1 == 1)){
gsm.begin(2400);   
if (sms.SendSMS("085123123123", "switch status relay1 ON"));
tanda1 = 0;
//simpan();
}

if((pinin2x == 0)&&(tanda2 == 0)){
gsm.begin(2400);   
if (sms.SendSMS("085123123123", "switch status relay1 ON"));
tanda2 = 1;
//simpan();
}

if((pinin2x == 1)&&(tanda2 == 1)){
gsm.begin(2400);   
if (sms.SendSMS("085123123123", "switch status relay1 ON"));
tanda2 = 0;
//simpan();
}

delay(1000);

}

/*
 void simpan(){

  myFile = SD.open("coba.txt", FILE_WRITE);
  if (myFile) {    
    myFile.print(rtc.getTimeStr());
    myFile.println("                 ");    
    
    if(pinin1x == 1){
  myFile.println("RELAY1 ON");
  }

  if(pinin1x == 0){
  myFile.println("RELAY1 OFF");
  }

  if(pinin2x == 1){
  myFile.println("RELAY2 ON");
  }

  if(pinin2x == 0){
  myFile.println("RELAY2 OFF");
  }
    myFile.close(); // close the file
  }
  // if the file didn't open, print an error:
  else {
    Serial.println("error opening test.txt");
  }
   
  lcd.setCursor(0,0);
  lcd.print("saving.....");
  delay(1000);

}
*/


e. VIDEO HASILNYA
 


   

No comments:

Post a Comment