Monitoring Gas Menggunakan Internet Web Server dan Arduino + Ethernet
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat alat monitoring gas via internet, jadi data yang didapat oleh Arduino dikirimkan ke server online melalui media internet dan router. Data yang dikirimkan adalah data berupa gas yang akan disimpan di hosting server / MySQL Database dan akan ditampilkan melalui HTML / PHP. untuk lebih jelasnya berikut adalah program dan skema alatnya.
b. Router Support Modem
c. Sensor Gas
d. Program Arduino IDE
#include <SPI.h>
#include <Ethernet.h>
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() {
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);
EthernetClient client;
if (client.connect(server, 80)){
txData2 = "voltage0="+ (String (voltage0));
Serial.println("connected");
Serial.print(txData2);
client.println("POST /insert.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);
}
}
#include <Ethernet.h>
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() {
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);
EthernetClient client;
if (client.connect(server, 80)){
txData2 = "voltage0="+ (String (voltage0));
Serial.println("connected");
Serial.print(txData2);
client.println("POST /insert.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);
}
}
e. config.php
<?php
$dbhost = 'mysql.idhostinger.com';
$dbuser = 'u76xxxx_local';
$dbpass = '12345';
$dbname = 'u76xxxx_udara';
$conn = @mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
if(!$conn){
echo "database gak konek";
}else{
}
?>
f. insert.php
<?php
require("config.php");
$query = "INSERT INTO tbudara (voltage0) VALUES('$_POST[voltage0]')";
if(!@mysql_query($query))
{
echo "&Answer; SQL Error - ".mysql_error();
return;
}
?>
require("config.php");
$query = "INSERT INTO tbudara (voltage0) VALUES('$_POST[voltage0]')";
if(!@mysql_query($query))
{
echo "&Answer; SQL Error - ".mysql_error();
return;
}
?>
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 UDARA</title>
</head>
<body>
<CENTER>
<p><h2> MONITORING UDARA</h2></p>
<br>
<input type="button" onclick="location.href='http://monitoring-udara.hol.es/dbshow.php';" value="Lihat Database" />
<br>
</CENTER>
<CENTER>
<p><h3>
Konsentrasi GAS CO =
<?php
include "config.php";
$tampil = @mysql_query("SELECT * FROM tbudara WHERE no IN (SELECT MAX(no) FROM tbudara)");
while ($r=mysql_fetch_array($tampil)){
echo "$r[voltage0]";
}
?>
</CENTER>
</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 >MONITORING UDARA</title>
</head>
<body>
<CENTER>
<p><h2> MONITORING UDARA</h2></p>
<br>
<input type="button" onclick="location.href='http://monitoring-udara.hol.es/dbshow.php';" value="Lihat Database" />
<br>
</CENTER>
<CENTER>
<p><h3>
Konsentrasi GAS CO =
<?php
include "config.php";
$tampil = @mysql_query("SELECT * FROM tbudara WHERE no IN (SELECT MAX(no) FROM tbudara)");
while ($r=mysql_fetch_array($tampil)){
echo "$r[voltage0]";
}
?>
</CENTER>
</body>
</html>
h. 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 UDARA</h2></p>
<br>
<input type="button" onclick="location.href='http://monitoring-udara.hol.es/index.php';" value=" HOME " />
<br>
<br>
<br>
<?php
include "config.php";
$tampil = mysql_query("SELECT * FROM tbudara");
echo "<table border = '1'>
<tr><th bgcolor = #C87C5B>GAS CO</th></tr>";
while ($r=mysql_fetch_array($tampil)){
echo "<tr>
<td bgcolor = #FFC848>$r[voltage0]</td></tr>";
}
echo "</table>";
@mysql_close($con);
?>
</CENTER>
</body>
</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 UDARA</h2></p>
<br>
<input type="button" onclick="location.href='http://monitoring-udara.hol.es/index.php';" value=" HOME " />
<br>
<br>
<br>
<?php
include "config.php";
$tampil = mysql_query("SELECT * FROM tbudara");
echo "<table border = '1'>
<tr><th bgcolor = #C87C5B>GAS CO</th></tr>";
while ($r=mysql_fetch_array($tampil)){
echo "<tr>
<td bgcolor = #FFC848>$r[voltage0]</td></tr>";
}
echo "</table>";
@mysql_close($con);
?>
</CENTER>
</body>
</html>
i. pragram menampilkan jam tanggal (java script)
<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>
j. Contoh Program PHP untuk menghasilkan tampilan koma di index.php
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;
}
?>
k. Contoh Program Parsing PHP dengan If else
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";
}
}
?>
l. Gambar Hasilnya
Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com
atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :