#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <DHT.h>
#define DHT_PIN 2
#define DHT_TYPE DHT22
#define LCD_ADDRESS 0x27
#define LCD_COL 16
#define LCD_ROW 2
#define RED_LED_PIN 13
#define BLUE_LED_PIN 12
#define YELLOW_LED_PIN 8
enum Climate {HOT = 40, NORMAL = 30, COLD = 20};
// sensor struct objects
LiquidCrystal_I2C lcd(LCD_ADDRESS, LCD_ROW, LCD_COL);
DHT dht(DHT_PIN, DHT_TYPE);
void setup() {
// put your setup code here, to run once:
pinMode(RED_LED_PIN, OUTPUT);
pinMode(BLUE_LED_PIN, OUTPUT);
pinMode(YELLOW_LED_PIN, OUTPUT);
Serial.begin(9600);
dht.begin();
lcd.init();
lcd.backlight();
lcd.setCursor(LCD_COL - 2, 0);
lcd.print("\xDF");
lcd.print("C");
lcd.setCursor(LCD_COL - 1, 1);
lcd.print("%");
}
void loop() {
// put your main code here, to run repeatedly:
float temp = dht.readTemperature();
float humid = dht.readHumidity();
lcd.setCursor(0, 0);
lcd.print(temp);
lcd.setCursor(0, 1);
lcd.print(humid);
if (temp <= Climate::COLD) {
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(BLUE_LED_PIN, HIGH);
digitalWrite(YELLOW_LED_PIN, LOW);
} else if (temp >= Climate::NORMAL && temp < Climate::HOT) {
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(BLUE_LED_PIN, LOW);
digitalWrite(YELLOW_LED_PIN, HIGH);
} else if (temp >= Climate::HOT ) {
digitalWrite(RED_LED_PIN, HIGH);
digitalWrite(BLUE_LED_PIN, LOW);
digitalWrite(YELLOW_LED_PIN, LOW);
} else {
}
delay(2250);
}