Translate

Alat Kendali Relay dan Monitor Arus via WIFI ARDUINO Ethernet Aplikasi Android

Alat Kendali Relay dan Monitor Arus via WIFI ARDUINO Ethernet Aplikasi Android


            Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang berfungsi untuk monitor arus dan kendali relay via WIFI. alat ini menggunakan aplikasi android sebagai device kendalinya atau interfacenya. alat ini menggunakan router sebagai pemancar wifi sehingga jarak kendali dan monitor hanya sebatas jarak router saja. untuk lebih jelasnya berikut adalah program dan daftar komponennya.



a. Arduino Mega + Ethernet Shield




b. Sensor Arus ACS712




c. Relay Module 2 Channel




d. Router 




e. Program Android









f. Program Arduino IDE

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,99);

unsigned long start_times[300];
unsigned long stop_times[300];
unsigned long values[300];

const unsigned char PS_16 = (1 << ADPS2);
const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0);
const unsigned char PS_64 = (1 << ADPS2) | (1 << ADPS1);
const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);

EthernetServer server(80);

const int ledpin1 = A8;
const int ledpin2 = A9;

String readString;
float arus1x;
float arus1;
float arus2x;
float arus2;

void setup() {

 // set up the ADC
  ADCSRA &= ~PS_128;  // remove bits set by Arduino library

  // you can choose a prescaler from above.
  // PS_16, PS_32, PS_64 or PS_128
  ADCSRA |= PS_128;    // set our own prescaler to 64
  
   pinMode(ledpin1, OUTPUT);
   pinMode(ledpin2, OUTPUT);
   digitalWrite(ledpin1, HIGH); 
   digitalWrite(ledpin2, HIGH); 
  
  Serial.begin(9600);
   while (!Serial) {
  }

  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}

void loop() {

unsigned int i;
unsigned int z;
z = 0;
   
  // capture the values to memory
  for(i=0;i<300;i++) {
    start_times[i] = micros();
    values[i] = analogRead(A0);             
 
  if (values[i] >= z) {
  z = values[i]; 
  }
    stop_times[i] = micros();
  }

  arus1x = z * (5.0/1023.0);
  arus1x = (arus1x - 2.438)/ 0.251;
  arus1 = arus1x * 1;
 
  z = 0;
  i = 0;
//=================================================

 // capture the values to memory
  for(i=0;i<300;i++) {
    start_times[i] = micros();
    values[i] = analogRead(A1);             
 
  if (values[i] >= z) {
  z = values[i]; 
  } 
    stop_times[i] = micros();
  }

  arus2x = z * (5.0/1023.0);
  arus2x = (arus2x - 2.438)/ 0.251;
  arus2 = arus2x * 1;
 
  z = 0;
  i = 0;


  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 Lampu </title> ");     
          client.println("<body bgcolor = #000000>");     
          client.println("<center>");
            client.println("<font color = yellow><center><h1>KENDALI LAMPU VIA ETHERNET ANDROID<br></h1></center><br>");
            client.println("<br />");
            client.println("<h2>");
            client.println("##");
            client.print(arus1);
            client.println("  <br />");
            client.println("###");
            client.print(arus2);
            client.println("  <br />");
            client.println("</font></h2>");
            
           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("</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, LOW);    
          }
          else{           
          if(readString.indexOf("?lightoff1") >0)
          {

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

                digitalWrite(ledpin2, HIGH); 
          }
          }
          
         readString="";
}





g. VIDEO HASILNYA









No comments:

Post a Comment