int temp1 = A0;
int temp2 = A1;
int temp3 = A2;
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
#include "DHT.h"
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#define DHTPIN 2
#define DHTTYPE DHT22
Servo myservo1;
LiquidCrystal_I2C lcd(0x27,20,4);
int potpin = 0;
int val;
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
lcd.init();
pinMode(temp1, INPUT);
pinMode(temp2, INPUT);
pinMode(temp3, INPUT);
dht.begin();
myservo1.attach(9);
lcd.backlight();
}
void loop() {
delay(2000);
// DHT
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t)){
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
// TMPs
int tempv1 = analogRead(A0);
float tempc1 = 1 / (log(1 / (1023. / tempv1 - 1)) / BETA + 1.0 / 298.15) - 273.15;
int tempv2 = analogRead(A1);
float tempc2 = 1 / (log(1 / (1023. / tempv2 - 1)) / BETA + 1.0 / 298.15) - 273.15;
int tempv3 = analogRead(A2);
float tempc3 = 1 / (log(1 / (1023. / tempv3 - 1)) / BETA + 1.0 / 298.15) - 273.15;
/*
Serial.print("Temperature 1: ");
Serial.print(tempc1,1);
Serial.print(" C ");
Serial.print("Temperature 2: ");
Serial.print(tempc2,1);
Serial.print(" C ");
Serial.print("Temperature 3: ");
Serial.print(tempc3,1);
Serial.println(" C");
Serial.print(F("Humidity: "));
Serial.print(h,1);
Serial.print(F("% Temperature: "));
Serial.print(t,1);
Serial.println(F("°C "));
*/
//lcd
lcd.setCursor(0,0);
lcd.print("T1:");
lcd.print(tempc1,1);
lcd.print(" C ");
lcd.print("T2:");
lcd.print(tempc2,1);
lcd.print(" C ");
lcd.setCursor(0,1);
lcd.print("T3:");
lcd.print(tempc3,1);
lcd.println(" C");
lcd.setCursor(0,2);
lcd.print("RH:");
lcd.print(h,1);
lcd.print(" % ");
lcd.print("T:");
lcd.print(t);
lcd.print(" C");
//conditions
if ((h<=90 && h>=70) && (t<=28 && t>=22)) {
myservo1.write(0);
lcd.setCursor(0,3);
lcd.print("OPTIMAL");
}
if ((h>90) && (t<=28 && t>=22)) {
myservo1.write(180);
lcd.setCursor(0,3);
lcd.print("RH HIGH");
}
if ((h<70) && (t<=28 && t>=22)) {
myservo1.write(90);
lcd.setCursor(0,3);
lcd.print("RH LOW");
}
if ((h<=90 && h>=70) && (t<22)) {
myservo1.write(90);
lcd.setCursor(0,3);
lcd.print("TEMP LOW");
}
if ((h<=90 && h>=70) && (t>28)) {
myservo1.write(180);
lcd.setCursor(0,3);
lcd.print("TEMP HIGH");
}
if ((h>90) && (t>28)) {
myservo1.write(30);
lcd.setCursor(0,3);
lcd.print("CRITICAL");
}
}