Translate

Membuat Alat Monitoring Polusi via Internet Menggunakan Ethernet Webserver dan Arduino

Membuat Alat Monitoring Polusi via Internet Menggunakan Ethernet Webserver dan Arduino


               Pada kesempatan yang berbahagia kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang digunakan untuk monitoring polusi udara menggunakan internet webserver. alat ini hanya digunakan untuk monitoring jarak jauh tanpa bisa kendali jarak jauh, jadi terdapat dua buah arduino yang mana arduino 1 untuk mengolah menjadi data ppm kemudian arduino 2 digunakan untuk mengirim data ke server, sebenarnya menggunakan 1 arduino saja bisa namun dikarenakan pinout-nya tidak cukup maka digunakanlah 2 arduino. sensor yang digunakan bisa dimodifikasi sesuai keinginan, untuk lebih jelasnya berikut skema dan programnya.




a. Arduino Uno + Ethernet Shield





b. Router + Modem GSM





c. Cara Konfigurasi Web Hosting





d. Program Arduino IDE

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

String txData2="";

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

EthernetClient client;

double s_humidity=0;
double s_temperature=0;
double s_windspeed=0;
double s_direction=1;
double s_dust=0;
double s_ppm_CO=0;
double s_ppm_O3=0;
double s_ppm_NH3=0;
double s_ppm_CO2=0;

int value1=0;           
int value2=0;  
int value3=0;  
int value4=0;  
int value5=0;  
int value6=0;  
int value7=0;  
int value8=0;  
int value9=0;  

void setup()
{
    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()
{
  kirim ();
}

void kirim (){
 
   while(Serial.available()>0)
    {
        value1 = Serial.parseInt();           
        value2 = Serial.parseInt();         
        value3 = Serial.parseInt();
        value4 = Serial.parseInt();           
        value5 = Serial.parseInt();         
        value6 = Serial.parseInt();
        value7 = Serial.parseInt();           
        value8 = Serial.parseInt();         
        value9 = Serial.parseInt();
       
        s_windspeed=value1;
        s_direction=value2;
        s_humidity=value3;
        s_temperature=value4;
        s_dust=value5;
        s_ppm_CO=value6;
        s_ppm_O3=value7;
        s_ppm_NH3=value8;
        s_ppm_CO2=value9;
       
        if(Serial.read()=='\n')
        {
                     
            Serial.print("windspeed=");
            Serial.print(s_windspeed);
            Serial.print("  ");
           
            Serial.print("direction=");
            Serial.print(s_direction);
            Serial.print("  ");
           
            Serial.print("humidity=");
            Serial.print(s_humidity);
            Serial.print("  ");
           
            Serial.print("temp=");
            Serial.print(s_temperature);
            Serial.print("  ");
           
            Serial.print("dust=");
            Serial.print(s_dust);
            Serial.print("  ");
           
            Serial.print("ppm CO=");
            Serial.print(s_ppm_CO);
            Serial.print("  ");
           
            Serial.print("ppm O3=");
            Serial.print(s_ppm_O3);
            Serial.print("  ");
           
            Serial.print("ppm NH3=");
            Serial.print(s_ppm_NH3);
            Serial.print("  ");
           
            Serial.print("ppm CO2=");
            Serial.print(s_ppm_CO2);
            Serial.print("\n");

  EthernetClient client;

if (client.connect(server, 80)){
    txData2 = "value1="+ (String (value1)) + "&value2="+ (String (value2)) + "&value3="+ (String (value3)) + "&value4="+ (String (value4)) + "&value5="+ (String (value5)) + "&value6="+ (String (value6)) + "&value7="+ (String (value7)) + "&value8="+ (String (value8)) + "&value9="+ (String (value9));           
    Serial.println("connected");
    Serial.print(txData2);
    client.println("POST /insert.php HTTP/1.1");
    client.println("Host: www.polusigasku.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 (10000);
        
  }  
  else{
    Serial.println("Connection Failed.");
    Serial.println();
    delay (1500);
  }
 
          }
    }
   }





e. Program PHP / HTML

1. 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 POLUSI GAS</title>

</head>


<body>

<CENTER>
<p><h2> MONITORING POLUSI UDARA</h2></p>


<script type='text/javascript'>
<!--
var months = ['Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember'];
var myDays = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jum&#39;at', 'Sabtu'];
var date = new Date();
var day = date.getDate();
var month = date.getMonth();
var thisDay = date.getDay(),
    thisDay = myDays[thisDay];
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
document.write(thisDay + ', ' + day + ' ' + months[month] + ' ' + year);
//-->
</script>

<br>


<script type="text/javascript">
<!--
var a_p = "";
var d = new Date();
var curr_hour = d.getHours();
if (curr_hour < 12) {
    a_p = "AM";
} else {
    a_p = "PM";
}
if (curr_hour == 0) {
    curr_hour = 12;
}
if (curr_hour > 12) {
    curr_hour = curr_hour - 12;
}

var curr_min = d.getMinutes();
curr_min = curr_min + "";
if (curr_min.length == 1) {
    curr_min = "0" + curr_min;
}
document.write(curr_hour + " : " + curr_min + " " + a_p);
//-->
</script>

<br><br>
<input type="button" onclick="location.href='http://polusigas.hol.es/dbshow.php';" value="Lihat Database" />
<br>
</CENTER>

<CENTER>
<p><h3>

WIND SPEED =
<?php
$a=100;
include "config.php";
$tampil = @mysql_query("SELECT * FROM tbgas WHERE no IN (SELECT MAX(no) FROM tbgas)");
        
    while ($r=mysql_fetch_array($tampil)){
       echo $r[value1]/$a;
   }
?>
&nbsp M/S

<br>
WIND DIRECTION =
<?php
include "config.php";
$tampil = @mysql_query("SELECT * FROM tbgas WHERE no IN (SELECT MAX(no) FROM tbgas)");
        
    while ($r=mysql_fetch_array($tampil)){

       $b = $r[value2];

if ($r[value2] == 1) {
    echo "NORTH";
}
elseif ($r[value2] == 2) {
    echo "NORTH EAST";
}
elseif ($r[value2] == 3) {
    echo "EAST";
}
elseif ($r[value2] == 4) {
    echo "SOUTH EAST";
}
elseif ($r[value2] == 5) {
    echo "SOUTH";
}
elseif ($r[value2] == 6) {
    echo "SOUTH WEST";
}
elseif ($r[value2] == 7) {
    echo "WEST";
}
elseif ($r[value2] == 8) {
    echo "NORTH WEST";
}


   }
?>



<br>
HUMIDITY =
<?php
$c=10;
include "config.php";
$tampil = @mysql_query("SELECT * FROM tbgas WHERE no IN (SELECT MAX(no) FROM tbgas)");
        
    while ($r=mysql_fetch_array($tampil)){
       echo $r[value3]/$c;
   }
?>
&nbsp %


<br>
TEMPERATURE =
<?php
$d=10;
include "config.php";
$tampil = @mysql_query("SELECT * FROM tbgas WHERE no IN (SELECT MAX(no) FROM tbgas)");
        
    while ($r=mysql_fetch_array($tampil)){
       echo $r[value4]/$d;
   }
?>
&nbsp C


<br>
PM =
<?php
$e=100;
include "config.php";
$tampil = @mysql_query("SELECT * FROM tbgas WHERE no IN (SELECT MAX(no) FROM tbgas)");
        
    while ($r=mysql_fetch_array($tampil)){
       echo $r[value5]/$e;
   }
?>
&nbsp MG/M3

<br>
GAS CO =
<?php
$f=100;
include "config.php";
$tampil = @mysql_query("SELECT * FROM tbgas WHERE no IN (SELECT MAX(no) FROM tbgas)");
        
    while ($r=mysql_fetch_array($tampil)){
       echo $r[value6]/$f;
   }
?>
&nbsp PPM


<br>
GAS O3 =
<?php
$g=100;
include "config.php";
$tampil = @mysql_query("SELECT * FROM tbgas WHERE no IN (SELECT MAX(no) FROM tbgas)");
        
    while ($r=mysql_fetch_array($tampil)){
       echo $r[value7]/$g;
   }
?>
&nbsp PPM

<br>
GAS NH3 =
<?php
$h=100;
include "config.php";
$tampil = @mysql_query("SELECT * FROM tbgas WHERE no IN (SELECT MAX(no) FROM tbgas)");
        
    while ($r=mysql_fetch_array($tampil)){
       echo $r[value8]/$h;
   }
?>
&nbsp PPM

<br>
GAS CO2 =
<?php
$i=100;
include "config.php";
$tampil = @mysql_query("SELECT * FROM tbgas WHERE no IN (SELECT MAX(no) FROM tbgas)");
        
    while ($r=mysql_fetch_array($tampil)){
       echo $r[value9]/$i;
   }
?>
&nbsp PPM


</CENTER>

</body>

</html>





2. dbshow.php

<html>
<head>
<meta http-equiv="refresh" content="3">
<style>
.bordered { border-style:solid; }
</style>
<title >DATABASE</title>
</head>
<body bgcolor = #ffaaff>

<CENTER>
<p><h2> DATABASE MONITORING POLUSI GAS</h2></p>

<br>
<input type="button" onclick="location.href='http://polusigas.hol.es/index.php';" value=" HOME " />
<br>
<br>
<br>

<?php
include "config.php";

$a=100;
$b=10;

$tampil = mysql_query("SELECT * FROM tbgas");

 echo "<table border = '1'>
          <tr><th bgcolor = #FFFFFF>WIND SPEED</th>
          <th bgcolor = #FFFFFF>WIND DIRECTION</th>
          <th bgcolor = #FFFFFF>TEMPERATURE</th>
          <th bgcolor = #FFFFFF>HUMIDITY</th>
          <th bgcolor = #FFFFFF>PM</th>
          <th bgcolor = #FFFFFF>GAS CO</th>
          <th bgcolor = #FFFFFF>GAS O3</th>
          <th bgcolor = #FFFFFF>GAS NH3</th>
          <th bgcolor = #FFFFFF>GAS CO2</th>

          </tr>";
 
    while ($r=mysql_fetch_array($tampil)){
       $x1 = $r[value1]/$a;
       $x2 = $r[value3]/$b;
       $x3 = $r[value4]/$b;
       $x4 = $r[value5]/$a;
       $x5 = $r[value6]/$a;
       $x6 = $r[value7]/$a;
       $x7 = $r[value8]/$a;
       $x8 = $r[value9]/$a;

if ($r[value2] == 1) {
    $z = "NORTH";
}
elseif ($r[value2] == 2) {
    $z = "NORTH EAST";
}
elseif ($r[value2] == 3) {
    $z = "EAST";
}
elseif ($r[value2] == 4) {
    $z = "SOUTH EAST";
}
elseif ($r[value2] == 5) {
    $z = "SOUTH";
}
elseif ($r[value2] == 6) {
    $z = "SOUTH WEST";
}
elseif ($r[value2] == 7) {
    $z = "WEST";
}
elseif ($r[value2] == 8) {
    $z = "NORTH WEST";
}

       echo "<tr>
             <td bgcolor = #FFC848>$x1</td>
             <td bgcolor = #FFC848>$z</td>
             <td bgcolor = #FFC848>$x2</td>
             <td bgcolor = #FFC848>$x3</td>
             <td bgcolor = #FFC848>$x4</td>
             <td bgcolor = #FFC848>$x5</td>
             <td bgcolor = #FFC848>$x6</td>
             <td bgcolor = #FFC848>$x7</td>
             <td bgcolor = #FFC848>$x8</td>

       </tr>";
    }
    echo "</table>";

@mysql_close($con);

?>

</CENTER>

</body>
</html>





3. insert.php

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

$query = "INSERT INTO tbgas (value1, value2, value3, value4, value5, value6, value7, value8, value9) VALUES('$_POST[value1]','$_POST[value2]','$_POST[value3]','$_POST[value4]','$_POST[value5]','$_POST[value6]','$_POST[value7]','$_POST[value8]','$_POST[value9]')";

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

?>




4. config.php

<?php

$dbhost = 'mysql.idhostinger.com';
$dbuser = 'u820xxxxxxxxccc';
$dbpass = '1235xxxxxxxxxxx';  
$dbname = 'u82042xxxxxxxx';

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

    }
?>





f. Gambar Hasilnya














No comments:

Post a Comment