{"id":52221,"date":"2026-11-01T10:50:41","date_gmt":"2026-11-01T10:50:41","guid":{"rendered":"http:\/\/siratek.net\/index.php\/tutorials\/dht22-temperature-humidity\/"},"modified":"2026-11-01T10:50:41","modified_gmt":"2026-11-01T10:50:41","slug":"dht22-temperature-humidity","status":"publish","type":"siratek_tutorial","link":"https:\/\/siratek.net\/index.php\/tutorials\/dht22-temperature-humidity\/","title":{"rendered":"DHT22, Better Accuracy Than the DHT11"},"content":{"rendered":"<body><p><\/p>\n<h2>What it does<\/h2>\n<p>The same job as the DHT11, done properly. Temperature and humidity, read over one wire, in a white plastic housing that is noticeably larger than its blue cousin.<\/p>\n<p>If you have done the DHT11 tutorial, this page is short by design: the wiring is the same, the library is the same, and the code is one word different. What is worth your time is <strong>when the extra cost is justified<\/strong>, because for a lot of projects it is not.<\/p>\n<h2>Before you begin<\/h2>\n<h3>Required parts and tools<\/h3>\n<ul>\n<li>An Arduino Uno or compatible board.<\/li>\n<li>One DHT22 module. This is Siratek product 2870.<\/li>\n<li>Three jumper wires. The Siratek part is supplied with a three-wire lead.<\/li>\n<\/ul>\n<h3>What you are holding<\/h3>\n<p>The Siratek part is a <strong>module, not a bare sensor<\/strong>: an ASAIR <strong>AM2302<\/strong> in the white housing, mounted on a small black PCB with a three-pin header marked<\/p>\n<p><strong><code>+<\/code>  <code>out<\/code>  <code>-<\/code><\/strong><\/p>\n<p>AM2302 is the same sensor as a DHT22 in a module package, which is why datasheets and libraries use both names for it.<\/p>\n<p>As with the DHT11 module, the board carries the pull-up resistor, so <strong>no external resistor is needed<\/strong>. A bare four-pin DHT22 without a board does need one, typically 10 kilohms between data and power.<\/p>\n<h3>Where it is better<\/h3>\n<table>\n<thead>\n<tr>\n<th><\/th>\n<th>DHT11<\/th>\n<th>DHT22<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Temperature range<\/td>\n<td>0 to 50 C<\/td>\n<td>-40 to 80 C<\/td>\n<\/tr>\n<tr>\n<td>Temperature accuracy<\/td>\n<td>about 2 C<\/td>\n<td>about 0.5 C<\/td>\n<\/tr>\n<tr>\n<td>Temperature resolution<\/td>\n<td>1 C, whole numbers only<\/td>\n<td>0.1 C<\/td>\n<\/tr>\n<tr>\n<td>Humidity range<\/td>\n<td>20 to 80 %<\/td>\n<td>0 to 100 %<\/td>\n<\/tr>\n<tr>\n<td>Humidity accuracy<\/td>\n<td>about 5 %<\/td>\n<td>about 2 to 5 %<\/td>\n<\/tr>\n<tr>\n<td>Reading interval<\/td>\n<td>1 second<\/td>\n<td><strong>2 seconds<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The resolution line is the one that usually decides it. <strong>A DHT11 reports temperature as whole degrees<\/strong>, so a room drifting from 24.2 to 24.8 shows no change at all, then jumps a degree. For anything you intend to graph, that alone is worth the upgrade.<\/p>\n<p>The range line matters outdoors or in a fridge, where the DHT11 simply stops being valid.<\/p>\n<h3>Where it is not worth it<\/h3>\n<p>If the project asks \u201cis it hot?\u201d or \u201cis it humid?\u201d, the DHT11 answers just as well for less money. Neither sensor is a laboratory instrument, and the DHT22\u2019s humidity accuracy is only modestly better than the DHT11\u2019s.<\/p>\n<p>And neither is the right choice for temperature alone. A DS18B20 is more accurate than both, reads faster, is waterproof, and several can share one pin. Buy a DHT for <strong>humidity<\/strong>; buy a DS18B20 for temperature.<\/p>\n<h3>Two seconds, not one<\/h3>\n<p>The DHT22 needs <strong>two seconds between readings<\/strong>, where the DHT11 needs one. Ask more often and you get the previous reading again, or a <code>nan<\/code>.<\/p>\n<p>This catches people moving a working DHT11 sketch across. The symptom is intermittent failed reads that look like a wiring fault.<\/p>\n<h2>Pin reference<\/h2>\n<table>\n<thead>\n<tr>\n<th>Pin or label<\/th>\n<th>Connect to<\/th>\n<th>Purpose<\/th>\n<th>Notes<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>+<\/code><\/td>\n<td>Uno <code>5V<\/code><\/td>\n<td>Power<\/td>\n<td>3.3 to 6 V<\/td>\n<\/tr>\n<tr>\n<td><code>out<\/code><\/td>\n<td>Uno <code>D2<\/code><\/td>\n<td>Data<\/td>\n<td>Pull-up already fitted on the module<\/td>\n<\/tr>\n<tr>\n<td><code>-<\/code><\/td>\n<td>Uno <code>GND<\/code><\/td>\n<td>Ground<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<figure class=\"siratek-tutorial-figure\"><img decoding=\"async\" src=\"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/dht22-temperature-humidity-wiring.svg\" alt=\"A DHT22 module with its three-pin header marked plus, out and minus wired to 5V, pin 2 and ground\" loading=\"lazy\"><figcaption>Three wires, and the pull-up is already on the board. Two seconds between readings, not one.<\/figcaption><\/figure>\n<h2>Wiring steps<\/h2>\n<ol>\n<li>Unplug the USB cable.<\/li>\n<li><code>+<\/code> to <code>5V<\/code>.<\/li>\n<li><code>out<\/code> to <code>D2<\/code>.<\/li>\n<li><code>-<\/code> to <code>GND<\/code>.<\/li>\n<li>Plug the USB cable back in.<\/li>\n<\/ol>\n<p>The supplied lead has three separate female ends, so check each against the silkscreen rather than assuming the colours. Orange, yellow and green here are just wire, not a convention.<\/p>\n<h2>Software and libraries<\/h2>\n<p>The same <strong>DHT sensor library<\/strong> by Adafruit used in the DHT11 tutorial, with <strong>Adafruit Unified Sensor<\/strong> alongside it. If you have already done that tutorial, nothing new to install.<\/p>\n<h2>Minimal working example<\/h2>\n<pre><code>\/\/ Siratek: temperature and humidity from a DHT22.\n\n#include &lt;DHT.h&gt;\n\nconst int dhtPin = 2;\n\n\/\/ The only change from the DHT11 sketch is this one word.\nDHT dht(dhtPin, DHT22);\n\nvoid setup() {\n  Serial.begin(9600);\n  dht.begin();\n  Serial.println(\"Siratek: DHT22 starting.\");\n}\n\nvoid loop() {\n  \/\/ Two seconds minimum for a DHT22.\n  delay(2000);\n\n  float humidity = dht.readHumidity();\n  float temperature = dht.readTemperature();\n\n  if (isnan(humidity) || isnan(temperature)) {\n    Serial.println(\"read failed. Check the wiring, and wait two seconds between reads.\");\n    return;\n  }\n\n  Serial.print(\"temperature = \");\n  Serial.print(temperature, 1);\n  Serial.print(\" C   humidity = \");\n  Serial.print(humidity, 1);\n  Serial.println(\" %\");\n}<\/code><\/pre>\n<p>The <code>DHT22<\/code> in the constructor is genuinely the whole difference. Leave it as <code>DHT11<\/code> with a DHT22 connected and you get nonsense rather than an error, because the library decodes the same bits a different way.<\/p>\n<p>Printing with <code>, 1<\/code> shows one decimal place, which is the point of this sensor. With a DHT11 that digit is always zero.<\/p>\n<h3>Checking for a failed read, every time<\/h3>\n<p><code>nan<\/code> means \u201cnot a number\u201d, and it is what the library returns when a reading did not arrive cleanly. Occasional failures are normal with these sensors, especially on a longer wire.<\/p>\n<p>The guard above prints a message. In a logger you would rather keep the previous value:<\/p>\n<pre><code>float lastGood = NAN;\n\nvoid loop() {\n  delay(2000);\n\n  float t = dht.readTemperature();\n  if (!isnan(t)) {\n    lastGood = t;\n  }\n\n  if (!isnan(lastGood)) {\n    Serial.println(lastGood, 1);\n  }\n}<\/code><\/pre>\n<p>A sketch that writes <code>nan<\/code> into a log file produces a spreadsheet column that will not plot. Filtering at the source is less work than cleaning it afterwards.<\/p>\n<h2>Expected result<\/h2>\n<p>A reading every two seconds, with one decimal place on both figures.<\/p>\n<p>Breathe gently on the sensor: humidity should climb several percent within a second or two and fall back over the next half minute. That is the fastest way to prove it is really measuring rather than reporting a constant.<\/p>\n<p>Expect the temperature to read a little above the room. The sensor warms itself slightly, and the effect is more noticeable in still air.<\/p>\n<h2>Troubleshooting<\/h2>\n<table>\n<thead>\n<tr>\n<th>Symptom<\/th>\n<th>Likely cause<\/th>\n<th>Check or fix<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Always <code>nan<\/code><\/td>\n<td>Wiring, or <code>DHT11<\/code> in the constructor<\/td>\n<td>Check both<\/td>\n<\/tr>\n<tr>\n<td>Intermittent <code>nan<\/code><\/td>\n<td>Reading faster than every two seconds<\/td>\n<td>Slow down<\/td>\n<\/tr>\n<tr>\n<td>Readings plausible but odd<\/td>\n<td>Wrong sensor type in the constructor<\/td>\n<td><code>DHT22<\/code>, not <code>DHT11<\/code><\/td>\n<\/tr>\n<tr>\n<td>Decimal place always zero<\/td>\n<td>That is a DHT11<\/td>\n<td>Check which part you have<\/td>\n<\/tr>\n<tr>\n<td>Humidity stuck at 99<\/td>\n<td>Condensation on the sensor<\/td>\n<td>Let it dry; it recovers<\/td>\n<\/tr>\n<tr>\n<td>Temperature reads high<\/td>\n<td>Self-heating, still air<\/td>\n<td>Normal; allow some airflow<\/td>\n<\/tr>\n<tr>\n<td>Fails on a long cable<\/td>\n<td>Signal degraded<\/td>\n<td>Keep it under a metre, or add a 10 k pull-up<\/td>\n<\/tr>\n<tr>\n<td>Works, then stops after months<\/td>\n<td>Humidity sensors age<\/td>\n<td>Expected; they drift over years<\/td>\n<\/tr>\n<tr>\n<td>Compile error about Adafruit_Sensor<\/td>\n<td>Unified Sensor library missing<\/td>\n<td>Install it as well<\/td>\n<\/tr>\n<tr>\n<td>Want a tenth of a degree outdoors<\/td>\n<td>This is the right sensor<\/td>\n<td>Or a DS18B20 for temperature alone<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Next steps<\/h2>\n<ul>\n<li><strong>Easier first:<\/strong> <em>Read Temperature and Humidity with DHT11<\/em>, which this page assumes.<\/li>\n<li><strong>Related products:<\/strong> the DS18B20 for temperature alone, or the BMP280 for pressure.<\/li>\n<li><strong>Next project:<\/strong> a mini weather station, logging temperature and humidity to an SD card with a real timestamp.<\/li>\n<\/ul>\n<h2>Sources and attribution<\/h2>\n<p>All text, wiring guidance and code in this tutorial are original Siratek work.<\/p>\n<ul>\n<li>DHT22 and DHT11 datasheets for the ranges, accuracies, resolutions and minimum reading intervals in the comparison table.<\/li>\n<li>The ASAIR <code>AM2302<\/code> marking, the <code>+ out -<\/code> header and the supplied three-wire lead were read from the Siratek product photographs for item 2870, which is what establishes that no external pull-up is needed.<\/li>\n<\/ul>\n<p>Accuracy figures are the manufacturer\u2019s typical values and are given as such. No third-party tutorial text, diagrams, photographs or code has been reproduced here.<\/p>\n<p><\/p>\n<\/body>","protected":false},"excerpt":{"rendered":"<p>The same job as the DHT11, done properly. Temperature and humidity, read over one wire, in a white plastic housing that is noticeably larger than its blue cousin.<\/p>\n","protected":false},"featured_media":0,"template":"","siratek_tutorial_level":[],"class_list":["post-52221","siratek_tutorial","type-siratek_tutorial","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>DHT22, Better Accuracy Than the DHT11 - siratek<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/siratek.net\/index.php\/tutorials\/dht22-temperature-humidity\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"DHT22, Better Accuracy Than the DHT11 - siratek\" \/>\n<meta property=\"og:description\" content=\"The same job as the DHT11, done properly. Temperature and humidity, read over one wire, in a white plastic housing that is noticeably larger than its blue cousin.\" \/>\n<meta property=\"og:url\" content=\"http:\/\/siratek.net\/index.php\/tutorials\/dht22-temperature-humidity\/\" \/>\n<meta property=\"og:site_name\" content=\"siratek\" \/>\n<meta property=\"og:image\" content=\"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/dht22-temperature-humidity-wiring.svg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/dht22-temperature-humidity\\\/\",\"url\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/dht22-temperature-humidity\\\/\",\"name\":\"DHT22, Better Accuracy Than the DHT11 - siratek\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/siratek.net\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/dht22-temperature-humidity\\\/#primaryimage\"},\"image\":{\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/dht22-temperature-humidity\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/siratek.net\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/dht22-temperature-humidity-wiring.svg\",\"datePublished\":\"2026-11-01T10:50:41+00:00\",\"breadcrumb\":{\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/dht22-temperature-humidity\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/dht22-temperature-humidity\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/dht22-temperature-humidity\\\/#primaryimage\",\"url\":\"https:\\\/\\\/siratek.net\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/dht22-temperature-humidity-wiring.svg\",\"contentUrl\":\"https:\\\/\\\/siratek.net\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/dht22-temperature-humidity-wiring.svg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/dht22-temperature-humidity\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/siratek.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorials\",\"item\":\"https:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"DHT22, Better Accuracy Than the DHT11\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/siratek.net\\\/#website\",\"url\":\"https:\\\/\\\/siratek.net\\\/\",\"name\":\"siratek\",\"description\":\"Your Best Electronic Retail Shop\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/siratek.net\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"DHT22, Better Accuracy Than the DHT11 - siratek","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/siratek.net\/index.php\/tutorials\/dht22-temperature-humidity\/","og_locale":"en_US","og_type":"article","og_title":"DHT22, Better Accuracy Than the DHT11 - siratek","og_description":"The same job as the DHT11, done properly. Temperature and humidity, read over one wire, in a white plastic housing that is noticeably larger than its blue cousin.","og_url":"http:\/\/siratek.net\/index.php\/tutorials\/dht22-temperature-humidity\/","og_site_name":"siratek","og_image":[{"url":"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/dht22-temperature-humidity-wiring.svg","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/siratek.net\/index.php\/tutorials\/dht22-temperature-humidity\/","url":"http:\/\/siratek.net\/index.php\/tutorials\/dht22-temperature-humidity\/","name":"DHT22, Better Accuracy Than the DHT11 - siratek","isPartOf":{"@id":"https:\/\/siratek.net\/#website"},"primaryImageOfPage":{"@id":"http:\/\/siratek.net\/index.php\/tutorials\/dht22-temperature-humidity\/#primaryimage"},"image":{"@id":"http:\/\/siratek.net\/index.php\/tutorials\/dht22-temperature-humidity\/#primaryimage"},"thumbnailUrl":"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/dht22-temperature-humidity-wiring.svg","datePublished":"2026-11-01T10:50:41+00:00","breadcrumb":{"@id":"http:\/\/siratek.net\/index.php\/tutorials\/dht22-temperature-humidity\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/siratek.net\/index.php\/tutorials\/dht22-temperature-humidity\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/siratek.net\/index.php\/tutorials\/dht22-temperature-humidity\/#primaryimage","url":"https:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/dht22-temperature-humidity-wiring.svg","contentUrl":"https:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/dht22-temperature-humidity-wiring.svg"},{"@type":"BreadcrumbList","@id":"http:\/\/siratek.net\/index.php\/tutorials\/dht22-temperature-humidity\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/siratek.net\/"},{"@type":"ListItem","position":2,"name":"Tutorials","item":"https:\/\/siratek.net\/index.php\/tutorials\/"},{"@type":"ListItem","position":3,"name":"DHT22, Better Accuracy Than the DHT11"}]},{"@type":"WebSite","@id":"https:\/\/siratek.net\/#website","url":"https:\/\/siratek.net\/","name":"siratek","description":"Your Best Electronic Retail Shop","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/siratek.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial\/52221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial"}],"about":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/types\/siratek_tutorial"}],"version-history":[{"count":0,"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial\/52221\/revisions"}],"wp:attachment":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/media?parent=52221"}],"wp:term":[{"taxonomy":"siratek_tutorial_level","embeddable":true,"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial_level?post=52221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}