Serial.print("Dew Point (°C): ");
Serial.println(DHT22.dewPoint(), DEC);
Serial.print("Dew PointFast (°C): ");
Serial.println(DHT22.dewPointFast(), DEC);
We see the output on the Arduino serial
monitor in Figure 10. Note that this runs the
serial port at 9600 baud.
Two DHT22 Sensors
Adding a second sensor is shown in Figures
11 and 12 in Fritzing breadboard and schematic
views. We connect the second sensor to the
Arduino pin 10 and make a couple of minor
changes in the code. We are now ready to go.
The following source code shows how
simple it is to add a sensor to a project when
you use a library. In the first example, we
created an instance of the dht22 class using
dht22 DHT22. For the example that uses two
sensors, we simply add two instances of the
class with:
dht22 DHT220;
dht22 DHT221;
■ FIGURE 13: DHT22 example with two sensors.
Next, we copy and paste some code as
shown in the listing. We’ll have two sensors
working in a matter of minutes:
#include <dht22.h>
■ FIGURE 14: Attic fan.
dht22 DHT220;
dht22 DHT221;
void setup()
{
DHT220.attach(10);
DHT221.attach(11);
Serial.begin(9600);
Serial.println("DHT22 TEST PROGRAM - two
sensors ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT22LIB_VERSION);
}
void loop()
{
Serial.println("\n");
int chk0 = DHT220.read();
Serial.print("Read sensor 0: ");
switch (chk0)
{
case 0: Serial.println("Sensor 0 OK");
break;
74 September 2013