1

How to know if Temperature and humidity sensor DHT11 is working. I am trying to read data from DHT11, when I read data using Adafruit library it just keeps waiting for data. When I tried using https://github.com/szazo/DHT11_Python it gives me error code 1, which means missing data.

Please help me out.

3

I suggest you try with my example DHTXX code.

Extract the zip to a directory and then compile/link with

gcc -Wall -pthread -o DHTXXD test_DHTXXD.c DHTXXD.c -lpigpiod_if2

The start the daemon

sudo pigpiod

and run the code

/DHTXXD -g4 # assuming you are using Broadcom GPIO 4

pigpio is pre-installed on recent Raspbians, otherwise try sudo apt-get install pigpio or see http://abyz.me.uk/rpi/pigpio/download.html

3
  • Thanks for the suggestion but my code suddenly started to work, dont know why it was not working earlier. But my question is still not answered because what you have provided is code to receive data as humidity and temperature. I was hoping there would be some way other than this to check the sensor. Jun 25 '16 at 17:45
  • @ShubhamTayal Check in what sense? It's a digital sensor. You send a trigger and it sends a series of pulses in response.
    – joan
    Jun 25 '16 at 18:51
  • @joan Please let me thank you for that sample code, sir. Better than any other I tried; better than what I did so far; to-the-point frontend code. May 16 '17 at 7:13
0

And with that, 3 days latter - dead. More research on the web says that the DTH22 will sometimes hang and the solution is to power cycle. From a python code I had run across they had used another GPIO pin to power the chip and not pin 1 (3v3). Original wiring was pins 1, 7, 9. I've moved the 3v to pin 11 GPIO-17.

Side story: My RasPi controls my hydroponic greenhouse - heating/cooling, watering, feeding a DB (graph of temps etc). Depending on the temperature the Pi sends an X10 signal to On/Off a 1500W space heater or to run a wet wall and exhaust fan. So: A) imperative that temperature reading be available at all time - fear of freezing or over heat, and B) I'm anal.

So, once a minute gtemp.php runs. (among other things) exec("DHTXXD", $th); then if temp = 32 and humd = 0 (@$!#@ sensor is hung) then:

system("gpio -g mode 17 out"); system("gpio -g write 17 0"); system("gpio -g write 17 1"); rerun DHTXXD (and send me an txt saying so)

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.