I am to use the DHT11 temperature and humidity sensor to measure and display the temperature and humidity using an LCD (i2c) screen. A momentary push-button (not a switch) must be used to read sensor, i.e. the temperature and humidity values are read every time the button is pressed. In the context of environmental monitoring and weather conditions, I am to include another indicator using RGB LED to show if conditions are bad, fair or good depending on the recorded values, i.e. change the color of LED based on the temperature/humidity levels.
This is my code for the DHT11 and the LCD including external libraries (at this point i cannot code without the libraries) :
#include <SimpleDHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// for DHT11,
// VCC: 5V or 3V
// GND: GND
// DATA: 2
int pinDHT11 = 2;
SimpleDHT11 dht11(pinDHT11);
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(115200);
}
void loop() {
Serial.println("=================================");
Serial.println("Sample DHT11...");
byte temperature = 0;
byte humidity = 0;
int err = SimpleDHTErrSuccess;
if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("Read DHT11 failed, err="); Serial.println(err);delay(1000);
return;
}
lcd.begin();
lcd.backlight();
lcd.print("tempature "); lcd.print((int)temperature);
lcd.setCursor(0, 1);
lcd.print("humidity ");
lcd.print((int)humidity);
delay(1000);
}
I need help to (1) incorporate all the elements into the code, (2) write the code without external libraries for the DHT11 and LCD.
Thanks!