#include "DHT.h"
DHT dht;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup()
{
lcd.begin();
Serial.begin(9600);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
Serial.println();
Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)");
lcd.setCursor(0, 1);
lcd.print("FAN : ");
dht.setup(2); // data pin 2
}
void loop()
{
delay(dht.getMinimumSamplingPeriod());
float humidity = dht.getHumidity();
long temperature = dht.getTemperature();
Serial.print(dht.getStatusString());
Serial.print("\tHumidity :");
Serial.print(humidity, 1);
Serial.print("\t\tTemp C:");
Serial.print(temperature, 1);
Serial.print("\t\tTemp F:");
Serial.println(dht.toFahrenheit(temperature), 1);
lcd.setCursor(0, 0);
lcd.print("Temperature");
lcd.setCursor(12, 0);
lcd.print(temperature);
lcd.setCursor(14, 0);
lcd.print(" C");
if (temperature >=25&& temperature <28 )
{
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
lcd.setCursor(0, 1);
lcd.print("FAN : 1 ");
}
if (temperature >=28&& temperature <31)
{
digitalWrite(4, LOW);
digitalWrite(3, LOW);
digitalWrite(5, HIGH);
lcd.setCursor(0, 1);
lcd.print("FAN : 2 ");
}
if (temperature >=31&& temperature <34)
{
digitalWrite(5, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
lcd.setCursor(0, 1);
lcd.print("FAN : 3 ");
}
if (temperature < 28)
{
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
lcd.setCursor(0, 1);
lcd.print("FAN : STOP");
}
else if (temperature >= 34)
{
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
lcd.setCursor(0, 1);
lcd.print("FAN : STOP");
}
delay(500);
}
ผิดตรงไหนครับ รันไม่ผ่านสักที่ ช่วยด้วยครับ
ช่วยหน่อยครับ
DHT dht;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup()
{
lcd.begin();
Serial.begin(9600);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
Serial.println();
Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)");
lcd.setCursor(0, 1);
lcd.print("FAN : ");
dht.setup(2); // data pin 2
}
void loop()
{
delay(dht.getMinimumSamplingPeriod());
float humidity = dht.getHumidity();
long temperature = dht.getTemperature();
Serial.print(dht.getStatusString());
Serial.print("\tHumidity :");
Serial.print(humidity, 1);
Serial.print("\t\tTemp C:");
Serial.print(temperature, 1);
Serial.print("\t\tTemp F:");
Serial.println(dht.toFahrenheit(temperature), 1);
lcd.setCursor(0, 0);
lcd.print("Temperature");
lcd.setCursor(12, 0);
lcd.print(temperature);
lcd.setCursor(14, 0);
lcd.print(" C");
if (temperature >=25&& temperature <28 )
{
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
lcd.setCursor(0, 1);
lcd.print("FAN : 1 ");
}
if (temperature >=28&& temperature <31)
{
digitalWrite(4, LOW);
digitalWrite(3, LOW);
digitalWrite(5, HIGH);
lcd.setCursor(0, 1);
lcd.print("FAN : 2 ");
}
if (temperature >=31&& temperature <34)
{
digitalWrite(5, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
lcd.setCursor(0, 1);
lcd.print("FAN : 3 ");
}
if (temperature < 28)
{
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
lcd.setCursor(0, 1);
lcd.print("FAN : STOP");
}
else if (temperature >= 34)
{
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
lcd.setCursor(0, 1);
lcd.print("FAN : STOP");
}
delay(500);
}
ผิดตรงไหนครับ รันไม่ผ่านสักที่ ช่วยด้วยครับ