2017-12-12 14:29:52 -05:00
|
|
|
//
|
|
|
|
// FILE: dht12_test.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
2021-01-29 06:31:58 -05:00
|
|
|
// VERSION: 0.2.0
|
2017-12-12 14:29:52 -05:00
|
|
|
// PURPOSE: DHT library test sketch for DHT12 && Arduino
|
2020-11-27 05:10:47 -05:00
|
|
|
// URL: https://github.com/RobTillaart/DHTstable
|
2017-12-12 14:29:52 -05:00
|
|
|
//
|
2020-11-27 05:10:47 -05:00
|
|
|
// HISTORY:
|
2021-01-29 06:31:58 -05:00
|
|
|
// 0.2.0 use getHumidity() and getTemperature()
|
2020-11-27 05:10:47 -05:00
|
|
|
// 0.1.1 add URL in header
|
2017-12-12 14:29:52 -05:00
|
|
|
|
|
|
|
#include <dht.h>
|
|
|
|
|
|
|
|
dht DHT;
|
|
|
|
|
|
|
|
#define DHT12_PIN 5
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.println(__FILE__);
|
2017-12-12 14:29:52 -05:00
|
|
|
Serial.print("LIBRARY VERSION: ");
|
|
|
|
Serial.println(DHT_LIB_VERSION);
|
|
|
|
Serial.println();
|
|
|
|
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
// READ DATA
|
|
|
|
Serial.print("DHT12, \t");
|
|
|
|
int chk = DHT.read12(DHT12_PIN);
|
|
|
|
switch (chk)
|
|
|
|
{
|
|
|
|
case DHTLIB_OK:
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print("OK,\t");
|
|
|
|
break;
|
2017-12-12 14:29:52 -05:00
|
|
|
case DHTLIB_ERROR_CHECKSUM:
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print("Checksum error,\t");
|
|
|
|
break;
|
2017-12-12 14:29:52 -05:00
|
|
|
case DHTLIB_ERROR_TIMEOUT:
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print("Time out error,\t");
|
|
|
|
break;
|
2017-12-12 14:29:52 -05:00
|
|
|
default:
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print("Unknown error,\t");
|
|
|
|
break;
|
2017-12-12 14:29:52 -05:00
|
|
|
}
|
|
|
|
// DISPLAY DATA
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(DHT.getHumidity(), 1);
|
2017-12-12 14:29:52 -05:00
|
|
|
Serial.print(",\t");
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.println(DHT.getTemperature(), 1);
|
2017-12-12 14:29:52 -05:00
|
|
|
|
|
|
|
delay(2000);
|
|
|
|
}
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2017-12-12 14:29:52 -05:00
|
|
|
// END OF FILE
|