Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang berfungsi untuk memonitor suhu benda atau object yang berjumlah 2 buah, jadi alat ini menggunakan dua buah sensor MLX90614 dan dua buah arduino, komunikasi kedua arduino menggunakan serial UART RX dan TX. alat ini dimonitor menggunakan web browser. untuk lebih jelasnya berikut adalah komponen dan programnya.
a. Arduino Uno
b. Sensor Suhu MLX90614 / GY-906
c. Sensor Getar
d. Router
e. Program Arduino Master
#include <Wire.h>
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
int data1;
int data2;
void setup() {
Serial.begin(9600);
mlx.begin();
}
void loop() {
sensing1();
delay(200);
sensing2();
delay(200);
Serial.print(data1);
Serial.print('\n');
Serial.print(data2);
Serial.print('\n');
}
void sensing1(){
data1 = mlx.readObjectTempC();
}
void sensing2(){
data2 = mlx.readObjectTempC();
}
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
int data1;
int data2;
void setup() {
Serial.begin(9600);
mlx.begin();
}
void loop() {
sensing1();
delay(200);
sensing2();
delay(200);
Serial.print(data1);
Serial.print('\n');
Serial.print(data2);
Serial.print('\n');
}
void sensing1(){
data1 = mlx.readObjectTempC();
}
void sensing2(){
data2 = mlx.readObjectTempC();
}
f. Program Arduino Slave
#include <SPI.h>
#include <Ethernet.h>
#include <Wire.h>
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,99);
EthernetServer server(80);
String readString;
int value1=0;
int value2=0;
double gear1=0;
double gear2=0;
int mlx1;
int mlx2;
int adcgetar;
void setup() {
mlx.begin();
Serial.begin(9600);
while (!Serial) {
}
Ethernet.begin(mac, ip);
server.begin();
//Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
ambil1();
ambil2();
adcgetar = analogRead(0);
if(Serial.available()>0)
{
value1 = Serial.parseInt();
value2 = Serial.parseInt();
gear1=value1;
gear2=value2;
if(Serial.read()=='\n')
{
Serial.print("Bearing 3=");
Serial.print(gear1);
Serial.print(" ");
Serial.print("Bearing 4=");
Serial.print(gear2);
Serial.print("\n");
kirim();
}
}
}
void kirim(){
EthernetClient client = server.available();
if (client) {
//Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 1");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println(" ");
client.println("<title> Monitor Suhu </title> ");
client.println("<body bgcolor = #000000>");
client.println("<center>");
client.println("<font color = yellow><center><h1>MONITOR SUHU BEARING</h1></center><br></font>");
client.println("<font color = #FFFFFF>");
client.println("<h2>");
client.println("Suhu Bearing 1 = ");
client.print(mlx1);
client.println("<br />");
client.println("Suhu Bearing 2 = ");
client.print(mlx2);
client.println("<br />");
client.println("Suhu Bearing 3 = ");
client.print(gear1);
client.println("<br />");
client.println("Suhu Bearing 4 = ");
client.print(gear2);
client.println("<br />");
client.println("ADC Getar = ");
client.print(adcgetar);
client.println("<br />");
client.println("</h2>");
client.println("</font>");
client.println("</center>");
client.println("</body>");
client.println("</html>");
break;
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
//Serial.println("client disonnected");
}
readString="";
}
void ambil1(){
mlx1 = mlx.readObjectTempC();
}
void ambil2(){
mlx2 = mlx.readObjectTempC();
}
g. VIDEO HASILNYA
#include <Ethernet.h>
#include <Wire.h>
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,99);
EthernetServer server(80);
String readString;
int value1=0;
int value2=0;
double gear1=0;
double gear2=0;
int mlx1;
int mlx2;
int adcgetar;
void setup() {
mlx.begin();
Serial.begin(9600);
while (!Serial) {
}
Ethernet.begin(mac, ip);
server.begin();
//Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
ambil1();
ambil2();
adcgetar = analogRead(0);
if(Serial.available()>0)
{
value1 = Serial.parseInt();
value2 = Serial.parseInt();
gear1=value1;
gear2=value2;
if(Serial.read()=='\n')
{
Serial.print("Bearing 3=");
Serial.print(gear1);
Serial.print(" ");
Serial.print("Bearing 4=");
Serial.print(gear2);
Serial.print("\n");
kirim();
}
}
}
void kirim(){
EthernetClient client = server.available();
if (client) {
//Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 1");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println(" ");
client.println("<title> Monitor Suhu </title> ");
client.println("<body bgcolor = #000000>");
client.println("<center>");
client.println("<font color = yellow><center><h1>MONITOR SUHU BEARING</h1></center><br></font>");
client.println("<font color = #FFFFFF>");
client.println("<h2>");
client.println("Suhu Bearing 1 = ");
client.print(mlx1);
client.println("<br />");
client.println("Suhu Bearing 2 = ");
client.print(mlx2);
client.println("<br />");
client.println("Suhu Bearing 3 = ");
client.print(gear1);
client.println("<br />");
client.println("Suhu Bearing 4 = ");
client.print(gear2);
client.println("<br />");
client.println("ADC Getar = ");
client.print(adcgetar);
client.println("<br />");
client.println("</h2>");
client.println("</font>");
client.println("</center>");
client.println("</body>");
client.println("</html>");
break;
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
//Serial.println("client disonnected");
}
readString="";
}
void ambil1(){
mlx1 = mlx.readObjectTempC();
}
void ambil2(){
mlx2 = mlx.readObjectTempC();
}
g. VIDEO HASILNYA
No comments:
Post a Comment