RHT03

/media/uploads/tristanjph/10167-01.jpg

The RHT03 is a digital humidity and temperature sensor. It is sometimes know as the DHT22. The sensor is available from Sparkfun here.

Hello World!

Import program

00001 #include "mbed.h"
00002 #include "RHT03.h" //Include neede to use the RHT03 lib
00003 
00004 int main()
00005 {
00006     int done=0;
00007     float temp,hum;
00008 
00009     RHT03 humtemp(p24); //Initalise the RHT03 (change pin number to the pin its connected to)
00010 
00011     while(!done) //Loop keeps running until RHT03 is read succesfully
00012     {
00013         wait(2); //Needed to make sure the sensor has time to initalise and so its not polled too quickly
00014         if(humtemp.readData() == RHT_ERROR_NONE) done=1; //Request data from the RHT03
00015     }
00016     
00017     temp = humtemp.getTemperatureC(); //Gets the current temperature in centigrade
00018     hum = humtemp.getHumidity(); //Gets the current humidity in percentage
00019 
00020 }

Wiring the RHT03

The sensor comes in a 4 legged package, but only 3 are required. The pins are numbered 1-4 from left to right when looking at the front of the sensor.

The will work on any voltage from 3.3-6v. The datasheet advises putting a 100nF capacitor between VDD and GND for wave filtering, but don't worry if you don't have one of these it will still work!

VDD should be connected onto pin 1 and GND onto pin 4.

The sensor uses a MaxDetect 1-wire bus, this is a dual direction digital signal. This can be connected to any of the Digital In/Out ports on the mbed. The digital in/out port of the mbed should be connected to pin 2 on the RHT03. A 1K pull up resistor is also required on the data line.

The pins are numbered 1-4 from left to right when looking at the front of the sensor.

/media/uploads/tristanjph/rht03_wiring.png

Getting Data from the RHT03

The bus/sensor is a little bit temperamental at times...

All you need to know about getting the data is:

  • You have to wait at least 2 seconds after a power on to get data from the sensor
  • You can only request data from the sensor every 2 seconds
  • You will get a get a couple of check sum errors most times you try to read sensor data

RHT03 Library

Import library

Public Member Functions

RHT03 (PinName Data)
Configure data pin.
RHT03_ERROR readData (void)
Reads data from the RHT03 .
float getHumidity ()
Gives current humidity value.
float getTemperatureC ()
Gives current temperature value.

Data sheet: http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Weather/RHT03.pdf


All wikipages