// DHT Temperature & Humidity Sensor
// DHT Temperature & Humidity Sensor
// Unified Sensor Library Example
// Written by Tony DiCola for Adafruit Industries
// Released under an MIT license.
// Depends on the following Arduino libraries:
// - Adafruit Unified Sensor Library: https://github.com/adafruit/Adafruit_Sensor
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
#include<LiquidCrystal.h> // include the LCD library code:
#include<Adafruit_Sensor.h>
#include<DHT.h>
#include<DHT_U.h>
// initialize the library with the numbers of the interface pins
//01/07/17 gfp: my setup is:
//LCD pin name RS EN DB4 DB5 DB6 DB7
//Arduino pin # 7 6 5 4 3 2
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
#define DHTPIN 8 // Pin which is connected to the DHT sensor.
// Uncomment the type of sensor in use:
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// See guide for details on sensor wiring and usage:
// https://learn.adafruit.com/dht/overview
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;
double tempF = 0; //holds temperature returned from DHT22
double RelHumPct = 0; //holds relative humidity returned from DHT22
void setup() {
Serial.begin(115200);
// Initialize Temp/Humidity sensor.
dht.begin();
Serial.println("DHTxx Unified Sensor Example");
// Print temperature sensor details.
sensor_t sensor;
dht.temperature().getSensor(&sensor);
Serial.println("------------------------------------");
Serial.println("Temperature");
Serial.print("Sensor: "); Serial.println(sensor.name);
Serial.print("Driver Ver: "); Serial.println(sensor.version);
Serial.print("Unique ID: "); Serial.println(sensor.sensor_id);
Serial.print("Max Value: "); Serial.print(sensor.max_value); Serial.println(" *C");
Serial.print("Min Value: "); Serial.print(sensor.min_value); Serial.println(" *C");
Serial.print("Resolution: "); Serial.print(sensor.resolution); Serial.println(" *C");
Serial.println("------------------------------------");
// Print humidity sensor details.
dht.humidity().getSensor(&sensor);
Serial.println("------------------------------------");
Serial.println("Humidity");
Serial.print("Sensor: "); Serial.println(sensor.name);
Serial.print("Driver Ver: "); Serial.println(sensor.version);
Serial.print("Unique ID: "); Serial.println(sensor.sensor_id);
Serial.print("Max Value: "); Serial.print(sensor.max_value); Serial.println("%");
Serial.print("Min Value: "); Serial.print(sensor.min_value); Serial.println("%");
Serial.print("Resolution: "); Serial.print(sensor.resolution); Serial.println("%");
Serial.println("------------------------------------");
// Set delay between sensor readings based on sensor details.
delayMS = sensor.min_delay / 1000;
// set up the LCD's number of columns and rows:
//lcd.begin(16, 2);
lcd.begin(8, 2);
// Print a message to the LCD.
//lcd.print("hello, world!");
//String str = "Temp: ";
//str += "43";
//lcd.print(str);
}
void loop()
{
// Delay between measurements.
delay(delayMS);
// Get temperature event and print its value.
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature))
{
Serial.println("Error reading temperature!");
}
else //good data
{
//12/07/16 temp is in C - convert to F
tempF = event.temperature * (9.0 / 5.0) + 32;
Serial.print("Temp/Humidity: ");
Serial.print(tempF);
Serial.print(" F\t");
}
// Get humidity event and print its value.
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity))
{
Serial.println("Error reading humidity!");
}
else //good data
{
RelHumPct = event.relative_humidity;
//Serial.print(event.relative_humidity);
Serial.print(RelHumPct);
Serial.println(" %");
}
//// set the LCD cursor to column 0, line 1
//// (note: line 1 is the second row, since counting begins with 0):
//lcd.setCursor(0, 1);
//// print the number of seconds since reset:
//lcd.print(millis() / 1000);
//set the LCD cursor to column 0, line 0 (1st line)
lcd.setCursor(0, 0);
String str = "T: ";
str += String(tempF,1);
lcd.print(str);
//set the LCD cursor to column 0, line 1 (2nd line)
lcd.setCursor(0, 1);
str = "RH:";
str += String(RelHumPct,0);
lcd.print(str);
}