2

I just bought the sensor DHT11 and trying to test it with the library code provided by the IDE, but I always get the same error on .read() . Code -2

/*####################################################################
FILE: dht11_functions.pde - DHT11 Usage Demo.
VERSION: 2S0A

PURPOSE: Measure and return temperature & Humidity. Additionally provides conversions.

LICENSE: GPL v3 (http://www.gnu.org/licenses/gpl.html)
GET UPDATES: https://www.virtuabotix.com/

  --##--##--##--##--##--##--##--##--##--##--
  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##
  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##
  | ##  ##  ##  ##  ##  ##  ##  ##  ##  ## |
  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##
  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##
  | ##  ##  ##  ##  ##  ##  ##  ##  ##  ## |
  ##  ##  ##  ## DHT11 SENSOR ##  ##  ##  ##
  ##  ##  ##  ##  ##FRONT ##  ##  ##  ##  ##
  | ##  ##  ##  ##  ##  ##  ##  ##  ##  ## |
  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##
  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##
  | ##  ##  ##  ##  ##  ##  ##  ##  ##  ## |
  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##
  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##
  --##--##--##--##--##--##--##--##--##--##--
      ||       ||          || (Not    ||
      ||       ||          || Used)   ||
    VDD(5V)   Readout(I/O)          Ground

HISTORY:
Joseph Dattilo (Virtuabotix LLC) - Version 2S0A (27 May 12)
-Rewritten to with more powerful Versalino functionality
Joseph Dattilo (Virtuabotix LLC) - Version 0.4.5 (11/11/11)
-Made Library Arduino 1.0 Compatible
Joseph Dattilo (Virtuabotix LLC) - Version 0.4.0 (06/11/11)
-Fixed bugs (squish)
Mod by Rob Tillaart - Version 0.3 (28/03/2011)
Mod by SimKard - Version 0.2 (24/11/2010)
George Hadjikyriacou - Original version (??)
#######################################################################*/


#include <dht11.h>

dht11 DHT11;

void setup()
{
    DHT11.attach(2);
    Serial.begin(9600);
    Serial.println("DHT11 TEST PROGRAM ");
    Serial.print("LIBRARY VERSION: ");
    Serial.println(DHT11LIB_VERSION);
}

void loop()
{
    Serial.println("\n");

    int chk = DHT11.read();

    Serial.print("Read sensor: ");
    switch (chk)
    {
        case 0: Serial.println("OK"); break;
        case -1: Serial.println("Checksum error"); break;
        case -2: Serial.println("Time out error"); break;
        default: Serial.println("Unknown error"); break;
    }

    Serial.print("Humidity (%): ");
    Serial.println((float)DHT11.humidity, DEC);

    Serial.print("Temperature (°C): ");
    Serial.println((float)DHT11.temperature, DEC);

    Serial.print("Temperature (°F): ");
    Serial.println(DHT11.fahrenheit(), DEC);

    Serial.print("Temperature (°K): ");
    Serial.println(DHT11.kelvin(), DEC);

    Serial.print("Dew Point (°C): ");
    Serial.println(DHT11.dewPoint(), DEC);

    Serial.print("Dew PointFast (°C): ");
    Serial.println(DHT11.dewPointFast(), DEC);

    delay(2000);
}

And this is my ouput:

DHT11 TEST PROGRAM 
LIBRARY VERSION: 2S0A


Read sensor: Time out error
Humidity (%): 0.0000000000
Temperature (°C): 0.0000000000
Temperature (°F): 32.0000000000
Temperature (°K): 273.1499938964
Dew Point (°C): nan
Dew PointFast (°C): nan


Read sensor: Time out error
Humidity (%): 0.0000000000
Temperature (°C): 0.0000000000
Temperature (°F): 32.0000000000
Temperature (°K): 273.1499938964
Dew Point (°C): nan
Dew PointFast (°C): nan

The wiring:

-left pin: 5v

-right pin: gnd

-middle pin: 5v - digital2 - through 10kO resistor

enter image description here enter image description here

UPDATED: I found a library that works. I also changed the wiring because I found out the sainsmart dht11 switches the pins:

-left: signal with 10kO and to 5v

-middle: 5v

-right: GND

Now just a question. What is the difference between these two dht11 sensors. Dht11 basic dht11 with board

The one from sainsmart has a piece of circuit I don't know what it is.(I have a lack on electronics I try to fix step by step...)

It is a resitor, capacitor? it says 103.

How does this affect to the wiring?

  • In the code you linked, it says that you are reading pin 2 for input, but on your image, your wire is in pin 3. – Djensen Jan 20 '15 at 14:54
  • Hi, thanks for the answer. You are right. It was a problem in the wiring. After fixing it I was still getting errors. The problem was the library version, that was giving some problems with read response for dht11 sensors – blfuentes Jan 21 '15 at 7:38
2

The DHT11 sensor is available as-is and integrated on a break-out board. The break-out board shows following differences:

  • the order of PINs is changed, e.g. in one version: 1 -> signal, 2 -> +, 3 -> GND (left-to-right, pins down, looking at the front)
  • the unused pin is not connected
  • the board already has a 10 KOhm pull-up resistor connected

Thus, when you have a DHT11 on a break-out board you have to adjust schematics that use it as-is - e.g. in this example you have to remove the external pull-up resistor and connect the pins in the correct order.

Be aware that there may be different versions of DHT11 breakout boards available - i.e. ones where the order of pins is different. You can look out for PIN markings like S (-> signal) and - (-> GND). Also, you can look at both sides of the breakout board to trace the connections.

The resistor usually comes as SMD on such a board - and if it has a marking it uses a special code. For example, 103 means 10 * 10^3 Ohm, i.e. 10 KOhm.

The adafruit DHT library comes with an example sketch that prints the sensor values over serial.

0

It seems you wiring is ok, although I think you already have pull-up resistor on breakout board (look for a small 103 resistor).

Maybe you can try another library for DHT? I have used one made by adafruit (https://github.com/adafruit/DHT-sensor-library) and everything worked just fine.

Regards, Ian

  • Thank you for the answer, but it didn't work. I tried with and without resistor(I saw the 103 in the dht11's board). Also tried with the adafruit library and then I get the "Failed to read from DHT sensor!" error. I debugged the example and readHumidity readTemperature get errors on reading. Maybe my sensor is broken. I ordered a new one to check... – blfuentes Oct 21 '14 at 5:34
  • The DHT11 board + sensor already has the resistor. I use those with arduino directly, no extra components required. – vlad b. Aug 27 '15 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.