Yah kali ini saya akan menjelaskan mengenai bagaimana cara membuat alat untuk memonitoring kecepatan air dalam m/s menggunakan water flow sensor, alat ini memiliki kelebihan yang diunggulkan yaitu dapat mengirimkan data ke internet atau web hosting sehingga siapapun, kapanpun dan dimanapun user berada, user dapat memantau kondisinya selama koneksi internet masih lancar, itulah kelebihan dari alat ini yaitu tidak kenal jarak. untuk lebih jelasnya berikut akan dijelaskan mengenai bagaimana program dan skemanya.
a. Arduino Uno
c. Router TP-LINK dan Modem Huawei
d. Program Arduino Uno
#include <SPI.h>
#include <Ethernet.h>
String txData2="";
float ms;
char T_string[10];
String f;
volatile int NbTopsFan;
int Calc;
int hallsensor = 2;
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "www.monitoring.hol.es";
IPAddress ip(192,168,1,99);
EthernetClient client;
void rpm ()
{
NbTopsFan++;
}
void setup() {
pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
Serial.begin(9600); //This is the setup function where the serial port is initialised
attachInterrupt(0, rpm, RISING);
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
}
delay(1000);
Serial.println("connecting...");
datain ();
kirim ();
}
void loop() {
datain ();
kirim ();
}
void datain() {
NbTopsFan = 0;
sei();
delay (1000);
cli();
Calc = (NbTopsFan * 60 / 7.5);
Serial.print (Calc, DEC);
Serial.print (" L/hour\r\n");
}
void kirim() {
EthernetClient client;
if (client.connect(server, 80)){
ms = (Calc / 60) * 6.28 * 0.015;
dtostrf(ms,6, 2,T_string);
f = String(T_string);
Serial.println(f);
Serial.println("connected");
txData2 = "ms="+ (f);
Serial.println(txData2);
client.println("POST /insert.php HTTP/1.1");
client.println("Host: www.monitoring.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);
delay (1000);
}
else{
Serial.println("Connection Failed.");
Serial.println();
delay (1000);
}
}
#include <Ethernet.h>
String txData2="";
float ms;
char T_string[10];
String f;
volatile int NbTopsFan;
int Calc;
int hallsensor = 2;
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "www.monitoring.hol.es";
IPAddress ip(192,168,1,99);
EthernetClient client;
void rpm ()
{
NbTopsFan++;
}
void setup() {
pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
Serial.begin(9600); //This is the setup function where the serial port is initialised
attachInterrupt(0, rpm, RISING);
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
}
delay(1000);
Serial.println("connecting...");
datain ();
kirim ();
}
void loop() {
datain ();
kirim ();
}
void datain() {
NbTopsFan = 0;
sei();
delay (1000);
cli();
Calc = (NbTopsFan * 60 / 7.5);
Serial.print (Calc, DEC);
Serial.print (" L/hour\r\n");
}
void kirim() {
EthernetClient client;
if (client.connect(server, 80)){
ms = (Calc / 60) * 6.28 * 0.015;
dtostrf(ms,6, 2,T_string);
f = String(T_string);
Serial.println(f);
Serial.println("connected");
txData2 = "ms="+ (f);
Serial.println(txData2);
client.println("POST /insert.php HTTP/1.1");
client.println("Host: www.monitoring.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);
delay (1000);
}
else{
Serial.println("Connection Failed.");
Serial.println();
delay (1000);
}
}
e. Program Hosting
config.php
<?php
$dbhost = 'mysql.idhostinger.com';
$dbuser = 'u86xxxx_speed';
$dbpass = '12398987';
$dbname = 'u86xxxxx_flow';
$conn = @mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
if(!$conn){
echo "database gak konek";
}else{
echo "";
}
?>
$dbhost = 'mysql.idhostinger.com';
$dbuser = 'u86xxxx_speed';
$dbpass = '12398987';
$dbname = 'u86xxxxx_flow';
$conn = @mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
if(!$conn){
echo "database gak konek";
}else{
echo "";
}
?>
insert.php
<?php
require("config.php");
$query = "INSERT INTO tbmonitoring (ms) VALUES('$_POST[ms]')";
if(!@mysql_query($query))
{
echo "&Answer; SQL Error - ".mysql_error();
return;
}
?>
require("config.php");
$query = "INSERT INTO tbmonitoring (ms) VALUES('$_POST[ms]')";
if(!@mysql_query($query))
{
echo "&Answer; SQL Error - ".mysql_error();
return;
}
?>
default.php
<html>
<head>
<meta http-equiv="refresh" content="3">
<style>
.bordered { border-style:solid; }
</style>
<title >Monitoring</title>
</head>
<body>
<center>
<p><h2> MONITORING KECEPATAN AIR </h2></p>
<p><h3>
KECEPATAN =
<?php
include "config.php";
$tampil = mysql_query("SELECT * FROM tbmonitoring WHERE no IN (SELECT MAX(no) FROM tbmonitoring)");
while ($r=mysql_fetch_array($tampil)){
echo "$r[ms]";
}
?>
m/s
</center>
</body>
</html>
f. VIDEO HASILNYA
No comments:
Post a Comment