1
2
3
4#include <dht_nonblocking.h>
5#define DHT_SENSOR_TYPE DHT_TYPE_11
6#include <LiquidCrystal.h>
7
8static const int DHT_SENSOR_PIN = 2;
9DHT_nonblocking dht_sensor( DHT_SENSOR_PIN, DHT_SENSOR_TYPE );
10
11int tempPin = 0;
12
13
14LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
15
16
17void setup()
18{
19 Serial.begin(9600);
20
21 lcd.begin(16, 2);
22}
23
24static bool measure_environment( float *temperature, float *humidity )
25{
26 static unsigned long measurement_timestamp = millis( );
27
28
29 if( millis( ) - measurement_timestamp > 10000ul )
30 {
31 if( dht_sensor.measure( temperature, humidity ) == true )
32 {
33 measurement_timestamp = millis( );
34 return( true );
35 }
36 }
37
38 return( false );
39}
40
41void loop()
42{
43
44 int tempReading = analogRead(tempPin);
45 double tempK = log(10000.0 * ((1024.0 / tempReading - 1)));
46 tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK );
47 float tempC = tempK - 273.15;
48 float tempF = (tempC * 9.0)/ 5.0 + 32.0;
49
50
51 float temperature;
52 float humidity;
53 if( measure_environment( &temperature, &humidity ) == true )
54
55 {
56
57 Serial.print( "DH11 " );
58 Serial.print( temperature, 1 );
59 Serial.print(" C, " );
60 Serial.print( humidity, 1 );
61 Serial.print(" %; Therm ");
62 Serial.print(tempC);
63 Serial.print(" C, ");
64 Serial.print(tempF);
65 Serial.print(" F\
66");
67
68
69
70
71 lcd.setCursor(0, 0);
72 lcd.print("Therm C ");
73 lcd.setCursor(7, 0);
74 lcd.print(tempC);
75
76
77 lcd.setCursor(0, 2);
78 lcd.print("DH11 C %");
79 lcd.setCursor(5, 2);
80 lcd.print(temperature,1);
81
82
83 lcd.setCursor(11, 2);
84 lcd.print(humidity,1);
85
86 delay(500);
87 }
88}
89