{"id":52219,"date":"2026-11-01T10:50:40","date_gmt":"2026-11-01T10:50:40","guid":{"rendered":"http:\/\/siratek.net\/index.php\/tutorials\/dht11-temperature-humidity\/"},"modified":"2026-11-01T10:50:40","modified_gmt":"2026-11-01T10:50:40","slug":"dht11-temperature-humidity","status":"publish","type":"siratek_tutorial","link":"https:\/\/siratek.net\/index.php\/tutorials\/dht11-temperature-humidity\/","title":{"rendered":"Read Temperature and Humidity with DHT11"},"content":{"rendered":"<body><p><\/p>\n<h2>What it does<\/h2>\n<p>The DHT11 measures air temperature and relative humidity and reports both as digital values. It does its own measuring and converting, so you receive numbers rather than a voltage to interpret.<\/p>\n<p>It is the usual first environmental sensor, and the first part most people meet that needs a <strong>library<\/strong>. The reason is worth understanding: the DHT11 does not use I2C or SPI. It has one data wire and a timing-critical protocol of its own, where bits are distinguished by how long the line stays high, measured in microseconds. Writing that by hand is possible and unpleasant. A library does it properly, and this is a good moment to learn how libraries fit in.<\/p>\n<h2>Before you begin<\/h2>\n<h3>Required parts and tools<\/h3>\n<ul>\n<li>An Arduino Uno or compatible board, already set up.<\/li>\n<li>One DHT11 sensor or module.<\/li>\n<li>Three jumper wires, and a breadboard if your sensor is a bare component.<\/li>\n<li>A USB data cable.<\/li>\n<\/ul>\n<h3>Know what accuracy you are buying<\/h3>\n<p>The DHT11 is cheap and adequate for a room monitor. It is not an instrument, and a tutorial that implies otherwise sets up a disappointment.<\/p>\n<table>\n<thead>\n<tr>\n<th><\/th>\n<th>Typical figure<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Temperature range<\/td>\n<td>about 0 to 50 degrees C<\/td>\n<\/tr>\n<tr>\n<td>Temperature accuracy<\/td>\n<td>roughly plus or minus 2 degrees C<\/td>\n<\/tr>\n<tr>\n<td>Humidity range<\/td>\n<td>about 20 to 90 percent relative humidity<\/td>\n<\/tr>\n<tr>\n<td>Humidity accuracy<\/td>\n<td>roughly plus or minus 5 percent<\/td>\n<\/tr>\n<tr>\n<td>Resolution<\/td>\n<td>whole numbers<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Confirm these against the datasheet for the part you actually received, since the figures vary a little between suppliers.<\/p>\n<p>If you need decimals or better accuracy, the DHT22 is the same wiring and almost the same code, and Siratek stocks it. For temperature alone, the DS18B20 is more accurate still and comes in a waterproof probe.<\/p>\n<p>Note the lower humidity limit. Below about 20 percent the DHT11 simply cannot report, which matters during harmattan when indoor humidity can fall below its range.<\/p>\n<h3>The board Siratek sells<\/h3>\n<p>The DHT11 on the Siratek product page is a <strong>module<\/strong>: the blue sensor is soldered to a small circuit board with a three-pin header, and it comes with jumper leads.<\/p>\n<p>That matters, because the module already carries the pull-up resistor the sensor needs. It is the small component marked <code>103<\/code> on the board, which is the code for 10 kilohms. <strong>You do not need to add one.<\/strong><\/p>\n<p>The three pins are marked <code>+<\/code>, <code>OUT<\/code> and <code>-<\/code>. Match those marks to your wires rather than counting positions, because the header can be fitted either way round.<\/p>\n<p>A <strong>bare four-pin sensor<\/strong>, bought loose rather than on a board, is the other thing sold as a DHT11. That one does need a 10 kilohm resistor between its data pin and <code>VCC<\/code>, and its fourth pin is unused.<\/p>\n<h3>Once a second, no faster<\/h3>\n<p>The DHT11 takes its own time to measure. Asking more often than <strong>once per second<\/strong> returns a stale or failed reading. The sketches here wait two seconds, which is comfortable.<\/p>\n<p>This is also why a library that returns the same number repeatedly is not necessarily broken. It may be handing back the last successful measurement.<\/p>\n<h3>Safety notes<\/h3>\n<p>Low voltage and tiny currents throughout. Wire it with the USB cable unplugged.<\/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>Also works at 3.3 V on 3.3 V boards<\/td>\n<\/tr>\n<tr>\n<td><code>OUT<\/code><\/td>\n<td>Uno <code>D2<\/code><\/td>\n<td>The one-wire data line<\/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>Common ground<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>Fourth pin, bare sensors only<\/td>\n<td>Nothing<\/td>\n<td>Unused<\/td>\n<td>Not present on the module<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The header can be fitted either way round, so read the printing on your own board rather than counting positions from a picture, including the one below.<\/p>\n<h2>Wiring steps<\/h2>\n<figure class=\"siratek-tutorial-figure\"><img decoding=\"async\" src=\"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/dht11-temperature-humidity-wiring.svg\" alt=\"DHT11 module wired to an Arduino Uno, plus to 5V, OUT to pin 2 and minus to ground\" loading=\"lazy\"><figcaption>Three wires. The 10 kilohm pull-up, marked 103, is already on the board.<\/figcaption><\/figure>\n<ol>\n<li>Unplug the USB cable.<\/li>\n<li>Connect the pin marked <code>-<\/code> to a <code>GND<\/code> pin on the Uno.<\/li>\n<li>Connect the pin marked <code>+<\/code> to <code>5V<\/code>.<\/li>\n<li>Connect the pin marked <code>OUT<\/code> to digital pin <code>2<\/code>.<\/li>\n<li>Check the marks once more. Power and ground reversed will make the sensor hot, and this is the part where that mistake is easy.<\/li>\n<li>Plug the USB cable back in.<\/li>\n<\/ol>\n<h2>Software and libraries<\/h2>\n<p>This one needs a library. The widely used choice is the <strong>DHT sensor library<\/strong> from Adafruit, which also requires the <strong>Adafruit Unified Sensor<\/strong> library to be installed alongside it.<\/p>\n<ol>\n<li>Open <strong>Tools &gt; Manage Libraries<\/strong>.<\/li>\n<li>Search for <code>DHT sensor library<\/code> and install it.<\/li>\n<li>If the IDE offers to install its dependencies, accept. If it does not, search for <code>Adafruit Unified Sensor<\/code> and install that too.<\/li>\n<li>Record the version you installed in this tutorial\u2019s front matter when the sensor is tested on hardware.<\/li>\n<\/ol>\n<p>That last step is not bookkeeping for its own sake. These libraries change, and a sketch that worked a year ago can fail against a newer version. Knowing which version was tested is what makes the tutorial reproducible.<\/p>\n<h2>Minimal working example<\/h2>\n<pre><code>\/\/ Siratek: reading temperature and humidity from a DHT11.\n\n#include &lt;DHT.h&gt;\n\nconst int dhtPin = 2;\nDHT dht(dhtPin, DHT11);    \/\/ Second argument selects the sensor type.\n\nvoid setup() {\n  Serial.begin(9600);\n  Serial.println(\"Siratek: DHT11 starting.\");\n  dht.begin();\n}\n\nvoid loop() {\n  \/\/ Read both values first, then check them.\n  float humidity = dht.readHumidity();\n  float temperature = dht.readTemperature();   \/\/ Celsius by default.\n\n  \/\/ A failed read returns NaN, which is not the same as zero.\n  if (isnan(humidity) || isnan(temperature)) {\n    Serial.println(\"read failed\");\n  } else {\n    Serial.print(\"temperature = \");\n    Serial.print(temperature, 1);\n    Serial.print(\" C   humidity = \");\n    Serial.print(humidity, 1);\n    Serial.println(\" %\");\n  }\n\n  delay(2000);   \/\/ Never faster than once per second.\n}<\/code><\/pre>\n<p>The <code>isnan()<\/code> check is the line that separates a working project from a confusing one. When a read fails, the library returns \u201cnot a number\u201d, and arithmetic on it produces more nonsense rather than an error. Checking every reading before using it is a habit worth forming here, because the same pattern applies to most sensor libraries.<\/p>\n<h3>Reacting to a reading<\/h3>\n<pre><code>const float warmThreshold = 30.0;\n\nif (!isnan(temperature)) {\n  if (temperature &gt; warmThreshold) {\n    digitalWrite(fanPin, HIGH);\n    Serial.println(\"above threshold: fan on\");\n  } else {\n    digitalWrite(fanPin, LOW);\n  }\n}<\/code><\/pre>\n<p>A real fan or pump draws far more than a pin can supply, so <code>fanPin<\/code> here would drive a relay module or MOSFET module rather than the load itself. <em>Voltage, Current and Resistance<\/em> explains why, and the relay tutorial covers doing it safely.<\/p>\n<h2>Expected result<\/h2>\n<p>A reading every two seconds, with plausible values for the room:<\/p>\n<pre><code>Siratek: DHT11 starting.\ntemperature = 29.0 C   humidity = 68.0 %\ntemperature = 29.0 C   humidity = 68.0 %\ntemperature = 29.0 C   humidity = 67.0 %<\/code><\/pre>\n<p>Values will be whole numbers, because that is the sensor\u2019s resolution. Breathing gently on the sensor should raise the humidity within a few seconds and bring it back down slowly, which is the quickest way to confirm it is really measuring rather than repeating a stored value.<\/p>\n<p>The first read after power-up sometimes fails. That is normal; the second should succeed.<\/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><code>read failed<\/code> every time<\/td>\n<td>Data pin wrong, or sensor not powered<\/td>\n<td>Check all three wires and the pin in the sketch<\/td>\n<\/tr>\n<tr>\n<td><code>read failed<\/code> on a bare sensor<\/td>\n<td>Missing pull-up resistor<\/td>\n<td>Fit 10 k between data and <code>VCC<\/code>. The module already has one<\/td>\n<\/tr>\n<tr>\n<td>First read fails, rest work<\/td>\n<td>Sensor still settling<\/td>\n<td>Normal, ignore the first<\/td>\n<\/tr>\n<tr>\n<td>Same numbers forever<\/td>\n<td>Reading faster than once a second<\/td>\n<td>Increase the delay to 2000 ms<\/td>\n<\/tr>\n<tr>\n<td>Sketch will not compile<\/td>\n<td>Library not installed<\/td>\n<td>Install DHT sensor library and Adafruit Unified Sensor<\/td>\n<\/tr>\n<tr>\n<td>Compiles, no sensible values<\/td>\n<td><code>DHT22<\/code> passed instead of <code>DHT11<\/code><\/td>\n<td>Correct the second argument<\/td>\n<\/tr>\n<tr>\n<td>Sensor is hot to touch<\/td>\n<td>Power and ground reversed<\/td>\n<td>Unplug at once and recheck the labels<\/td>\n<\/tr>\n<tr>\n<td>Humidity stuck at the bottom<\/td>\n<td>Genuinely below the sensor\u2019s range<\/td>\n<td>Expected below about 20 percent<\/td>\n<\/tr>\n<tr>\n<td>Temperature out by a couple of degrees<\/td>\n<td>Within the sensor\u2019s stated accuracy<\/td>\n<td>Use a DS18B20 if you need better<\/td>\n<\/tr>\n<tr>\n<td>Values fine indoors, wrong in the sun<\/td>\n<td>Direct sunlight heats the housing<\/td>\n<td>Shade the sensor, keep air moving<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Next steps<\/h2>\n<ul>\n<li><strong>Easier first:<\/strong> <em>Installing and Managing Libraries<\/em>, if the library step was the difficult part.<\/li>\n<li><strong>Related product:<\/strong> the DHT22, for decimals and a wider range, or the DS18B20 for accurate temperature alone.<\/li>\n<li><strong>Next project:<\/strong> add the I2C LCD and build a mini weather station that shows both readings without a computer attached.<\/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>DHT11 datasheet, for ranges, accuracy and the minimum interval between readings.<\/li>\n<li>Adafruit DHT sensor library documentation, for the function names and the unified sensor dependency. The library is linked rather than reproduced, and no library code appears here.<\/li>\n<\/ul>\n<p>Pin ordering and labelling differ between suppliers of this module, so the tutorial directs the reader to the printing on their own board. 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 DHT11 measures air temperature and relative humidity and reports both as digital values. It does its own measuring and converting, so you receive numbers rather than a voltage to interpret.<\/p>\n","protected":false},"featured_media":0,"template":"","siratek_tutorial_level":[],"class_list":["post-52219","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>Read Temperature and Humidity with 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\/dht11-temperature-humidity\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Read Temperature and Humidity with DHT11 - siratek\" \/>\n<meta property=\"og:description\" content=\"The DHT11 measures air temperature and relative humidity and reports both as digital values. It does its own measuring and converting, so you receive numbers rather than a voltage to interpret.\" \/>\n<meta property=\"og:url\" content=\"http:\/\/siratek.net\/index.php\/tutorials\/dht11-temperature-humidity\/\" \/>\n<meta property=\"og:site_name\" content=\"siratek\" \/>\n<meta property=\"og:image\" content=\"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/dht11-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=\"7 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\\\/dht11-temperature-humidity\\\/\",\"url\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/dht11-temperature-humidity\\\/\",\"name\":\"Read Temperature and Humidity with DHT11 - siratek\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/siratek.net\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/dht11-temperature-humidity\\\/#primaryimage\"},\"image\":{\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/dht11-temperature-humidity\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/siratek.net\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/dht11-temperature-humidity-wiring.svg\",\"datePublished\":\"2026-11-01T10:50:40+00:00\",\"breadcrumb\":{\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/dht11-temperature-humidity\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/dht11-temperature-humidity\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/dht11-temperature-humidity\\\/#primaryimage\",\"url\":\"https:\\\/\\\/siratek.net\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/dht11-temperature-humidity-wiring.svg\",\"contentUrl\":\"https:\\\/\\\/siratek.net\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/dht11-temperature-humidity-wiring.svg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/dht11-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\":\"Read Temperature and Humidity with 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":"Read Temperature and Humidity with 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\/dht11-temperature-humidity\/","og_locale":"en_US","og_type":"article","og_title":"Read Temperature and Humidity with DHT11 - siratek","og_description":"The DHT11 measures air temperature and relative humidity and reports both as digital values. It does its own measuring and converting, so you receive numbers rather than a voltage to interpret.","og_url":"http:\/\/siratek.net\/index.php\/tutorials\/dht11-temperature-humidity\/","og_site_name":"siratek","og_image":[{"url":"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/dht11-temperature-humidity-wiring.svg","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/siratek.net\/index.php\/tutorials\/dht11-temperature-humidity\/","url":"http:\/\/siratek.net\/index.php\/tutorials\/dht11-temperature-humidity\/","name":"Read Temperature and Humidity with DHT11 - siratek","isPartOf":{"@id":"https:\/\/siratek.net\/#website"},"primaryImageOfPage":{"@id":"http:\/\/siratek.net\/index.php\/tutorials\/dht11-temperature-humidity\/#primaryimage"},"image":{"@id":"http:\/\/siratek.net\/index.php\/tutorials\/dht11-temperature-humidity\/#primaryimage"},"thumbnailUrl":"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/dht11-temperature-humidity-wiring.svg","datePublished":"2026-11-01T10:50:40+00:00","breadcrumb":{"@id":"http:\/\/siratek.net\/index.php\/tutorials\/dht11-temperature-humidity\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/siratek.net\/index.php\/tutorials\/dht11-temperature-humidity\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/siratek.net\/index.php\/tutorials\/dht11-temperature-humidity\/#primaryimage","url":"https:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/dht11-temperature-humidity-wiring.svg","contentUrl":"https:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/dht11-temperature-humidity-wiring.svg"},{"@type":"BreadcrumbList","@id":"http:\/\/siratek.net\/index.php\/tutorials\/dht11-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":"Read Temperature and Humidity with 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\/52219","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\/52219\/revisions"}],"wp:attachment":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/media?parent=52219"}],"wp:term":[{"taxonomy":"siratek_tutorial_level","embeddable":true,"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial_level?post=52219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}