Translate

Membuat Alat Monitoring Arus LAMPU AC via Internet (IOT) menggunakan ARDUINO ethernet webserver

Membuat Alat Monitoring Arus LAMPU AC via Internet (IOT) menggunakan ARDUINO ethernet webserver


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang berfungsi untuk monitoring arus pada sebuah lampu AC berdaya masing-masing 100 watt, lampu ini berjumlah 4 buah dan terdapat saklar untuk menghidupkan atau mematikan lampu secara manual, arus yang terbaca oleh sensor arus ACS712 akan dikirimkan via internet dan akan ditampilkan pada interface server. alat ini menggunakan Arduino sebagai kontrollernya dan ethernet shield untuk media penghubung TCP-IP nya. kemudian router dan modem untuk pengiriman ke website. untuk lebih jelasnya berikut adalah skema dan programnya.




a. Arduino Mega + Ethernet Shield





b. Router + Modem





c. Sensor Arus ACS712





d. Lampu Bohlam 100 watt







e. Program Arduino IDE

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

// 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 txData2="";

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  char server[] = "www.viskositasoli.hol.es";
IPAddress ip(192,168,0,99);

EthernetClient client;

float arus1x;
float arus2x;
float arus3x;
float arus4x;

int arus1;
int arus2;
int arus3;
int arus4;



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

  Serial.begin(9600);
  while (!Serial) {
    ;
  }

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    Ethernet.begin(mac, ip);
  }

    delay(1000);
    Serial.println("connecting...");
    kirim ();
  
  }

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 * 100;
 
  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 * 100;
 
  z = 0;
  i = 0;

//===================================================

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

  arus3x = z * (5.0/1023.0);
  arus3x = (arus3x - 2.438)/ 0.251;
  arus3 = arus3x * 100;

  z = 0;
  i = 0;

//==============================================

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

  arus4x = z * (5.0/1023.0);
  arus4x = (arus4x - 2.438)/ 0.251;
  arus4 = arus4x * 100;

  z = 0;
  i = 0;
 
  kirim ();
}


void kirim (){

  EthernetClient client;

if (client.connect(server, 80)){
    txData2 = "arus1="+ (String (arus1)) + "&arus2="+ (String (arus2)) + "&arus3="+ (String (arus3)) + "&arus4="+ (String (arus4));           
    Serial.println("connected");
    Serial.print(txData2);
    client.println("POST /update2.php HTTP/1.1");
    client.println("Host: www.viskositasoli.hol.es");
    client.println("Connection: close");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(txData2.length());
    client.print("\n\n");
    client.print(txData2);
    Serial.println(txData2);    
    delay (5000);
        
  }  
  else{
    Serial.println("Connection Failed.");
    Serial.println();
    delay (3000);
  }
}





f. Config.php

<?php

$dbhost = 'mysql.idhostinger.com';
$dbuser = 'u1417xxx_local';
$dbpass = '12345';  
$dbname = 'u1417xxx_arus';

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

    }
?>



g. update2.php

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

$query = "UPDATE dbarus SET arus1='$_POST[arus1]', arus2='$_POST[arus2]', arus3='$_POST[arus3]', arus4='$_POST[arus4]' WHERE no=1";

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




h. 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 ARUS</title>
</head>
<body>

<CENTER>
<p><h2> MONITORING ARUS</h2></p>


</CENTER>

<CENTER>
<p><h3>

ARUS 1 =
<?php
include "confignew.php";
$tampil = @mysql_query("SELECT * FROM dbarus WHERE no IN (SELECT MAX(no) FROM dbarus)");
        
    while ($r=mysql_fetch_array($tampil)){
       echo $r[arus1]/100;
             
   }
?>
&nbsp Amper <br>


ARUS 2 =
<?php
include "confignew.php";
$tampil = @mysql_query("SELECT * FROM dbarus WHERE no IN (SELECT MAX(no) FROM dbarus)");
        
    while ($r=mysql_fetch_array($tampil)){
       echo $r[arus2]/100;
             
   }
?>
&nbsp Amper <br>


ARUS 3 =
<?php
include "confignew.php";
$tampil = @mysql_query("SELECT * FROM dbarus WHERE no IN (SELECT MAX(no) FROM dbarus)");
        
    while ($r=mysql_fetch_array($tampil)){
       echo $r[arus3]/100;
             
   }
?>
&nbsp Amper <br>


ARUS 4 =
<?php
include "confignew.php";
$tampil = @mysql_query("SELECT * FROM dbarus WHERE no IN (SELECT MAX(no) FROM dbarus)");
        
    while ($r=mysql_fetch_array($tampil)){
       echo $r[arus4]/100;
             
   }
?>
&nbsp Amper <br>


<BR><BR>

<?php
include "confignew.php";
$tampil = @mysql_query("SELECT * FROM dbarus WHERE no IN (SELECT MAX(no) FROM dbarus)");
        
    while ($r=mysql_fetch_array($tampil)){
             
       if ($r[arus1] > 65) {
         echo "LAMPU 1 ON";
       }
     
       if ($r[arus1] < 65) {
         echo "LAMPU 1 OFF";
       }
      
   }
?>
<br>


<?php
include "confignew.php";
$tampil = @mysql_query("SELECT * FROM dbarus WHERE no IN (SELECT MAX(no) FROM dbarus)");
        
    while ($r=mysql_fetch_array($tampil)){
             
       if ($r[arus2] > 65) {
         echo "LAMPU 2 ON";
       }
     
       if ($r[arus2] < 65) {
         echo "LAMPU 2 OFF";
       }
      
   }
?>
<br>



<?php
include "confignew.php";
$tampil = @mysql_query("SELECT * FROM dbarus WHERE no IN (SELECT MAX(no) FROM dbarus)");
        
    while ($r=mysql_fetch_array($tampil)){
             
       if ($r[arus3] > 65) {
         echo "LAMPU 3 ON";
       }
     
       if ($r[arus3] < 65) {
         echo "LAMPU 3 OFF";
       }
      
   }
?>
<br>



<?php
include "confignew.php";
$tampil = @mysql_query("SELECT * FROM dbarus WHERE no IN (SELECT MAX(no) FROM dbarus)");
        
    while ($r=mysql_fetch_array($tampil)){
             
       if ($r[arus4] > 65) {
         echo "LAMPU 4 ON";
       }
     
       if ($r[arus4] < 65) {
         echo "LAMPU 4 OFF";
       }
      
   }
?>
<br>

</CENTER>
</body>
</html>





i. Gambar Interface Server







j. VIDEO HASILNYA









No comments:

Post a Comment