Translate

Monitoring Tegangan 3 fasa (3-phase Voltage monitoring) Sensor PZEM-004t TCP-IP WEBSERVER ARDUINO

Monitoring Tegangan 3 fasa (3-phase Voltage monitoring) Sensor PZEM-004t TCP-IP WEBSERVER ARDUINO

         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk monitoring tegangan 3 fasa dan juga bisa memonitor tegangan dc serta jarak, alat ini juga dilengkapi fitur kendali relay, alat ini menggunakan komunikasi ke server via TCP-IP sehingga membutuhkan IP address. untuk lebih jelasnya berikut koding dan daftar komponennya.


a. Arduino Mega 




b. Ethernet Shield




c. Sensor PZEM 004t




d. Sensor Tegangan DC




e. Sensor Jarak HC-SRF04




f. Modul Relay




g. Program Arduino IDE

#include <Wire.h>  // i2C Conection Library
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <Ethernet.h>
#include <PZEM004Tv30.h>
#include <SoftwareSerial.h>
#define trigPin 26
#define echoPin 28
LiquidCrystal_I2C lcd(0x27,16,2); 
PZEM004Tv30 pzem1(11, 12);
PZEM004Tv30 pzem2(A8, A9);
PZEM004Tv30 pzem3(A10, A11);
int voltage1, voltage2, voltage3;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,99);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
long duration, distance;
EthernetServer server(80);
String readString;
int relay1 = 22;
int relay2 = 24;
int mark = 0;
int markx = 2;
int incomingByte = 0; 

void setup() {
  lcd.begin();   
  lcd.noCursor();
  lcd.clear();
  Serial.begin(9600);  
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
  
   while (!Serial) {
  }
  Ethernet.begin(mac, ip);
  server.begin();
    delay(1000);
}

void loop() {
voltage1 = pzem1.voltage();
voltage2 = pzem2.voltage();
voltage3 = pzem3.voltage();
int adcteg = analogRead(A0);
float tegangan = adcteg * (5.0 / 1023.0) * 4.8;
  
digitalWrite(trigPin, LOW);  // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
distance = 23 - distance;
if(distance < 0){
  distance = 0;
}
lcd.setCursor(0, 0);
lcd.print(voltage1);
lcd.print("/");
lcd.print(voltage2);
lcd.print("/");
lcd.print(voltage3);
lcd.print("               ");
lcd.setCursor(0, 1);
lcd.print(tegangan);
lcd.print("/");
lcd.print(distance);
lcd.print("              ");
  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: 3");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println(" ");
          client.println("<title> Monitor </title> ");     
          client.println("<body bgcolor = #000000>");     
          client.println("<center>");
            client.println("<font color = yellow><center><h2>MONITORING TEGANGAN RST </h2></center><br></font>");
            client.println("<font color = #FFFFFF>");
            client.println("<h1>");
            client.println(" Tegangan R = ");
            client.print(voltage1);
            client.println("<br />");
            client.println(" Tegangan S = ");
            client.print(voltage2);
            client.println("<br />");
            client.println(" Tegangan T = ");
            client.print(voltage3);
            client.println("<br />");
            client.println(" VDC = ");
            client.print(tegangan);
            client.println("<br />"); 
            client.println(" Jarak = ");
            client.print(distance);
            client.println("<br />");          
            client.println("</h1>");      
            client.println("</font><br><br>");
           client.println("<a href = \"/?lighton1\"\"><input type = 'button' value = 'ON 1' ></a>");
           client.println("<a href = \"/?lightof2\"\"><input type = 'button' value = 'TOG 1' ></a> ");    
           client.println("<a href = \"/?lighton3\"\"><input type = 'button' value = 'ON 2' ></a>");
           client.println("<a href = \"/?lightof4\"\"><input type = 'button' value = 'TOG 2' ></a> "); 
           client.println("</center>");
//untuk kirim data ke client via TCPIP 
        server.print("Tegangan R = ");
        server.print(voltage1);
        server.print(" Tegangan S = ");
        server.print(voltage1);
        server.print(" Tegangan T = ");
        server.print(voltage1);
        server.print(" VDC = ");
        server.print(tegangan);
        server.print(" Jarak = ");
        server.println(distance);
        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)&&(mark == 1))
          {
             digitalWrite(relay1, LOW);
             delay(3000);
             digitalWrite(relay1, HIGH);                
             mark = 0;
          }
         
          if((readString.indexOf("?lightof2") >0)&&(mark == 0))
          {
             mark = 1;
          }
        
          if((readString.indexOf("?lighton3") >0)&&(markx == 3))
          {
             digitalWrite(relay2, LOW);
             delay(3000);
             digitalWrite(relay2, HIGH);                
             markx = 2;   
          }
         
          if((readString.indexOf("?lightof4") >0)&&(markx == 2))
          {
             markx = 3;
          }
 
readString="";
delay(1000);
}



h. VIDEO HASILNYA



      

No comments:

Post a Comment