Wednesday, January 25, 2012

Step Three: Interfacing RHT03 Temperature & Humidity Sensor

Since this project revolves around the temperature and humidity, this was the first component I wanted to test.

Browsing sparkfun's comments on the product, I was able to find a good starting point for this component on github:

nethoncho's Arduino DHT22 Library via GitHub

This library however is not Arduino 1.0 compatible. Thankfully there is a pull request with the necessary adjustments by user ringerc on January 15th (great timing!):
https://github.com/nethoncho/Arduino-DHT22/pull/2

You can download the complete commit that is 1.0 compatible from the following page:
https://github.com/ringerc/Arduino-DHT22/tree/f1c5b3ab1e6f274ec66ecee09df729224af1cf7d

Or using this direct link:
https://github.com/ringerc/Arduino-DHT22/zipball/f1c5b3ab1e6f274ec66ecee09df729224af1cf7d

After un-zipping, you want to drag the entire folder into your 'libraries' directory within the Arduino application.

Once in that directory, you can open the example sketch within the Arduino application.

Wiring the temperature sensor based on comments in the example sketch and sparkfun customer comments yields a steady stream of temperature / humidity data as shown:



From left to right pins 1,2,3,4:
1: Connect to 5v VCC
2: Connect to Pin 7 on the Arduino with a 4.7K resistor to 5v VCC (pull up)
3: Ground
4: Ground

Running the sketch referenced above we'll the temp/humidity readings:






Next, we want to modify this sketch to leverage the 7-segment display. That will come in the next post!

TLDR;

You want to interface with the RHT03 Sensor? Just use the library here to get a hello-world sketch, and wire up the sensor's pins as described above.

6 comments:

  1. Hey Eric, I've been working on a similar project with the same sensor, and have found your blog to be very helpful!

    I found the library for the sensor here, but complete Arduino 1.0 compatible library linked from this page had a bug in it that caused sync timeouts on most read attempts until I changed the retryCount on line 159 from 35 to 70.

    Can you explain why the resistor is necessary? I find that I get the same readings with or without the resistor, and have read from the comments on SparkFun's site that it's not needed, though I see it says otherwise in the data sheet. Any thoughts?

    Thanks for the valuable resource and looking forward to see how your project progresses!

    ReplyDelete
    Replies
    1. Hi Moon!

      Glad some of these posts have been useful for you - I'd be happy to try and help with whatever questions you may have.

      I am not so sure about the retryCount value. Pretty sure I am running at 35.. I'll diff the libraries and let you know if I just forgot about a value that I changed.

      Regarding the resistor - I simply added it as a quick and easy way to get the sensor working based on other peoples experience. Regarding the pull up resistor, it can't hurt because I do not believe the RHT03 has one built in. (I have to revisit the data sheet though).

      To get a better feel for why the pull up resistor helps I would check out this article:
      http://dsscircuits.com/articles/effects-of-varying-i2c-pull-up-resistors.html

      They even have many oscilloscope captures of how various resistors may impact your voltage. Conceptually it's there to clean up the signal coming from the RHT03.

      Other articles that may add to your knowledge include:
      http://www.cmiyc.com/tutorials/arduino-pull-ups/
      http://en.wikipedia.org/wiki/Pull-up_resistor

      Anything you'd like to see specifically with this project? I am just thinking about a summary post with various screenshots etc.

      Delete
  2. Thanks Eric, somehow that has been a fairly difficult concept for me to grasp for whatever reason, but the arduino-pull-ups video really made good sense of it.

    I got an html based monitor working for my sensor, but had to parse the serial through python and then store each update to a mongodb, cause I haven't gotten the Ethernet shield yet, but that's the next step.

    I can't think of anything specifically right now, but I'll keep following along, and I'll get something online about my projects too.

    Cheers!

    ReplyDelete
  3. Hey Eric, thanks for this blog. I'm doing a senior thesis in college making a chicken egg incubator, and I will be using the RHT03, but am totally new to Arduino. So this will help me a lot -- thanks so much!

    ~ Caroline

    ReplyDelete
    Replies
    1. Ah, excellent! Let me know if anything isn't clear :)

      Delete
  4. Hi,

    I get error something like -

    Serial:42: error: 'class DHT22' has no member named 'getTemperatureCInt'

    Would you help please?

    Thanks,

    Deepak

    ReplyDelete