Translate

Membuat Alat Monitor Daya (Arus dan Tegangan) sensor ACS712 dan ZMPT101B LOCALHOST PHPMYADMIN MYSQL ARDUINO Ethernet Shield

Membuat Alat Monitor Daya (Arus dan Tegangan) sensor ACS712 dan ZMPT101B LOCALHOST PHPMYADMIN MYSQL ARDUINO Ethernet Shield


              Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor daya yaitu arus dan tegangan AC kemudian data tersebut bisa disimpan dan dilihat melalui localhost komputer, sehingga arduino harus bisa mengirimkan data dari sensor menuju ke localhost komputer / laptop. alat ini menggunakan sensor arus ACS712 dan sensor tegangan AC satu fasa ZMPT101B kemudian terdapat LCD sebagai penampil nilainya. untuk pengiriman data ke localhost komputer menggunakan ethernet shield. data yang ditampilkan oleh web browser adalah data realtime. untuk lebih jelasnya berikut adalah program dan skemanya.



a. Arduino Mega + Ethernet Shield




b. Sensor Arus AC ACS712




c. Sensor Tegangan AC ZMPT101B





d. LCD 16x2 + I2C






e. Program Arduino IDE

#include <Wire.h>
#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal_I2C.h>  //i2C LCD Library

LiquidCrystal_I2C lcd(0x27, 16, 2);

// Arrays to save our results in
unsigned long start_times[300];
unsigned long stop_times[300];
unsigned long values[300];


// Define various ADC prescaler
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);

String txData="";

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

EthernetClient client;

int tegangan;
int arus;

void setup() {

lcd.begin();
lcd.clear();
lcd.noCursor();

  // 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
 
  Serial.begin(9600);
  while (!Serial) {
    ; //wait for serial port to connect. Needed for Leonardo only
  }
//  if (Ethernet.begin(mac) == 0) {
//    Serial.println("Failed to configure Ethernet using DHCP");
    Ethernet.begin(mac, ip);
//  }
    delay(1000);
    Serial.println("connecting...");
 

}

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();
  }

   int vin = z ;

  z = 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();
  }
    float v1x = z * (5.0/1023.0);
    float arusx = (v1x-2.5)/0.251 ;

int arus = arusx * 100;

if (arusx < 0.5) {
arusx = 0;
arus = 0;
}

 z = 0;

float teganganx = (vin - 559.9) / 0.413 ;
int tegangan = teganganx * 100;

if (teganganx < 0) {
teganganx = 0;
tegangan = 0;
}

float dayax = teganganx * arusx;
int daya = dayax;

  lcd.setCursor(0, 0);
  lcd.print("V=");
  lcd.print(teganganx,1);
 
  lcd.print(" I=");
  lcd.print(arusx);
  lcd.print("     ");
 
  lcd.setCursor(0, 1);
  lcd.print("P=");
  lcd.print(daya);
  lcd.print("     ");

 
  EthernetClient client;

   if (client.connect("192.168.1.111", 80)){
    txData = "tegangan="+ (String (tegangan)) + "&arus="+ (String (arus)) + "&daya="+ (String (daya));
    Serial.println("connected");
    Serial.print(txData);
    client.println("POST /monitoring_daya/update.php HTTP/1.1");
    //jika menggunakan insert pakai client.println("POST /antri/insert.php HTTP/1.1");
    client.println("Host: 192,168,1,111");
    client.println("Connection: close");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(txData.length());
    client.print("\n\n");
    client.print(txData);
    Serial.println(txData);
    delay (2000);
  
  }  
  else{
    Serial.println("Connection Failed.");
    Serial.println();
    delay (1500);
  }
}




f. config.php

<?php

$dbhost = 'localhost';
$dbuser = 'root';
//$dbpass = '';   
$dbname = 'dbmonitordaya'; //This is the name of your database on the mysql server

$conn = mysql_connect($dbhost,$dbuser) or die ('Error connecting to mysql');
mysql_select_db($dbname);
if(!$conn){
     //   echo "database gak konek";
    }else{
     //   echo "database konek";
    }
?>




g. index.php

<html>
<head>
<meta http-equiv="refresh" content="3">
<style>
.bordered { border-style:solid; }
</style>
<link rel="stylesheet" type="text/css" href="latweb.css" />
<title >MONITORING</title>
</head>
<body>

<CENTER>
<p><h2> MONITORING DAYA<h2></p>

</CENTER>

<CENTER>
<p><h3>

Tegangan =
<?php

include "config.php";
$tampil = @mysql_query("SELECT * FROM tbdaya WHERE no IN (SELECT MAX(no) FROM tbdaya)");
        
    while ($r=mysql_fetch_array($tampil)){
       echo $r['tegangan']/100;
   }
?>

volt

<br>

Arus =
<?php
include "config.php";
$tampil = @mysql_query("SELECT * FROM tbdaya WHERE no IN (SELECT MAX(no) FROM tbdaya)");
        
    while ($r=mysql_fetch_array($tampil)){
       echo $r['arus']/100;
   }
?>

ampere

<br>

Daya =
<?php
include "config.php";
$tampil = @mysql_query("SELECT * FROM tbdaya WHERE no IN (SELECT MAX(no) FROM tbdaya)");
        
    while ($r=mysql_fetch_array($tampil)){
       echo $r['daya'];
   }
?>

watt



</CENTER>

</body>

</html>





h. update.php

<?php
require("config.php");

$query = "UPDATE tbdaya SET tegangan='$_POST[tegangan]', arus='$_POST[arus]', daya='$_POST[daya]' WHERE no=1";

if(!@mysql_query($query))
{
    echo "&Answer; SQL Error - ".mysql_error();
    return;
}
?>




i. Setting LOCALHOST







j. Gambar Hasilnya







k. VIDEO HASILNYA











6 comments: