I have bought the DHT11 sensor, but when I use the code given me in the examples, it comes full of errors.
I will leave the code given to me and the errors, and I would like someone to help and teach me more about it, thanks in advance ^^
Example code:
//
// FILE: dht_test.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.07
// 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
#define DHT21_PIN 5
#define DHT22_PIN 6
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;
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");
chk = DHT.read21(DHT21_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;
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;
default:
Serial.print("Unknown error,\t");
break;
}
// DISPLAY DATA
Serial.print(DHT.humidity,1);
Serial.print(",\t");
Serial.println(DHT.temperature,1);
delay(1000);
}
Errors:
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.6 (Windows NT (unknown)), Board: "TMinus1"
FLGSQRUHOKSCTUA-1.ino:13: error: 'dht' does not name a type
FLGSQRUHOKSCTUA-1.ino: In function 'void setup()':
FLGSQRUHOKSCTUA-1.ino:24: error: 'DHT_LIB_VERSION' was not declared in this scope
FLGSQRUHOKSCTUA-1.ino: In function 'void loop()':
FLGSQRUHOKSCTUA-1.ino:33: error: 'DHT' was not declared in this scope
FLGSQRUHOKSCTUA-1.ino:36: error: 'DHTLIB_OK' was not declared in this scope
FLGSQRUHOKSCTUA-1.ino:39: error: 'DHTLIB_ERROR_CHECKSUM' was not declared in this scope
FLGSQRUHOKSCTUA-1.ino:42: error: 'DHTLIB_ERROR_TIMEOUT' was not declared in this scope
FLGSQRUHOKSCTUA-1.ino:62: error: 'DHTLIB_OK' was not declared in this scope
FLGSQRUHOKSCTUA-1.ino:65: error: 'DHTLIB_ERROR_CHECKSUM' was not declared in this scope
FLGSQRUHOKSCTUA-1.ino:68: error: 'DHTLIB_ERROR_TIMEOUT' was not declared in this scope
FLGSQRUHOKSCTUA-1.ino:87: error: 'DHTLIB_OK' was not declared in this scope
FLGSQRUHOKSCTUA-1.ino:90: error: 'DHTLIB_ERROR_CHECKSUM' was not declared in this scope
FLGSQRUHOKSCTUA-1.ino:93: error: 'DHTLIB_ERROR_TIMEOUT' was not declared in this scope
FLGSQRUHOKSCTUA-1.ino:105: error: expected `}' at end of input
If there is someone willing to make a code and explain it for me, I would be very appreciated ![]()