// Example testing sketch for various DHT humidity/temperature sensors
// Tech at Home
#include "DHT.h"
#define DHTPIN 10 // what pin we're connected to
// Uncomment whatever type you're using!
// #define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
int ldrPin = A3;
int led = 7;
int threshold = 70;
void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
pinMode(led, OUTPUT);
dht.begin();
lcd.begin(16,2);
// Turn on the blacklight and print a message.
lcd.backlight();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
float hif = dht.computeHeatIndex(f, h);
float hic = dht.computeHeatIndex(t, h, false);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
int data = analogRead(ldrPin);
Serial.print("Light Sensor ");
Serial.print("Value = ");
Serial.print(data);
Serial.println("");
lcd.clear();
lcd.setCursor(0, 0); // Set the cursor to the first column of the first row
lcd.print("Temp: ");
lcd.print(t);
lcd.print(" *C");
delay(2500);
lcd.clear();
lcd.print("Humidity: ");
lcd.print(h);
lcd.print(" %");
delay(2500);
lcd.clear();
lcd.print("Heat Index: ");
lcd.print(hic);
lcd.print(" %");
delay(2500);
lcd.clear();
lcd.print("Ldr: ");
lcd.print(data);
lcd.print(" %");
delay(500);
}