Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor polusi udara menggunakan Arduino sebagai kontrollernya serta internet sebagai media pengiriman datanya (IOT). alat ini terdiri dari beberapa bagian yaitu bagian sensor, bagian pengolah data dan bagian pengiriman data, untuk interface menggunakan server dari www.idhostinger.com. untuk lebih jelasnya berikut adalah skema dan programnya.
a. Arduino Uno + Ethernet Shield
b. Sensor Gas Polutan
c. Router + Modem USB
d. Program Arduino IDE
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <Ethernet.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
String txData2="";
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "www.monitoring-udara.hol.es";
IPAddress ip(192,168,0,99);
EthernetClient client;
void setup()
{
lcd.begin();
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()
{
int voltage0 = analogRead(A0); //mq135
int voltage1 = analogRead(A1); //mq9
int voltage2 = analogRead(A2); //gasamonia
int voltage3 = analogRead(A3); //gasco2
EthernetClient client;
if (client.connect(server, 80)){
txData2 = "voltage0="+ (String (voltage0)) + "&voltage1="+ (String (voltage1)) + "&voltage2="+ (String (voltage2)) + "&voltage3="+ (String (voltage3));
Serial.println("connected");
Serial.print(txData2);
client.println("POST /updatex.php HTTP/1.1");
client.println("Host: www.monitoring-udara.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 (1000);
}
else{
Serial.println("Connection Failed.");
Serial.println();
delay (1500);
}
lcd.setCursor(0,0);
lcd.print("1=");
lcd.print(voltage0);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("2=");
lcd.print(voltage1);
lcd.print(" ");
lcd.setCursor(7,0);
lcd.print("3=");
lcd.print(voltage2);
lcd.print(" ");
lcd.setCursor(7,1);
lcd.print("4=");
lcd.print(voltage3);
lcd.print(" ");
delay(5000);
}
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <Ethernet.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
String txData2="";
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "www.monitoring-udara.hol.es";
IPAddress ip(192,168,0,99);
EthernetClient client;
void setup()
{
lcd.begin();
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()
{
int voltage0 = analogRead(A0); //mq135
int voltage1 = analogRead(A1); //mq9
int voltage2 = analogRead(A2); //gasamonia
int voltage3 = analogRead(A3); //gasco2
EthernetClient client;
if (client.connect(server, 80)){
txData2 = "voltage0="+ (String (voltage0)) + "&voltage1="+ (String (voltage1)) + "&voltage2="+ (String (voltage2)) + "&voltage3="+ (String (voltage3));
Serial.println("connected");
Serial.print(txData2);
client.println("POST /updatex.php HTTP/1.1");
client.println("Host: www.monitoring-udara.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 (1000);
}
else{
Serial.println("Connection Failed.");
Serial.println();
delay (1500);
}
lcd.setCursor(0,0);
lcd.print("1=");
lcd.print(voltage0);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("2=");
lcd.print(voltage1);
lcd.print(" ");
lcd.setCursor(7,0);
lcd.print("3=");
lcd.print(voltage2);
lcd.print(" ");
lcd.setCursor(7,1);
lcd.print("4=");
lcd.print(voltage3);
lcd.print(" ");
delay(5000);
}
e. updatex.php
<?php
require("configx.php");
$query = "UPDATE tbudara SET voltage0='$_POST[voltage0]', voltage1='$_POST[voltage1]', voltage2='$_POST[voltage2]', voltage3='$_POST[voltage3]' WHERE no=1";
if(!@mysql_query($query))
{
echo "&Answer; SQL Error - ".mysql_error();
return;
}
?>
require("configx.php");
$query = "UPDATE tbudara SET voltage0='$_POST[voltage0]', voltage1='$_POST[voltage1]', voltage2='$_POST[voltage2]', voltage3='$_POST[voltage3]' WHERE no=1";
if(!@mysql_query($query))
{
echo "&Answer; SQL Error - ".mysql_error();
return;
}
?>
f. 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 >AIR QUALITY CONTROL</title>
</head>
<center>
<p><h2>AIR QUALITY CONTROL</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'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>
</center>
<body>
<CENTER>
<br>
<input type="button" onclick="location.href='http://monitoring-udara.hol.es/dbshow.php';" value="Lihat Database" />
<br><br>
</CENTER>
<CENTER>
<p><h3>
Konsentrasi GAS CO2 =
<?php
include "configx.php";
$tampil = @mysql_query("SELECT * FROM tbudara WHERE no IN (SELECT MAX(no) FROM tbudara)");
while ($r=mysql_fetch_array($tampil)){
echo $r[voltage0];
}
?>
<br>
Konsentrasi GAS SnO2 =
<?php
include "configx.php";
$tampil = @mysql_query("SELECT * FROM tbudara WHERE no IN (SELECT MAX(no) FROM tbudara)");
while ($r=mysql_fetch_array($tampil)){
echo "$r[voltage1]";
}
?>
<br>
Konsentrasi GAS NH3 =
<?php
include "configx.php";
$tampil = @mysql_query("SELECT * FROM tbudara WHERE no IN (SELECT MAX(no) FROM tbudara)");
while ($r=mysql_fetch_array($tampil)){
echo "$r[voltage2]";
}
?>
<br>
Konsentrasi GAS CO =
<?php
include "configx.php";
$tampil = @mysql_query("SELECT * FROM tbudara WHERE no IN (SELECT MAX(no) FROM tbudara)");
while ($r=mysql_fetch_array($tampil)){
echo "$r[voltage3]";
}
?>
</CENTER>
<br><br><br>
</body>
</html>
<head>
<meta http-equiv="refresh" content="3">
<style>
.bordered { border-style:solid; }
</style>
<link rel="stylesheet" type="text/css" href="latweb.css" />
<title >AIR QUALITY CONTROL</title>
</head>
<center>
<p><h2>AIR QUALITY CONTROL</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'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>
</center>
<body>
<CENTER>
<br>
<input type="button" onclick="location.href='http://monitoring-udara.hol.es/dbshow.php';" value="Lihat Database" />
<br><br>
</CENTER>
<CENTER>
<p><h3>
Konsentrasi GAS CO2 =
<?php
include "configx.php";
$tampil = @mysql_query("SELECT * FROM tbudara WHERE no IN (SELECT MAX(no) FROM tbudara)");
while ($r=mysql_fetch_array($tampil)){
echo $r[voltage0];
}
?>
<br>
Konsentrasi GAS SnO2 =
<?php
include "configx.php";
$tampil = @mysql_query("SELECT * FROM tbudara WHERE no IN (SELECT MAX(no) FROM tbudara)");
while ($r=mysql_fetch_array($tampil)){
echo "$r[voltage1]";
}
?>
<br>
Konsentrasi GAS NH3 =
<?php
include "configx.php";
$tampil = @mysql_query("SELECT * FROM tbudara WHERE no IN (SELECT MAX(no) FROM tbudara)");
while ($r=mysql_fetch_array($tampil)){
echo "$r[voltage2]";
}
?>
<br>
Konsentrasi GAS CO =
<?php
include "configx.php";
$tampil = @mysql_query("SELECT * FROM tbudara WHERE no IN (SELECT MAX(no) FROM tbudara)");
while ($r=mysql_fetch_array($tampil)){
echo "$r[voltage3]";
}
?>
</CENTER>
<br><br><br>
</body>
</html>
g. dbshow.php
<html>
<head>
<meta http-equiv="refresh" content="3">
<style>
.bordered { border-style:solid; }
</style>
<title >DATABASE</title>
</head>
<body bgcolor = #ffffff>
<CENTER>
<p><h2>AIR QUALITY CONTROL DATABASE</h2></p>
<center>
<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'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>
</center>
<br>
<input type="button" onclick="location.href='http://monitoring-udara.hol.es/index.php';" value=" HOME " />
<br>
<input type="button" onclick="location.href='http://monitoring-udara.hol.es/downloadExcel.php';" value=" Download Data" />
<br>
<?php
include "configx.php";
//$id=mysql_fetch_array(mysql_query("SELECT * FROM tbudara ORDER BY no desc LIMIT 1 "))[no];
//mysql_query("UPDATE `u761553243_udara`.`tbudara` SET `waktu` = (SELECT CONVERT_TZ(CURRENT_TIMESTAMP,'+00:00','+07:00')) WHERE `tbudara`.`no` =$id;");
$tampil = mysql_query("SELECT * FROM tbudara ORDER BY `tbudara`.`no` DESC");
echo "<table border = '0'>
<tr><th bgcolor = #F0F011>GAS CO2</th><th bgcolor = #F0F011>GAS SnO2</th><th bgcolor = #F0F011>GAS NH3</th><th bgcolor = #F0F011>GAS CO</th></tr>";
while ($r=mysql_fetch_array($tampil)){
echo "<tr>
<td bgcolor = #FFC848>$r[voltage0]</td>
<td bgcolor = #FFC848>$r[voltage1]</td>
<td bgcolor = #FFC848>$r[voltage2]</td>
<td bgcolor = #FFC848>$r[voltage3]</td></tr>";
}
echo "</table>";
@mysql_close($con);
?>
</CENTER>
</body>
</html>
h. configx.php
<head>
<meta http-equiv="refresh" content="3">
<style>
.bordered { border-style:solid; }
</style>
<title >DATABASE</title>
</head>
<body bgcolor = #ffffff>
<CENTER>
<p><h2>AIR QUALITY CONTROL DATABASE</h2></p>
<center>
<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'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>
</center>
<br>
<input type="button" onclick="location.href='http://monitoring-udara.hol.es/index.php';" value=" HOME " />
<br>
<input type="button" onclick="location.href='http://monitoring-udara.hol.es/downloadExcel.php';" value=" Download Data" />
<br>
<?php
include "configx.php";
//$id=mysql_fetch_array(mysql_query("SELECT * FROM tbudara ORDER BY no desc LIMIT 1 "))[no];
//mysql_query("UPDATE `u761553243_udara`.`tbudara` SET `waktu` = (SELECT CONVERT_TZ(CURRENT_TIMESTAMP,'+00:00','+07:00')) WHERE `tbudara`.`no` =$id;");
$tampil = mysql_query("SELECT * FROM tbudara ORDER BY `tbudara`.`no` DESC");
echo "<table border = '0'>
<tr><th bgcolor = #F0F011>GAS CO2</th><th bgcolor = #F0F011>GAS SnO2</th><th bgcolor = #F0F011>GAS NH3</th><th bgcolor = #F0F011>GAS CO</th></tr>";
while ($r=mysql_fetch_array($tampil)){
echo "<tr>
<td bgcolor = #FFC848>$r[voltage0]</td>
<td bgcolor = #FFC848>$r[voltage1]</td>
<td bgcolor = #FFC848>$r[voltage2]</td>
<td bgcolor = #FFC848>$r[voltage3]</td></tr>";
}
echo "</table>";
@mysql_close($con);
?>
</CENTER>
</body>
</html>
h. configx.php
<?php
$dbhost = 'mysql.idhostinger.com';
$dbuser = 'u76xxxx_local';
$dbpass = '19986876';
$dbname = 'u76xxx_udara';
$conn = @mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
if(!$conn){
echo "database gak konek";
}else{
}
?>
$dbhost = 'mysql.idhostinger.com';
$dbuser = 'u76xxxx_local';
$dbpass = '19986876';
$dbname = 'u76xxx_udara';
$conn = @mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
if(!$conn){
echo "database gak konek";
}else{
}
?>
i. VIDEO HASILNYA
No comments:
Post a Comment