// LCD1602 to Arduino Uno connection example
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
int buzzerPin = 6;
void setup() {
lcd.begin(16, 2);
// you can now interact with the LCD, e.g.:
lcd.print(F("DHT22 example!"));
Serial.begin(115200);
dht.begin();
pinMode(buzzerPin, OUTPUT);
}
void loop() {
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// Check if any reads failed and exit early (to try again).
if (isnan(temperature) || isnan(humidity)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
lcd.print(F("Humidity: "));
lcd.print(humidity);
lcd.print(F("% Temperature: "));
lcd.print(temperature);
lcd.println(F("°C "));
delay(2000);
// Wait a few seconds between measurements.
if(temperature>40){
delay(2000);
tone(buzzerPin, 31);
}
// ...
}