#include <LiquidCrystal_I2C.h>
#include <DHT.h>
uint8_t dot[] = {0x0e, 0x0A, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00};
LiquidCrystal_I2C lcd(0x27, 20, 4); // Update address
DHT dht(32, DHT22);
void setup() {
Serial.begin(115200);
Serial.println("Hello Lab 3");
dht.begin();
lcd.init();
lcd.backlight();
lcd.createChar(0, dot); // Use slot 0
}
void loop() {
float h = dht.readHumidity(); // Relative humidity
float c = dht.readTemperature(); // Celsius
float f = dht.readTemperature(true); // Fahrenheit
// Check if any reads failed and try again
if (isnan(h) || isnan(c) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.printf("Temp=%.1f deg C %.1f deg F; RH=%.1f", c, f, h);
Serial.printf("%\n");
lcd.setCursor(0, 0);
lcd.print("RH="); lcd.print(h, 1); lcd.print("%");
lcd.setCursor(0, 1);
lcd.print("Temp="); lcd.print(c, 2); lcd.write(0); lcd.print("C");
lcd.setCursor(0, 2);
lcd.print("Temp="); lcd.print(f, 1); lcd.write(0); lcd.print("F");
if(f >= 90) {
lcd.setCursor(0,3);
lcd.print("Temp >= 90"); lcd.print(f, 1); lcd.write(0); lcd.print("F App");
}
if(f < 90) {
lcd.setCursor(0,3);
lcd.print("Temp >= 90"); lcd.print(f, 1); lcd.write(0); lcd.print("F Disp");
}
delay(4000);
}
Practical Test 1: Question 3 (Friday)
1. Print temperatures and humidity on the serial port
2. Print humidity on the 1st row of the LCD
3. Print temperature with with °C on the 2nd row of the LCD
4. Print temperature with the with °F on the 3rd row of the LCD
5. Alarm processing on 90 °F on the 4th row of the LCD