Program Arduino Ethernet dengan Sensor Suhu LM35 dan DHT11 Untuk Mengendalikan Suhu Ruangan

Berikut ini adalah program dari project smart warehouse yang pernah saya buat.
cara kerjanya cukup mudah yaitu pengontrolan suhu ruangan suatu pabrik yang kita jaga konstan dimana nilai sensor kita monitoring menggunakan visual basic-net , dimana komunikasinya kita menggunakan ethernet sehingga bisa dikendalikan secara jarak jauh , visual basic digunakan sebagai tampilan dengan fitur yang dapat menerima data dari arduino juga memberi perintah ke arduino (menggunakan alamat ip)

Oh ya program ini pengontrolannya masih on-off jadi kurang smooth gitu..
untuk video nya menyusul saya lupa taruh mana tuh file…

Berikut ini adalah program Arduino-nya

#include <SPI.h>
#include <Ethernet.h>
#include <Wire.h>
#include <LiquidCrystal.h>
#include “DHT.h”

#define DHTPIN 2 // what digital pin we’re connected to

// Uncomment whatever type you’re using!
#define DHTTYPE DHT11 // DHT 11
//define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

DHT dht(DHTPIN, DHTTYPE);
int kipas = 5 ;
int pemanas = 6 ;
int pin_suhu = A3 ;
//int pin_ldr = A2 ;
int lamp1 = 7 ;
int lamp2 = 8 ;
int lamp3 = 9 ;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress serverIP(192, 168, 0, 2);
int serverPort=80;
EthernetServer server(serverPort);
//LiquidCrystal lcd(2,3,4,5,6,7);
const int pin0=A0;
const int pin1=A1;
double a;
double a1;
int olah;
int olah1;
int lampu ;

String commandStr =””;
int i=0;
int startdata;
void setup()
{

Serial.println(“DHTxx test!”);
analogReference(INTERNAL);

pinMode(kipas,OUTPUT);
pinMode(pemanas,OUTPUT);
pinMode(lamp1,OUTPUT);
pinMode(lamp2,OUTPUT);
pinMode(lamp3,OUTPUT);

startdata=0;
dht.begin();
Ethernet.begin(mac, serverIP);
server.begin();
a=0;
a1=0;
Serial.begin(9600);
i=0;
// lcd.begin(16,2);

}

void loop()
{
// a = analogRead(pin0);

// olah = a;
// a1 = analogRead(pin1);
// olah1 = a1;

// Wait a few seconds between measurements.
// int ldr = analogRead(pin_ldr);
float celcius = analogRead(pin_suhu) / 9.31 ;

//Serial.print(” ldr = “);Serial.println(ldr);
delay(1000);

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}

// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);

float suhu = t + 1 ;
/*
Serial.print(“Suhu Lm35 = “); Serial.print(celcius); Serial.print(” *C “);
Serial.print(“Humidity: “);
Serial.print(h);
Serial.print(” %\t”);
Serial.print(“Temperature DHT: “);
Serial.print(t);
Serial.println(” *C “);
*/
Serial.print(“|”);
Serial.print(suhu);
Serial.print(“|”);
Serial.print(t);
Serial.print(“|”);

/*
lcd.setCursor(0,0);
lcd.print(“Tegangan:”);
lcd.print(olah);
lcd.print(” Volt”);
lcd.setCursor(0,1);
lcd.print(“Arus:”);
lcd.print(olah1);
lcd.print(” Ampere”);
*/
//Serial.print(olah);
//Serial.print(“|”);
//Serial.print(olah1);
//Serial.println();
delay(250);

EthernetClient client = server.available();
String commandStr =””;//Connamdstring where incoming commands are stored
Serial.println(commandStr);

//==============================================

if (client.available())
{
char c = client.read();
commandStr+=c;//and ands them to the commands String
startdata=1;
Serial.print(c);

if (c == ‘a’)
{
digitalWrite(lamp3,HIGH);
digitalWrite(lamp2,HIGH);
}
if (c ==’b’)
{
digitalWrite(lamp3,LOW);
digitalWrite(lamp2,LOW);

}
//client.print(olah);
//client.print(“|”);
//client.print(olah1);
}

if (startdata==1)
{
client.print(“|”);
client.print(suhu);
client.print(“|”);
client.print(t);
client.print(“|”);
delay(100);
//client.println(“c”);
}

if (suhu <= 32 && t < 32)
{
digitalWrite(pemanas,HIGH);
digitalWrite(kipas,LOW);
Serial.println(“Suhu kurang dari 32 C pemanas menyala”);
Serial.println(” “);
}
else if (suhu > 32 && t > 32)
{
digitalWrite(kipas,HIGH) ;
digitalWrite(pemanas,LOW);
Serial.println(“Suhu lebih dari 32 C kipas menyala”);
Serial.println(” “);
}
else if (suhu >= 32 && t == 32)
{
Serial.println(“Suhu gudang padi normal”);
digitalWrite(kipas,LOW) ;
digitalWrite(pemanas,LOW);
}
Serial.println(“”);
Serial.println(“PLAN INI KITA JAGA SUHU DIDALAM KONSTAN 32 Celcius”);
Serial.println(“”);

}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Google

You are commenting using your Google account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s