2013-08-28 07:57:45 -04:00
|
|
|
//
|
|
|
|
// FILE: dht_test.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
2014-10-23 10:15:26 -04:00
|
|
|
// VERSION: 0.1.08
|
2013-08-28 07:57:45 -04:00
|
|
|
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
|
|
|
|
// URL: http://arduino.cc/playground/Main/DHTLib
|
|
|
|
//
|
|
|
|
// Released to the public domain
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <dht.h>
|
|
|
|
|
|
|
|
dht DHT;
|
|
|
|
|
|
|
|
#define DHT11_PIN 4
|
2013-09-29 06:35:28 -04:00
|
|
|
#define DHT21_PIN 5
|
|
|
|
#define DHT22_PIN 6
|
2013-08-28 07:57:45 -04:00
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println("DHT TEST PROGRAM ");
|
|
|
|
Serial.print("LIBRARY VERSION: ");
|
|
|
|
Serial.println(DHT_LIB_VERSION);
|
|
|
|
Serial.println();
|
|
|
|
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
// READ DATA
|
|
|
|
Serial.print("DHT22, \t");
|
|
|
|
int chk = DHT.read22(DHT22_PIN);
|
|
|
|
switch (chk)
|
|
|
|
{
|
|
|
|
case DHTLIB_OK:
|
|
|
|
Serial.print("OK,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_CHECKSUM:
|
|
|
|
Serial.print("Checksum error,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_TIMEOUT:
|
|
|
|
Serial.print("Time out error,\t");
|
|
|
|
break;
|
2014-10-23 10:15:26 -04:00
|
|
|
case DHTLIB_ERROR_CONNECT:
|
|
|
|
Serial.print("Connect error,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_ACK_L:
|
|
|
|
Serial.print("Ack Low error,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_ACK_H:
|
|
|
|
Serial.print("Ack High error,\t");
|
|
|
|
break;
|
2013-08-28 07:57:45 -04:00
|
|
|
default:
|
|
|
|
Serial.print("Unknown error,\t");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// DISPLAY DATA
|
|
|
|
Serial.print(DHT.humidity, 1);
|
|
|
|
Serial.print(",\t");
|
|
|
|
Serial.println(DHT.temperature, 1);
|
|
|
|
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
|
|
|
|
// READ DATA
|
|
|
|
Serial.print("DHT21, \t");
|
2013-09-29 06:35:28 -04:00
|
|
|
chk = DHT.read21(DHT21_PIN);
|
2013-08-28 07:57:45 -04:00
|
|
|
switch (chk)
|
|
|
|
{
|
|
|
|
case DHTLIB_OK:
|
|
|
|
Serial.print("OK,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_CHECKSUM:
|
|
|
|
Serial.print("Checksum error,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_TIMEOUT:
|
|
|
|
Serial.print("Time out error,\t");
|
|
|
|
break;
|
2014-10-23 10:15:26 -04:00
|
|
|
case DHTLIB_ERROR_CONNECT:
|
|
|
|
Serial.print("Connect error,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_ACK_L:
|
|
|
|
Serial.print("Ack Low error,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_ACK_H:
|
|
|
|
Serial.print("Ack High error,\t");
|
|
|
|
break;
|
2013-08-28 07:57:45 -04:00
|
|
|
default:
|
|
|
|
Serial.print("Unknown error,\t");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// DISPLAY DATA
|
|
|
|
Serial.print(DHT.humidity, 1);
|
|
|
|
Serial.print(",\t");
|
|
|
|
Serial.println(DHT.temperature, 1);
|
|
|
|
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
// READ DATA
|
|
|
|
Serial.print("DHT11, \t");
|
|
|
|
chk = DHT.read11(DHT11_PIN);
|
|
|
|
switch (chk)
|
|
|
|
{
|
|
|
|
case DHTLIB_OK:
|
|
|
|
Serial.print("OK,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_CHECKSUM:
|
|
|
|
Serial.print("Checksum error,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_TIMEOUT:
|
|
|
|
Serial.print("Time out error,\t");
|
|
|
|
break;
|
2014-10-23 10:15:26 -04:00
|
|
|
case DHTLIB_ERROR_CONNECT:
|
|
|
|
Serial.print("Connect error,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_ACK_L:
|
|
|
|
Serial.print("Ack Low error,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_ACK_H:
|
|
|
|
Serial.print("Ack High error,\t");
|
|
|
|
break;
|
2013-08-28 07:57:45 -04:00
|
|
|
default:
|
|
|
|
Serial.print("Unknown error,\t");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// DISPLAY DATA
|
|
|
|
Serial.print(DHT.humidity,1);
|
|
|
|
Serial.print(",\t");
|
|
|
|
Serial.println(DHT.temperature,1);
|
|
|
|
|
|
|
|
delay(1000);
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// END OF FILE
|
|
|
|
//
|