Translate

Membuat Alat Kendali Peralatan Listrik Berdasarkan Setting Jam Hand Phone Android dan ARDUINO WIFI Ethernet

Membuat Alat Kendali Peralatan Listrik Berdasarkan Setting Jam Hand Phone Android dan ARDUINO WIFI Ethernet


         Pada kesempatan yang berbahagia kali ini saya akan menjelaskan sebuah terobosan inovasi terbaru dari alat kami, yaitu alat kendali peralatan listrik menggunakan setting alarm HP Android, jadi prinsip kerjanya adalah lampu atau kipas angin dll. akan hidup dan mati sesuai dengan jam yang diset melalui HP Android, misal di HP android kita set lampu jam 6 AM mati dan jam 5 PM menyala, maka saat waktu yang tepat lampu akan menyala secara otomatis, setting waktu menggunakan router dan wireless WIFI. untuk lebih jelasnya berikut program dan skemanya.




a. Arduino Uno + Ethernet Shield





b. Wifi Router 





c. Relay Modul





d. Program Android









e. Program Arduino IDE

#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal.h>
#include <Wire.h>
#define DS3231_I2C_ADDRESS 0x68

// Convert normal decimal numbers to binary coded decimal
LiquidCrystal lcd(A0, A1, A2, A3, 3, 2);

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 0, 88 }; // ip in lan
byte gateway[] = { 192, 168, 0, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80);; //server port

String readString;


const int ledpin1 = 5;
const int ledpin2 = 7;
const int ledpin3 = 4;

int ton = 0;
int toff = 0;

#define DS3231_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}
void setup()
{

  Wire.begin();
  lcd.begin(16, 2);
  lcd.clear();
  lcd.noCursor();
 
   pinMode(ledpin1, OUTPUT);
   pinMode(ledpin2, OUTPUT);
   pinMode(ledpin3, OUTPUT);
     
  Wire.begin();
  Serial.begin(9600);
 
  while (!Serial) {
  }

  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
 
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
   //setDS3231time(0,59,21,6,27,5,16);
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}




void displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  // convert the byte variable to a decimal number when displayed
  Serial.print(":");
  if (minute<10)
  {
    Serial.print("0");
  }
  Serial.print(minute, DEC);
  Serial.print(":");
  if (second<10)
  {
    Serial.print("0");
  }
  Serial.print(second, DEC);
  Serial.print(" ");
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(month, DEC);
  Serial.print("/");
  Serial.print(year, DEC);
  Serial.print(" Day of week: ");
  switch(dayOfWeek){
  case 1:
    Serial.println("Sunday");
    break;
  case 2:
    Serial.println("Monday");
    break;
  case 3:
    Serial.println("Tuesday");
    break;
  case 4:
    Serial.println("Wednesday");
    break;
  case 5:
    Serial.println("Thursday");
    break;
  case 6:
    Serial.println("Friday");
    break;
  case 7:
    Serial.println("Saturday");
    break;
  }
 
 
  if ((hour >= ton) && (toff > 0 )) {
 
 
    if (hour >= toff){
      digitalWrite(ledpin1, LOW);
    }
    else
    {
      digitalWrite(ledpin1, HIGH);
     
    }
   
   
  }

  
 
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
     if (readString.length() < 100) {

          //store characters to string
          readString += c;
          //Serial.print(c);
        }
        if (c == '\n' && currentLineIsBlank) {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println("Refresh: 1");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println(" ");
          client.println("<title> Monitor Kemiringan </title> ");    
          client.println("<body bgcolor = #FFFFFF>");    
          client.println("<center>");
          client.println("<font color = black><center><h1>KENDALI LAMPU VIA ETHERNET ANDROID</h1><br></center><br>");
          client.println("<h1>");
           client.println("Jam = ");
          client.println(hour);
          client.println(" : ");
          client.println(minute);
          client.println(" : ");
          client.println(second);
          client.println("<br>");
          client.println("Tanggal = ");
          client.println(dayOfMonth);
          client.println(" - ");
          client.println(month);
          client.println(" - ");
          client.println(year);
          client.println("</h1>");
          
         //  client.println("<a href = \"/?lighton1\"\"><input type = 'button' value = 'ON 1' ></a>");
         // client.println("<a href = \"/?lightoff1\"\"><input type = 'button' value = 'OFF 1' ></a> ");
         //  client.println("<a href = \"/?lighton2\"\"><input type = 'button' value = 'ON 2' ></a>");
         // client.println("<a href = \"/?lightoff2\"\"><input type = 'button' value = 'OFF 2' ></a> ");
         //  client.println("<a href = \"/?lighton3\"\"><input type = 'button' value = 'ON 3' ></a>");
         // client.println("<a href = \"/?lightoff3\"\"><input type = 'button' value = 'OFF 3' ></a> ");
         //  client.println("<a href = \"/?lighton4\"\"><input type = 'button' value = 'ON 4' ></a>");
         // client.println("<a href = \"/?lightoff4\"\"><input type = 'button' value = 'OFF 4' ></a> ");
        
          client.println("</center>");
          client.println("</body>");
          client.println("</html>");
           
          break;      
        }   
        if (c == '\n') {
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }
    delay(1);
    client.stop();
    Serial.println("client disonnected");
  }
 
  if(readString.indexOf("?lighton1") >0)
          {

            digitalWrite(ledpin1, HIGH);   
          }
          else{          
          if(readString.indexOf("?lightoff1") >0)
          {

             digitalWrite(ledpin1, LOW);
          }
          }
        
             if(readString.indexOf("?lighton2") >0)
          {

            digitalWrite(ledpin2, HIGH);   
          }
          else{          
          if(readString.indexOf("?lightoff2") >0)
          {

                digitalWrite(ledpin2, LOW);
          }
          }
          if(readString.indexOf("?lighton3") >0)
          {

            digitalWrite(ledpin3, HIGH);   
          }
          else{          
          if(readString.indexOf("?lightoff3") >0)
          {

                digitalWrite(ledpin3, LOW);
          }
          }
         
         
          if(readString.indexOf("?lightonA17") >0)
          {

            ton = 17;
           
          }
          else{          
          if(readString.indexOf("?lightoffB22") >0)
          {

            toff = 22;
               
          }
          }
         
         
           if(readString.indexOf("?lightonA15") >0)
          {

            ton = 15;
           
          }
          else{          
          if(readString.indexOf("?lightoffB20") >0)
          {

            toff = 20;
               
          }
          }
        
        
         readString="";
    
 
}


void loop()
{
  displayTime();
                 
}






f. Cara Menggunakan Alat

      Untuk menggunakan alat ini langkah pertama yaitu setting dahulu jam ON dengan cara memasukkan HH-MM-SS-AM/PM, kemudian yang bagian off juga. pada layar terdapat 6 buah tombol yang fungsinya untuk ON/OFF device secara manual artinya tidak otomatis, kalau setting menggunakan jam maka dia akan otomatis ON dan OFF sesuai jam yang di setting.  masukkan IP ARDUINO address = 192.168.0.88 dan Port = 80. jika berhasil maka saat waktu yang tepat device lampu atau kipas akan menyala otomatis sesuai waktu pada HP Android secara Real Time.





g. VIDEO HASILNYA












No comments:

Post a Comment