2 // FILE: dht11_test1.pde
3 // PURPOSE: DHT11 library test sketch for Arduino
6 //Celsius to Fahrenheit conversion
7 double Fahrenheit(double celsius)
9 return 1.8 * celsius + 32;
12 // fast integer version with rounding
13 //int Celcius2Fahrenheit(int celcius)
15 // return (celsius * 18 + 5)/10 + 32;
19 //Celsius to Kelvin conversion
20 double Kelvin(double celsius)
22 return celsius + 273.15;
25 // dewPoint function NOAA
26 // reference: http://wahiduddin.net/calc/density_algorithms.htm
27 double dewPoint(double celsius, double humidity)
29 double RATIO = 373.15 / (273.15 + celsius); // RATIO was originally named A0, possibly confusing in Arduino context
30 double SUM = -7.90298 * (RATIO - 1);
31 SUM += 5.02808 * log10(RATIO);
32 SUM += -1.3816e-7 * (pow(10, (11.344 * (1 - 1/RATIO ))) - 1) ;
33 SUM += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ;
34 SUM += log10(1013.246);
35 double VP = pow(10, SUM - 3) * humidity;
36 double T = log(VP/0.61078); // temp var
37 return (241.88 * T) / (17.558 - T);
40 // delta max = 0.6544 wrt dewPoint()
41 // 5x faster than dewPoint()
42 // reference: http://en.wikipedia.org/wiki/Dew_point
43 double dewPointFast(double celsius, double humidity)
47 double temp = (a * celsius) / (b + celsius) + log(humidity/100);
48 double Td = (b * temp) / (a - temp);
60 #include <DallasTemperature.h>
62 // Data wire is plugged into port 2 on the Arduino
63 #define ONE_WIRE_BUS 10
65 // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
66 OneWire oneWire(ONE_WIRE_BUS);
68 // Pass our oneWire reference to Dallas Temperature.
69 DallasTemperature sensors(&oneWire);
74 Serial.println("DHT11 TEST PROGRAM ");
75 Serial.print("LIBRARY VERSION: ");
76 Serial.println(DHT11LIB_VERSION);
85 int chk = DHT11.read(DHT11PIN);
87 Serial.print("DHT11 Read sensor: ");
93 case DHTLIB_ERROR_CHECKSUM:
94 Serial.println("Checksum error");
96 case DHTLIB_ERROR_TIMEOUT:
97 Serial.println("Time out error");
100 Serial.println("Unknown error");
104 Serial.print("Humidity (%): ");
105 Serial.println((float)DHT11.humidity, 2);
107 Serial.print("Temperature (oC): ");
108 Serial.println((float)DHT11.temperature, 2);
110 Serial.print("Temperature (oF): ");
111 Serial.println(Fahrenheit(DHT11.temperature), 2);
113 Serial.print("Temperature (K): ");
114 Serial.println(Kelvin(DHT11.temperature), 2);
116 Serial.print("Dew Point (oC): ");
117 Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));
119 Serial.print("Dew PointFast (oC): ");
120 Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));
123 Serial.print("DS18B20 Requesting temperatures...");
124 sensors.requestTemperatures(); // Send the command to get temperatures
125 Serial.println("DONE");
127 sensors.requestTemperatures(); // Send the command to get temperatures
128 Serial.print("Temperature for the device 1 (index 0) is: ");
129 Serial.println(sensors.getTempCByIndex(0));