<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>humidity Archives | Microcontroller Tutorials</title>
	<atom:link href="https://www.teachmemicro.com/tag/humidity/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.teachmemicro.com/tag/humidity/</link>
	<description>Microcontroller Tutorials and Resources</description>
	<lastBuildDate>Sun, 15 Oct 2023 21:55:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.2</generator>

<image>
	<url>https://www.teachmemicro.com/wp-content/uploads/2019/04/blue-icon-65x65.png</url>
	<title>humidity Archives | Microcontroller Tutorials</title>
	<link>https://www.teachmemicro.com/tag/humidity/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>ESP8266 NodeMCU DHT22 Interfacing Tutorial</title>
		<link>https://www.teachmemicro.com/nodemcu-esp8266-dht22-interfacing/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=nodemcu-esp8266-dht22-interfacing</link>
					<comments>https://www.teachmemicro.com/nodemcu-esp8266-dht22-interfacing/#comments</comments>
		
		<dc:creator><![CDATA[Roland Pelayo]]></dc:creator>
		<pubDate>Sun, 05 May 2019 03:33:31 +0000</pubDate>
				<category><![CDATA[ESP8266 Tutorial]]></category>
		<category><![CDATA[humidity]]></category>
		<category><![CDATA[iot]]></category>
		<category><![CDATA[temperature]]></category>
		<guid isPermaLink="false">https://www.teachmemicro.com/?p=3318</guid>

					<description><![CDATA[<p>The DHT22 is a temperature and humidity sensor in one package. It is widely used mainly due to its price but also because of it being robust and user-friendly. In this NodeMCU DHT22 interfacing tutorial, I will guide you in creating an IoT-based weather monitoring project with ESP8266. Introduction The DHT22 is an upgrade over &#8230;</p>
<p>The post <a href="https://www.teachmemicro.com/nodemcu-esp8266-dht22-interfacing/">ESP8266 NodeMCU DHT22 Interfacing Tutorial</a> appeared first on <a href="https://www.teachmemicro.com">Microcontroller Tutorials</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="https://www.teachmemicro.com/wp-content/uploads/2019/05/nodemcu-dht22-featured.jpg"><img loading="lazy" decoding="async" class="wp-image-3314 aligncenter" src="https://www.teachmemicro.com/wp-content/uploads/2019/05/nodemcu-dht22-featured.jpg" alt="NodeMCU DHT22" width="600" height="450" srcset="https://www.teachmemicro.com/wp-content/uploads/2019/05/nodemcu-dht22-featured.jpg 800w, https://www.teachmemicro.com/wp-content/uploads/2019/05/nodemcu-dht22-featured-300x225.jpg 300w, https://www.teachmemicro.com/wp-content/uploads/2019/05/nodemcu-dht22-featured-768x576.jpg 768w, https://www.teachmemicro.com/wp-content/uploads/2019/05/nodemcu-dht22-featured-320x240.jpg 320w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a></p>
<p>The DHT22 is a temperature and humidity sensor in one package. It is widely used mainly due to its price but also because of it being robust and user-friendly. In this NodeMCU DHT22 interfacing tutorial, I will guide you in creating an IoT-based weather monitoring project with <a href="https://www.win-source.net/products/detail/espressif/esp8266ex.html">ESP8266</a>.</p>
<p><span id="more-3318"></span></p>
<h3><strong>Introduction</strong></h3>
<p>The DHT22 is an upgrade over the DHT11. The upgrade, in this sense, is on the temperature and humidity range and sampling rate. The table below summarizes the difference between the DHT11 and DHT22.</p>
<table>
<tbody>
<tr>
<th>Parameter</th>
<th>DHT11</th>
<th>DHT22</th>
</tr>
<tr>
<td>Temperature Range</td>
<td>0 to 50°C</td>
<td>-40 to 125°C</td>
</tr>
<tr>
<td>Humidity Range</td>
<td>20 to 80%</td>
<td>0 to 100%</td>
</tr>
<tr>
<td>Sampling Rate</td>
<td>Once a second</td>
<td>Twice a second</td>
</tr>
<tr>
<td>Dimension</td>
<td>15.5mm x 12mm x 5.5mm</td>
<td>15.1mm x 25mm x 7.7mm</td>
</tr>
</tbody>
</table>
<p>Like its predecessor, the DHT22 contains only three usable pins: VCC, DOUT and GND.</p>
<p><a href="https://www.teachmemicro.com/wp-content/uploads/2019/05/nodemcu-dht22-solo-e1557025418849.jpg"><img loading="lazy" decoding="async" class="size-full wp-image-3316 aligncenter" src="https://www.teachmemicro.com/wp-content/uploads/2019/05/nodemcu-dht22-solo-e1557025418849.jpg" alt="NodeMCU DHT22" width="600" height="481" /></a></p>
<p>Depending on your chosen module, the DHT22 requires a <strong>pull-up resistor of 10k on its DOUT pin</strong>. The DHT22 module by DFRobot as pictured does not require any pull-up resistor. See <a href="https://www.teachmemicro.com/how-dht22-sensor-works/">more information about the DHT22</a>.</p>
<h3><strong>NodeMCU DHT22 Interfacing</strong></h3>
<p>The DOUT pin connects to any digital pin of the NodeMCU. As mentioned, a 10k pull-up resistor on the DOUt pin is necessary except if you own DFRobot’s module. The VCC pin and GND pin connect to the 3.3V pin and GND pin of the NodeMCU respectively.</p>
<p>We will use the following diagram for the rest of the tutorial:</p>
<p><a href="https://www.teachmemicro.com/wp-content/uploads/2019/05/nodemcu-dht22-fritzing.jpg"><img loading="lazy" decoding="async" class=" wp-image-3317 aligncenter" src="https://www.teachmemicro.com/wp-content/uploads/2019/05/nodemcu-dht22-fritzing.jpg" alt="NodeMCU DHT22 Fritzing diagram" width="553" height="386" /></a></p>
<table>
<tbody>
<tr>
<th>DHT22 Pin</th>
<th>NodeMCU Pin</th>
</tr>
<tr>
<td>VCC</td>
<td>3.3V</td>
</tr>
<tr>
<td>DOUT</td>
<td>D2</td>
</tr>
<tr>
<td>GND</td>
<td>GND</td>
</tr>
</tbody>
</table>
<p>We will be using the <a href="https://www.teachmemicro.com/intro-nodemcu-arduino/">Arduino IDE to program our NodeMCU</a>. As for the sketch, using the <a href="https://github.com/winlinvip/SimpleDHT">Simple DHT library</a> makes our work shorter. The library comes with a basic example which we can use to test if the DHT22 to NodeMCU interface is correct:</p>
<pre class="lang:arduino decode:true "><pre><code class="language-cpp">#include &lt;SimpleDHT.h&gt;

// for DHT11, 
//      VCC: 5V or 3V
//      GND: GND
//      DATA: 2
int pinDHT22 = 2;
SimpleDHT11 dht11(pinDHT11);

void setup() {
  Serial.begin(115200);
}

void loop() {
  // start working...
  Serial.println(&quot;=================================&quot;);
  Serial.println(&quot;Sample DHT11...&quot;);
  
  // read without samples.
  byte temperature = 0;
  byte humidity = 0;
  int err = SimpleDHTErrSuccess;
  if ((err = dht11.read(&amp;temperature, &amp;humidity, NULL)) != SimpleDHTErrSuccess) {
    Serial.print(&quot;Read DHT11 failed, err=&quot;); Serial.println(err);delay(1000);
    return;
  }
  
  Serial.print(&quot;Sample OK: &quot;);
  Serial.print((int)temperature); Serial.print(&quot; *C, &quot;); 
  Serial.print((int)humidity); Serial.println(&quot; H&quot;);
  
  // DHT11 sampling rate is 1HZ.
  delay(1500);
}</code></pre></pre>
<p>Upload the sketch, open the serial monitor and the humidity and temperature readings should appear.</p>
<h3><strong>IoT Weather Monitor</strong></h3>
<p>Now that we have successfully read both temperature and humidity from the DHT22, it is time to make a simple IoT weather monitor.</p>
<p>We will modify the sketch in the <a href="https://www.teachmemicro.com/nodemcu-ajax-dynamic-sensor-data-web-page/">NodeMCU AJAX tutorial</a> to display both temperature and humidity in a web page. Using AJAX here would be great because we want the temperature and humidity in real-time.</p>
<pre class="lang:arduino decode:true "><pre><code class="language-cpp">#include &lt;ESP8266WiFi.h&gt;
#include &lt;WiFiClient.h&gt;
#include &lt;ESP8266WebServer.h&gt;
#include &lt;SimpleDHT.h&gt;

int pinDHT22 = 2;
SimpleDHT11 dht11(pinDHT11);

// Replace with your network credentials
const char* ssid = &quot;&lt;Your-WiFi-SSID&gt;&quot;;
const char* password = &quot;&lt;Your-WiFi-Password&gt;&quot;;
ESP8266WebServer server(80);   //instantiate server at port 80 (http port)

String page = &quot;&quot;;
String text = &quot;&quot;;
double data;

void setup(void){
 pinMode(A0, INPUT);
 delay(1000);
 Serial.begin(115200);
 WiFi.begin(ssid, password); //begin WiFi connection
 Serial.println(&quot;&quot;);

 // Wait for connection
 while (WiFi.status() != WL_CONNECTED) {
 delay(500);
 Serial.print(&quot;.&quot;);
}

 Serial.println(&quot;&quot;);
 Serial.print(&quot;Connected to &quot;);
 Serial.println(ssid);
 Serial.print(&quot;IP address: &quot;);
 Serial.println(WiFi.localIP());
 server.on(&quot;/data.txt&quot;, [](){
   text = (String)data;
   server.send(200, &quot;text/html&quot;, text);
 });
 server.on(&quot;/&quot;, [](){
   page = &quot;&lt;h1&gt;NodeMCU IoT Weather Monitor&lt;/h1&gt;&lt;h1&gt;Data:&lt;/h1&gt; &lt;h1 id=\&quot;data\&quot;&gt;&quot;&quot;&lt;/h1&gt;\r\n&quot;;
   page += &quot;&lt;script&gt;\r\n&quot;;
   page += &quot;var x = setInterval(function() {loadData(\&quot;data.txt\&quot;,updateData)}, 1000);\r\n&quot;;
   page += &quot;function loadData(url, callback){\r\n&quot;;
   page += &quot;var xhttp = new XMLHttpRequest();\r\n&quot;;
   page += &quot;xhttp.onreadystatechange = function(){\r\n&quot;;
   page += &quot; if(this.readyState == 4 &amp;&amp; this.status == 200){\r\n&quot;;
   page += &quot; callback.apply(xhttp);\r\n&quot;;
   page += &quot; }\r\n&quot;;
   page += &quot;};\r\n&quot;;
   page += &quot;xhttp.open(\&quot;GET\&quot;, url, true);\r\n&quot;;
   page += &quot;xhttp.send();\r\n&quot;;
   page += &quot;}\r\n&quot;;
   page += &quot;function updateData(){\r\n&quot;;
   page += &quot; document.getElementById(\&quot;data\&quot;).innerHTML = this.responseText;\r\n&quot;;
   page += &quot;}\r\n&quot;;
   page += &quot;&lt;/script&gt;\r\n&quot;;
   server.send(200, &quot;text/html&quot;, page);
});

 server.begin();
 Serial.println(&quot;Web server started!&quot;);
}

void loop(void){
 byte temperature = 0;
 byte humidity = 0;
 int err = SimpleDHTErrSuccess;
 if ((err = dht11.read(&amp;temperature, &amp;humidity, NULL)) != SimpleDHTErrSuccess) {
    Serial.print(&quot;Read DHT11 failed, err=&quot;); Serial.println(err);delay(1000);
    return;
 }
  
 data += (int)temperature + &quot; *C &quot; + (int)humidity + &quot; H&quot;; 
  
 delay(1500);
 server.handleClient();
}</code></pre></pre>
<p>Upload the sketch above to your NodeMCU and open the serial monitor to acquire the IP address of your device. Don’t forget to supply your own WiFi SSID and password on lines 10 and 11.</p>
<p>Using your preferred browser, visit the IP address as seen on the serial monitor. The temperature and humidity are now visible and updated in real-time.</p>
<p>&nbsp;</p>
<p>The post <a href="https://www.teachmemicro.com/nodemcu-esp8266-dht22-interfacing/">ESP8266 NodeMCU DHT22 Interfacing Tutorial</a> appeared first on <a href="https://www.teachmemicro.com">Microcontroller Tutorials</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.teachmemicro.com/nodemcu-esp8266-dht22-interfacing/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 

Served from: www.teachmemicro.com @ 2026-07-25 22:36:56 by W3 Total Cache
-->