#include<LiquidCrystal.h> // Indicate that the program includes the LiquidCrystal Library
int rs = 7; // create an integer variable "rs" connected to pin 7
int en = 8; // create an integer variable "en" connected to pin 8
int d4 = 9; // create an integer variable "d4" connected to pin 9
int d5 = 10; // create an integer variable "d5" connected to pin 10
int d6 = 11; // create an integer variable "d6" connected to pin 11
int d7 = 12; // create an integer variable "d7" connected to pin 12
LiquidCrystal LCD(rs, en, d4, d5, d6, d7); // Summarizes the parameters covered by the LiquidCrystal program
#include <DHT11.h> // Indicate that the program includes the DHT11 Library
DHT11 dht11(2); // declares that the DHT11 temperature and humidity sensors are present in the Arduino
float humidity; // Declares that the humidity may contain decimal values
float temperature; // Declares that the temperature may contain decimal values
void setup() {
// put your setup code here, to run once:
LCD.begin(16,2); // Initializes the LCD
}
void loop() {
// put your main code here, to run repeatedly:
humidity = dht11.readHumidity(); // Read the humidity level from the DHT11
temperature = dht11.readTemperature(); // Read the temperature from DHT11
LCD.setCursor(0,0); // Sets the cursor position
if (humidity != DHT11::ERROR_CHECKSUM && humidity != DHT11::ERROR_TIMEOUT){ // Sets a condition for the humidity
LCD.print("humidity: "); // Display the text in the LCD
LCD.print(humidity); // Display the text in the LCD
LCD.print("%"); //Display the text in the LCD
}
else{
LCD.print(DHT11::getErrorString(humidity));
}
LCD.setCursor(0,1);
if (temperature != DHT11::ERROR_CHECKSUM && humidity != DHT11::ERROR_TIMEOUT){ // Sets a condition for the temperature
LCD.print("Temperature: "); // Display the text in the LCD
LCD.print(temperature); // Display the text in the LCD
LCD.print(" C"); // Display the text in the LCD
}
else{ // Set an alternative for when the temperature fails to meet the condition
LCD.print(DHT11::getErrorString(temperature));
}
delay(2000); // Declare the program to pause
}