Using the TinyTX with the DHT22 Temperature/Humidity Sensor

I covered some of this in the comments on my last post but thought it made sense to do a separate post detailing it.

The DHT22, also known as the AM2302 and RHT03 is a relatively cheap combined digital temperature and humidity sensor that with a little manipulation will go straight onto my TinyTX sensor board (or previous stripboard versions) in place of the DS18B20 temperature sensor.

The DHT22 is widely available and costs around £6 on eBay with delivery so not too expensive, don’t be tempted by the cheaper DHT11, in my tests the readings it returned were wildly inaccurate and it will only return integer values and only covers 0-50°C compared to -40 to 125°C for the DHT22. Someone also commented in the previous post that they had the same experience of inaccurate results with the DHT11 so it seems it wasn’t just a one off bad unit that I had.

The DHT22 has four pins but the third (looking at it face on) isn’t used, by bending the unused pin out of the way and bending the fourth in slightly it will fit into the pads for the DS18B20, the only other change required for the hardware is to swap the 4K7 resistor for a 10K. Load the ATtiny with some modified code and we’re good to go.

The gotcha here is that the DHT22 only works down to around 3V, once it dropped below 2.96V in my tests it started to return bad readings. For the moment I am just running one off 2xAA batteries (a starting voltage of 3.19V) and will see how long I can get from it. My ATmega based temperature sensor took 6 months before the voltage dropped to 3V so I should get at least that long and I could then recycle the batteries in one of my DS18B20 sensors. Failing that I could use a boost converter to keep the voltage up at 3.3V or add another battery or two and use a voltage regulator to drop it to 3.3V.

The code for using the DHT22 sensor is available on my GitHub here. The sensor uses a one wire type protocol but is incompatible with the Dallas OneWire system, I’m using the library from here although thanks to a comment from Troels in my last post I realised it has a bug regarding negative temperatures, I’ve fixed that and submitted a pull request but in the meantime you can use my fork here.

I’ve also been looking at other humidity sensors, the Sensirion SHT1x and SHT7x look good, work down to 2.4V and are easily available but they are pricey (~£20+), the HYT131 is a bit cheaper (~£15+) but not widely available. All these use a 2 wire bus to communicate so wouldn’t be as easy to use with this board as the DHT22. Probably something to look at closer for the next version of the TinyTX.

There is now a dedicated page for the TinyTX.

47 thoughts on “Using the TinyTX with the DHT22 Temperature/Humidity Sensor

  1. Nathan, wonderful project! I have the OpenEnergyMonitor system working, and had looked at your earlier posts, bought the parts, and even ordered the DHT22 to see if could also get this going. Now I see you have done all the hard work – thanks! I plan to have several such distributed sensors / transmitters. Have you considered offering the PCB (and components) for sale, perhaps via the OEM website if they wish to collaborate? I imagine setting up an e-commerce site is a lot of work. I think there would be demand!
    By the way, can the TinyTX version have multiple DS18B20 sensors all connected with the common bus? I assume so, but it is good to check!

  2. Thanks Andy. I’ve got some ideas brewing for the next version and have been thinking about offering some for sale as a few people have asked, wouldn’t be hard to do through Paypal.

    You can run multiple DS18B20 sensors by daisy chaining them in the normal way.

    To read them you can just do something simple like this:


    and add the variables to the Payload data structure.

    or if you plan on adding more sensors later it would be better to use the direct addressing method to identify each sensor so the variables don’t move round as you add more. There are some examples of how to do that in the emontx code somewhere.

  3. Hi Nathan, Thanks! I will definitely try this project (on stripboard to start with), but look forward to being able to buy some PCBs in future. I suspected that multiple temp sensors would work on a single unit, so I’m glad this is the case. I can see lots of applications for internal/external temp/humidity (calculating dew points and making recommendations when to open windows on hot evenings), as well as monitoring of the boiler, water tank, solar heating system. Cheers Andy.

  4. Hello

    great project but hard to find. I was looking for a wireless temp sensor reader that can read mutliple wireless sensors. As far as I followed your posts, you currently use only one wireless sensor.

    My goal is to have different wireless temp/humidity sensors spread over the rooms of the house and one outside and fead there data into a web server, so I can read the values from the network.

    Is it possible to use multiple sensors with your code?



  5. PS, sorry, I submitted to fast.

    Actually I have three wireless sensors using OOK at 430 Mhz. In the meantime I realized that it will be very hard to read there values although there are some descriptions out there to read there data (TFA Dorstmann sensors).

    So I turned around and would like to start with RFM12B based wireless sensors.



  6. Hi Josef,

    Yes, I’m only using one sensor on each board and putting multiple boards around the house, saves running wires for additional sensors.

    It doesn’t look like the DHT22 can’t be daisy chained like the DS18B20 sensor so to run multiple sensors would require a separate pin for each sensors data line. Looks like it would be easy enough to adapt the code for that.


  7. I am coming to this late. Moving some projects from arduino to rpi.

    The humidity from DHT11 is as often as not garbage. I am doing some sensor -> web “domestic” projects, and do weather application software for a living. I reckon only about half DHT11’s give a decent RH. (I’ve wired up a few now). Half are 15-20% out which will make a mess of a dewpoint applications. I suppose you get what you pay for. The temps from DHT11 and for that matter TMP36 / LM35 / BMP085 etc all look OK and comparable but for real weather apps you obviously need sensors that range down to -40 (well not really that far).

    Outdoor sensors make for much more interesting real applications but present the problems of preventing water ingress, dew and solar heating whilst still getting good ventilation. Real McCoy shields and screens come at a hefty price, and attract vandals and nosey pokey fingers IMHO. An incongruous home-made gubbins is a fun challenge.

    Regards / MikeR

  8. Yes, outdoor sensors are tricky, I initially had problems with solar heating mid morning until I moved them from the rear of the house to the front, they are currently situated under a sheltered outrigger which keeps them out of direct sunlight and rain, not ideal but ok for my purposes. I’m currently waiting for one of the Air Quality Egg kits, a project that has suffered many delays, not least of which has been the design of a suitable enclosure for the sensors, it will be interesting to see how it performs. The AQE is also built on AVR/RFM12B technology so should be a good match for my existing setup. Looking forward to eventually receiving it, latest estimate was end of this month.

  9. Hello Hathan,

    were you trying to run rfm12b at 4V? Right now I’m trying to solve problem with voltage and DHT21 (3 NIMHs are way cheaper than stepup from one AA battery). From datasheet there is up to 3.8V operating… The voltage will drop quite quickly below 3.8 but I’m starting at 4.0V…

    Thank you


  10. Have been working with the DHT11 sensor and as far as I can asertain by using a wet/dry hygrometer its humidity readings are of no use so I gave up on them. I went searching and found these: HIH-6130, HIH-6121 made by Honeywell they are I2C and their readings are proving to be accurate the HIH-6121 seems to be the best value for money with inbuilt filter, they cost more than the DHT sensors but if you want actual readings of humidity they give you that the only drawback is they all have the same slave address so only one per buss.

  11. Hi,

    I just received my tinytx3 pcb from seeedstudio. I have to say that the manufacture seems pretty nice for the price.

    I soldered the rfm12b and attiny84a and now i’m thinking about equipping the pcb with a DHT22.

    Any of you tried with a tinytx3 ? Pinout of the DHT22 doesn’t seems to match easily with the v3 compared to the v2 ….

    Have a nice day.

  12. For a lot of mine where they are out of sight I’ve just stuck the PCB to the battery holder with a double sided sticky pad but for some I’ve used the EN020 boxes from They can be tight depending on the size of your battery holder and if you are using a socket for the IC so the next size up might be better. I’ve also had some bigger ones with mounting flanges from in the past but doesn’t look like they do them anymore.

    If I’ve boxed them I’ve always had the sensor itself outside the box.

  13. I’m interested in 2 if you decide to make an offering in the near future….want the capabilities to turn on/off a heater/cooler and/or humidifier to keep fermentation room at proper temp/humidity….great project, thanks

  14. God bless you, Nathan!

    I think I am very close now…

    My RFM12Pi looks correctly installed.

    I would like to test it sending data from the TinyTX v3 with your software and the DHT22 to the Raspberry.

    I’ve assembled the TinyTX (great little thing!) and uploaded your arduino code (thanks for the tip to compile it again).

    I’ve tried turning it on while opening minicom but nothing happens…
    What should I do?

  15. What boost converter you use?
    NCP1402-5V Step-Up Breakout or NCP1402-3.3V Step-Up Breakout or another?
    Thank you!

  16. @ltpitt Did you get it working? if not you could try this test sketch on your TinyTX, it will send an incrementing number and the battery voltage every 10 seconds, if that works it points to a problem on the sensor side of things.

    You could also try setting 0q on the RFM12Pi which will let it show traffic from any other 433MHz devices you have around, that would at least confirm the RFM12Pi is working and receiving something.

    @cbiale You want the 3.3V one.

  17. @nathan
    I wish I could say so 🙁

    I have tried your suggestion:

    minicom -b 9600 -o -D /dev/ttyAMA0

    Then I see minicom and I configure it pressing:

    4b and 0g

    I should now receive from all devices sending data on 433 mhz, right?

    Why nothing happens? I have remote controllers and a tellstick but in minicom nothing appears…

    Should I press something?

    The board seem so work because if I turn its led on and off it works no problems.

  18. I want to cry the test finally worked :'(

    I am the happiest ever.

    How can I collect the data without emoncms?

    Thank you for your patience…

    This will be the last step required 🙂

  19. ps

    All happy I went putting on the tinyTX my other attiny with dht22 code and dht22 and resistor.

    Changed minicom accordingly: nothing received, now.

    Any clues on how I can find the culprit?

    I feed 3.5volt to the tinytx and I have no capacitors on it (it works fine with test script)

  20. pps

    Sorry but I keep on thinking on useful details:
    The DHT22 is perfectly working with the same resistor if I connect it to the raspberry Pi

  21. I finally did it!

    It was all thanks to a previous comment of yours in this page 😀

    I suggest to all users having TinyTX v3 and troubles with DHT22 to review accurately the comments and find this part:

    Then change the pin definitions in the code to the below:

    #define DHT22_PIN 9 // DHT sensor is connected on D9
    #define DHT22_POWER 8 // DHT Power pin is connected on D8

    Corrected this everything works great and I can finally send data and read it with python 🙂

    I get data like this:

    16 224 16 14 14 58 12
    -> ack
    16 250 15 3 14 174 11
    -> ack

    Where are temp, humidity and voltage?
    Can I get data with float?

    Thanks 🙂

  22. There are a couple of useful posts on Jeelabs here about decoding the packet format:

    Python isn’t my language of choice but this seems to be working:

    rx = "16 224 16 14 14 58 12"
    data = rx.split(" ")
    a = int(data[1])
    b = int(data[2])
    c = int(data[3])
    d = int(data[4])
    e = int(data[5])
    f = int(data[6])
    node_id = str(int(data[0]) & 0x1f)
    humidity = str((a+b*256)/100.0)
    voltage = str(c+d*256)
    temperature = str((e+f*256)/100.0)
    print "node:", node_id
    print "humidity:", humidity, "%"
    print "temperature:", temperature, "C"
    print "voltage:", voltage, "mV"


    node: 16
    humidity: 43.2 %
    temperature: 31.3 C
    voltage: 3598 mV

  23. Thanks a lot for the hint!

    I think something must be wrong in the calculations because data coming from my dht22 with your script looks like:

    Got: 16 146 19 202 12 156 9
    -> ack

    humidity: 373.92 %
    temperature: 399.48 C
    voltage: 51731 mV

    I will try to fix it…

  24. It works like in a dream!

    I just finished writing a complete python script to write data in mysql and get email notifications.

    If it’s ok for you I’d like to put it on git as my first little pubblication…

    Of course I put in it all credits and thanks to you and sweet TinyTX 🙂

  25. Hi Nathan,
    the TinyTX is awesome.
    I was wondering, if it is possible to change the time the TX is sending it’s data. I would like to send it every 10 minutes.
    I guess this could be done at the end of your code. but it says that the value should be 16-65000ms.

  26. @blue-TX I guess you might have worked this out by now as it was a while ago but you can put Sleepy::loseSomeTime in a loop to get a longer time, eg. for 10 minutes:

    for (byte i = 0; i < 10; ++i) Sleepy::loseSomeTime(60000); @Gerard You can use the RFM12Pi board to receive it on the Raspberry Pi and there is a plugin available for emoncms for it. You can get it from Open Energy Monitor here:
    I wrote about using an older version of it here:

    Or you can use another TinyTX instead of an RFM12Pi, see this comment here:

  27. I would like to create a temperature sensor and humidity I already have the TM36, can I add the sensor SHT21? See you problems? Is it a good humidity sensor?
    Could you recommend a economical humidity sensor to be put together with the TM36?

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.