{"id":628,"date":"2018-08-19T17:05:25","date_gmt":"2018-08-19T09:05:25","guid":{"rendered":"https:\/\/www.techcoil.com\/blog\/?p=628"},"modified":"2019-11-14T14:40:52","modified_gmt":"2019-11-14T06:40:52","slug":"how-to-read-temperature-and-humidity-from-a-dht11-sensor-that-is-connected-to-a-raspberry-pi-3","status":"publish","type":"post","link":"https:\/\/www.techcoil.com\/blog\/how-to-read-temperature-and-humidity-from-a-dht11-sensor-that-is-connected-to-a-raspberry-pi-3\/","title":{"rendered":"How to read temperature and humidity from a DHT11 sensor that is connected to a Raspberry Pi 3"},"content":{"rendered":"<p>I had always wanted to measure the temperature and humidity of the environment where my herbs are grown at.<\/p>\n<p>Since I had a few pieces of <a href=\"https:\/\/www.amazon.com\/ELEMENT-Element14-Raspberry-Pi-Motherboard\/dp\/B07BDR5PDW\/ref=as_li_ss_tl?ie=UTF8&linkCode=ll1&tag=clivsperswebs-20&linkId=20e5d714fa105ed5776d87eb6b0eeca9&language=en_US\" rel=\"noopener noreferrer\" target=\"_blank\">Raspberry Pi 3<\/a> lying around the house, I decided to use one of them to measure the temperature and humidity of the area of the house where my herbs are.<\/p>\n<p>An additional sensor is required to measure the temperature and humidity of the environment. Therefore, I went to <a href=\"http:\/\/s.click.aliexpress.com\/e\/c4qVZsBe\" rel=\"noopener noreferrer\" target=\"_blank\">AliExpress<\/a> and got a <a href=\"http:\/\/s.click.aliexpress.com\/e\/1Vl9x0k\" rel=\"noopener noreferrer\" target=\"_blank\">DHT11 sensor<\/a>. By connecting a DHT11 sensor to my Raspberry Pi 3, I can give it the ability to read the temperature and humidity of its environment.<\/p>\n<p>Given these points, I created this post to show how to read temperature and humidity from a DHT11 sensor that is connected to a Raspberry Pi 3.<\/p>\n<p>In order for us to check the temperature and humidity from the DHT11 sensor, we will build a simple Flask application that returns the temperature and humidity values as HTTP responses to HTTP clients.<\/p>\n<h2>Recommended bill of materials<\/h2>\n<p>In case you need it, here are the <a href=\"https:\/\/www.techcoil.com\/raspberry-pi-3-buying-guide\/\" rel=\"noopener noreferrer\" target=\"_blank\">things that you can buy for a Raspberry Pi 3 project<\/a> like this one:<\/p>\n<h3><a href=\"https:\/\/www.amazon.com\/ref=as_li_ss_tl?ie=UTF8&linkCode=ll2&tag=clivsperswebs-20&linkId=522c40343c0cbaaffb3b2c9ddd043653&language=en_US\" rel=\"noopener noreferrer\" target=\"_blank\">From Amazon<\/a><\/h3>\n<ul>\n<li><a href=\"https:\/\/www.amazon.com\/CanaKit-Raspberry-Power-Supply-Listed\/dp\/B07BC6WH7V\/ref=as_li_ss_tl?ie=UTF8&linkCode=ll1&tag=clivsperswebs-20&linkId=93e416c849f934c6b7cc8ff1648098c2\" rel=\"noopener noreferrer\" target=\"_blank\">CanaKit Raspberry Pi 3 B+ (B Plus) with 2.5A Power Supply (UL Listed)<\/a><\/li>\n<li><a href=\"https:\/\/www.amazon.com\/Sandisk-Ultra-Micro-UHS-I-Adapter\/dp\/B073JWXGNT\/\/ref=as_li_ss_tl?ie=UTF8&linkCode=ll1&tag=clivsperswebs-20&linkId=f1a242a1e4d5eba8dea23f1007ef067b\" rel=\"noopener noreferrer\" target=\"_blank\">Sandisk Ultra 32GB Micro SDHC UHS-I Card with Adapter<\/a><\/li>\n<li><a href=\"https:\/\/www.amazon.com\/Official-Original-Raspberry-Model-White\/dp\/B01CCPKCSK\/ref=as_li_ss_tl?&imprToken=tCbs8mgp8f2f4SwcP0EdCA&slotNum=22&ie=UTF8&qid=1520171364&sr=8-1&linkCode=ll1&tag=clivsperswebs-20&linkId=a07a33c3f7db1e0d9c4cb8d1987b11bb\" rel=\"noopener noreferrer\" target=\"_blank\">Official Raspberry Pi 3 Case - Red\/White<\/a> (Optional)<\/li>\n<\/ul>\n<form action=\"https:\/\/www.amazon.com\/gp\/aws\/cart\/add.html\" method=\"GET\" target=\"_blank\"><input name=\"AssociateTag\" type=\"hidden\" value=\"clivsperswebs-20\"><input name=\"SubscriptionId\" type=\"hidden\" value=\"[AKIAIMND5UBCQU2HRSUA]\"><input name=\"ASIN.1\" type=\"hidden\" value=\"B07BC6WH7V\"><input name=\"Quantity.1\" type=\"hidden\" value=\"1\"><input name=\"ASIN.2\" type=\"hidden\" value=\"B073JWXGNT\"><input name=\"Quantity.2\" type=\"hidden\" value=\"1\"><input name=\"ASIN.3\" type=\"hidden\" value=\"B01CCPKCSK\"><input name=\"Quantity.3\" type=\"hidden\" value=\"1\"><br \/>\n<input class=\"external_link\" type=\"submit\" alt=\"Buy from Amazon.com\" name=\"add\" value=\"Add these items to your Amazon cart\"><\/form>\n<p><a href=\"http:\/\/s.click.aliexpress.com\/e\/c1kEz6rQ\" rel=\"noopener noreferrer\" target=\"_blank\">From Aliexpress<\/a><\/p>\n<ul>\n<li><a href=\"http:\/\/s.click.aliexpress.com\/e\/ckXJW2nW\" rel=\"noopener noreferrer\" target=\"_blank\">DHT11 Temperature and Relative Humidity Sensor Module for Arduino \/ Raspberry Pi<\/a><\/li>\n<li><a href=\"http:\/\/s.click.aliexpress.com\/e\/b1IZnqVE\" rel=\"noopener noreferrer\" target=\"_blank\">40PCS 20cm 1P-1P Female To Female Jumper Wire Dupont Cable<\/a><\/li>\n<\/ul>\n<h2>Identifying the pins of your DHT11 sensor<\/h2>\n<p>Let's have a closer look at the DHT11 sensor that I had gotten from Aliexpress:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/DHT11-Sensor-with-s-and-markings.jpg\" alt=\"DHT11 Sensor with s and - markings\"><\/p>\n<p>Notice that the leftmost pin is marked with a <strong>s<\/strong> and the rightmost is marked with a <strong>-<\/strong>. In this case, the <strong>s<\/strong> stands for <strong>Signal<\/strong> and the <strong>-<\/strong> stands for <strong>ground<\/strong>. Therefore, the leftmost pin should be connected to a GPIO pin, the middle pin should be connected to a 5v pin and the rightmost pin should be connected to a ground pin.<\/p>\n<p>Let's look at another type of pin arrangement that is evident on the <a href=\"https:\/\/www.amazon.com\/Digital-Humidity-Temperature-Sensor-FREE-Arduino-Raspberry\/dp\/B078M77M9P\/ref=as_li_ss_tl?ie=UTF8&linkCode=ll1&tag=clivsperswebs-20&linkId=a9810ded187adccf44ac75030f81c55e&language=en_US\" rel=\"noopener noreferrer\" target=\"_blank\">Refaxi DHT11 Digital Module Humidity Temperature Sensor<\/a>:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/DHT11-Sensor-with-and-markings.jpg\" alt=\"DHT11 Sensor with + and - markings\"><\/p>\n<p>In this case, the leftmost pin is marked with a <strong>+<\/strong> and the rightmost is marked with a <strong>-<\/strong>. Therefore, the leftmost pin should be connected to a 5v pin, the middle pin should be connected to a GPIO pin and the rightmost pin should be connected to a ground pin.<\/p>\n<p><strong>This tutorial will be based on the <a href=\"http:\/\/s.click.aliexpress.com\/e\/ckXJW2nW\" rel=\"noopener noreferrer\" target=\"_blank\">DHT11 sensor that I had gotten from Aliexpress<\/a>.<\/strong><\/p>\n<h2>Connect your Raspberry Pi 3 to your DHT11 sensor<\/h2>\n<p>Let's have a look at the DHT11 sensor that I gotten from Aliexpress again:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/DHT11-Sensor-with-s-and-markings.jpg\" alt=\"DHT11 Sensor with s and - markings\"><\/p>\n<p>Notice that I had connected three female to female jumper wires to the pins. The brown one is for the Raspberry Pi 3 to read from, the red one is to supply 5v to the DHT11 sensor and the black one is for grounding.<\/p>\n<p>Once I had connected the female to female jumper wires to the DHT11 sensor, I proceeded to connect the other ends of the wires to the GPIO pins on a Raspberry Pi 3:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/Raspberry-Pi-3-Model-B-with-three-jumper-wires-connected-to-GPIO-4-5v-and-Ground.jpg\" alt=\"Raspberry Pi 3 Model B+ with three jumper wires connected to GPIO 4, 5v and Ground\"><\/p>\n<p>The signal pin of the DHT11 is connected to <strong>GPIO 4<\/strong>, the middle pin is connected to a 5v pin and the rightmost pin is connected to a ground pin on the Raspberry Pi 3.<\/p>\n<p>Putting everything in an image, the entire setup for this tutorial looks like this:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/Raspberry-Pi-Model-3-B-connected-to-DHT11-sensor.jpg\" alt=\"Raspberry Pi Model 3 B+ connected to DHT11 sensor\"><\/p>\n<p>Your setup should look similar to mine. If you want to try to connect your DHT11 sensor to other GPIO pins, you can <a href=\"https:\/\/www.techcoil.com\/blog\/helpful-gpio-pinout-resources-that-you-can-reference-while-connecting-sensors-to-your-raspberry-pi-3\/\" rel=\"noopener noreferrer\" target=\"_blank\">checkout these GPIO Pinout resources<\/a> to help you do so.<\/p>\n<h2>Setting up Raspbian Stretch Lite with SSH server enabled on your microSD card<\/h2>\n<p>Once you had connected your DHT11 sensor to your Raspberry Pi 3, proceed to <a href=\"https:\/\/www.techcoil.com\/blog\/how-to-setup-raspbian-stretch-lite-with-ssh-server-enabled-on-your-microsd-card\/\" rel=\"noopener noreferrer\" target=\"_blank\">setup Raspbian Stretch Lite with SSH server enabled on your microSD card<\/a>. Doing so will allow you to SSH into your Raspbian Stretch Lite to perform further configurations in this post.<\/p>\n<h2>Starting the Raspbian Stretch Lite operating system<\/h2>\n<p>Next, connect one end of the RJ45 cable to the RJ45 port on the Raspberry Pi 3 board and the other end of the cable to one of the switch port of your home router. After that, connect the micro USB power supply to the Raspberry Pi 3 board and a wall socket. Turn on the power socket to supply power to the Raspberry Pi 3 board.<\/p>\n<h2>Getting into Raspbian Stretch Lite and updating it<\/h2>\n<p>After you had started your Raspbian Stretch Lite, SSH into your Raspberry Pi 3 with a computer that is connected to the same network as your Raspberry Pi 3.<\/p>\n<p>Suppose your router had given your Raspberry Pi 3 <strong>192.168.1.123<\/strong> as the IP address, you will run the following command from your terminal program to get into Raspbian Stretch Lite:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nssh pi@192.168.1.123\r\n<\/pre>\n<p>When Raspbian Stretch Lite prompts for a password, enter <strong>raspberry<\/strong>.<\/p>\n<p>Once you had gotten into Raspbian Stretch Lite, run the following command to update it:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo apt-get update\r\n<\/pre>\n<h2>Installing Virtualenv on Raspbian Stretch Lite<\/h2>\n<p><a href=\"https:\/\/virtualenv.pypa.io\/\" rel=\"noopener noreferrer\" target=\"_blank\">Virtualenv<\/a> is a tool that allows us to create isolated environments in the same machine. This is useful when you have to run multiple applications with conflicting python dependencies on your Raspberry Pi 3.<\/p>\n<p>Therefore to be able to use the same Raspberry Pi 3 to try out other projects, we will be using Virtualenv to create an environment to run our Python 3 Flask application.<\/p>\n<p>To install Virtualenv, run the following command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo apt-get install virtualenv -y\r\n<\/pre>\n<h2>Installing Supervisor<\/h2>\n<p>When we want our Python 3 Flask application to start at boot time and constantly listen for HTTP requests to serve, we can use <a href=\"http:\/\/supervisord.org\/\" rel=\"noopener noreferrer\" target=\"_blank\">Supervisor<\/a> to help us monitor and control the process that will run our Python 3 Flask application.<\/p>\n<p>In order to install Supervisor, we need to run the following command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo apt-get install supervisor -y\r\n<\/pre>\n<h2>Coding a Python 3 Flask application that read from the DHT11 sensor on a Raspberry Pi 3<\/h2>\n<p>Once we had installed all the needed components on our Raspbian Stretch Lite, we can proceed to create a simple Python 3 Flask application.<\/p>\n<p>To keep things simple, let's create a Python 3 Flask application with a route for the root endpoint.<\/p>\n<p>Whenever a HTTP request is received at that endpoint, the application will read the humidity and temperature from the DHT11 sensor and create a HTTP response containing those values back to the client.<\/p>\n<p>Given these points, let's use <code>nano<\/code> to create a Python 3 script at <code>\/home\/pi\/run.py<\/code>:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nnano \/home\/pi\/run.py\r\n<\/pre>\n<p>Once the editor starts, copy the following Python 3 codes into the editor:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nfrom flask import Flask, jsonify\r\nimport Adafruit_DHT\r\n\r\napp = Flask(__name__)\r\n\r\n@app.route('\/')\r\ndef get_humidity_and_temperature_from_DHT11():\r\n    humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, 4)\r\n    return jsonify({'humidity': humidity, 'temperature': temperature})\r\n\r\napp.run(host='0.0.0.0', port='12345')\r\n\r\n<\/pre>\n<p>After that, type <strong>Ctrl-X<\/strong> and then <strong>Y<\/strong> to save the file.<\/p>\n<p>In the Python 3 script, we first import the libraries that we are going to use. After that, we create an instance of <a href=\"http:\/\/flask.pocoo.org\/docs\/1.0\/api\/#application-object\" rel=\"noopener noreferrer\" target=\"_blank\">Flask<\/a> for building the web server.<\/p>\n<h3>Indicating the function to call for HTTP GET requests made to the root endpoint<\/h3>\n<p>After that, we decorate a function, <code>get_humidity_and_temperature_from_DHT11<\/code>, with @app.route('\/') to indicate to Flask that <code>get_humidity_and_temperature_from_DHT11<\/code> should be called for HTTP GET requests made to the root endpoint.<\/p>\n<h3>Getting the humidity and temperature values from the DHT11 sensor<\/h3>\n<p>Inside <code>get_humidity_and_temperature_from_DHT11<\/code>, we use the <a href=\"https:\/\/github.com\/adafruit\/Adafruit_Python_DHT\" rel=\"noopener noreferrer\" target=\"_blank\">Adafruit_DHT<\/a> library to read the humidity and temperature from a DHT11 sensor at <strong>GPIO 4<\/strong>.<\/p>\n<p>Lastly, we return the humidity and temperature values as a JSON response.<\/p>\n<h3>Starting the Flask web server to listen at port 12345<\/h3>\n<p>The last line of the Python 3 script starts the Flask web server and makes it listen for HTTP requests at port <strong>12345<\/strong>.<\/p>\n<h2>Creating a virtual environment to run your Python 3 Flask application<\/h2>\n<p>Next, let's create a virtual environment to run the Python 3 Flask application. In order to do so, we will run the following command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nvirtualenv -p python3 \/home\/pi\/rpi-dht11-flask-env\r\n<\/pre>\n<p>After that, we get into the virtual environment by running the following command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsource \/home\/pi\/rpi-dht11-flask-env\/bin\/activate\r\n<\/pre>\n<p>Once you gotten into the virtual environment, run the following commands to install the Python dependencies for the Python 3 Flask application:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\npip install Flask==1.0.2 Adafruit-DHT==1.3.4\r\n<\/pre>\n<p>After <code>pip<\/code> finishes the installations, you will be able to run your Python 3 Flask application within the virtual environment.<\/p>\n<h2>Testing your Python 3 Flask application<\/h2>\n<p>Once you had installed the Python dependencies for your Python 3 Flask application, you can run it with the following commands:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncd \/home\/pi\r\npython run.py\r\n<\/pre>\n<p>You will notice that after you ran the commands, the terminal pauses. This meant that your Flask application is ready to serve HTTP GET requests to the root endpoint.<\/p>\n<p>Next, use a web browser from your work computer to access the IP address of your Raspberry Pi 3. For example, if the IP address of your Raspberry Pi 3 is <strong> 192.168.1.123<\/strong>, you will type in <strong>http:\/\/192.168.1.123:12345<\/strong> into the location bar of your web browser.<\/p>\n<p>After you had done so, your browser will receive a JSON object that tells you the humidity and temperature of the environment that your Raspberry Pi 3 is located at.<\/p>\n<h2>Running the Python 3 Flask application as a background process when your Raspberry Pi 3 powers on<\/h2>\n<p>When you want your Python 3 Flask application to run whenever your Raspberry Pi 3 is turned on, you can depend on Supervisor. This section will show how to get Supervisor to run your Python 3 Flask application whenever your Raspberry Pi 3 is turned on.<\/p>\n<p>Firstly, let's create a shell script that will activate the virtual environment that we had created earlier and run our Python 3 Flask application within that virtual environment.<\/p>\n<p>To do so, we use nano to create a shell script at \/home\/pi\/run.sh<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nnano \/home\/pi\/run.sh\r\n<\/pre>\n<p>Once the editor loads, write the following content into the editor:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n!#\/bin\/bash\r\nsource .\/rpi-dht11-flask-env\/bin\/activate\r\npython run.py\r\ndeactivate\r\n<\/pre>\n<p>After you had included the content, type <strong>Ctrl-X<\/strong> and then <strong>Y<\/strong> to save the file.<\/p>\n<p>Afterwards, make the shell script executable by running the following command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo chmod 744 \/home\/pi\/run.sh\r\n<\/pre>\n<p>To get Supervisor to start our Python 3 Flask application so that we can check the humidity and temperature with our Raspberry Pi 3, we first create a configuration file at <code>\/etc\/supervisor\/conf.d\/rpi-dht11-flask-app.conf<\/code>:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo nano \/etc\/supervisor\/conf.d\/rpi-dht11-flask-app.conf\r\n<\/pre>\n<p>After <code>nano<\/code> loads, copy the following configuration codes into the editor:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&#x5B;program:rpi-dht11-flask-app]\r\ndirectory=\/home\/pi\r\ncommand=\/bin\/bash -E -c .\/run.sh\r\nautostart=true\r\nautorestart=true\r\nstopsignal=INT\r\nstopasgroup=true\r\nkillasgroup=true\r\nuser=pi\r\n<\/pre>\n<p>Once you had written the configurations into the editor, run the following command to restart Supervisor:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo systemctl restart supervisor.service\r\n<\/pre>\n<p>When Supervisor runs again, it will take the configurations that you had created earlier and run your Python 3 Flask application.<\/p>\n<p>With that, whenever you power on your Raspberry Pi 3, you will be able check the humidity and temperature with your Raspberry Pi 3.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/How-to-read-temperature-and-humidity-from-a-DHT11-sensor-that-is-connected-to-a-Raspberry-Pi-3.jpg\" alt=\"How to read temperature and humidity from a DHT11 sensor that is connected to a Raspberry Pi 3\"><\/p>\n\n      <ul id=\"social-sharing-buttons-list\">\n        <li class=\"facebook\">\n          <a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fwp.me%2Fp245TQ-a8\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n            <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Facebook.png\" alt=\"Facebook icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"twitter\">\n          <a href=\"https:\/\/twitter.com\/intent\/tweet?text=&url=https%3A%2F%2Fwp.me%2Fp245TQ-a8&via=Techcoil_com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Twitter.png\" alt=\"Twitter icon\"> Tweet\n          <\/a>\n        <\/li>\n        <li class=\"linkedin\">\n          <a href=\"https:\/\/www.linkedin.com\/shareArticle?mini=1&title=&url=https%3A%2F%2Fwp.me%2Fp245TQ-a8&source=https:\/\/www.techcoil.com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/linkedin.png\" alt=\"Linkedin icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"pinterest\">\n          <a href=\"https:\/\/pinterest.com\/pin\/create\/button\/?url=https%3A%2F%2Fwww.techcoil.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F628&description=\" class=\"pin-it-button\" target=\"_blank\" role=\"button\" rel=\"nofollow\" count-layout=\"horizontal\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Pinterest.png\" alt=\"Pinterest icon\"> Save\n          <\/a>\n        <\/li>\n      <\/ul>\n    ","protected":false},"excerpt":{"rendered":"<p>I had always wanted to measure the temperature and humidity of the environment where my herbs are grown at.<\/p>\n<p>Since I had a few pieces of <a href=\"https:\/\/www.amazon.com\/ELEMENT-Element14-Raspberry-Pi-Motherboard\/dp\/B07BDR5PDW\/ref=as_li_ss_tl?ie=UTF8&#038;linkCode=ll1&#038;tag=clivsperswebs-20&#038;linkId=20e5d714fa105ed5776d87eb6b0eeca9&#038;language=en_US\" rel=\"noopener noreferrer\" target=\"_blank\">Raspberry Pi 3<\/a> lying around the house, I decided to use one of them to measure the temperature and humidity of the area of the house where my herbs are. <\/p>\n<p>An additional sensor is required to measure the temperature and humidity of the environment. Therefore, I went to <a href=\"http:\/\/s.click.aliexpress.com\/e\/c4qVZsBe\" rel=\"noopener noreferrer\" target=\"_blank\">AliExpress<\/a> and got a <a href=\"http:\/\/s.click.aliexpress.com\/e\/1Vl9x0k\" rel=\"noopener noreferrer\" target=\"_blank\">DHT11 sensor<\/a>. By connecting a DHT11 sensor to my Raspberry Pi 3, I can give it the ability to read the temperature and humidity of its environment.<\/p>\n<p>Given these points, I created this post to show how to read temperature and humidity from a DHT11 sensor that is connected to a Raspberry Pi 3. <\/p>\n<p>In order for us to check the temperature and humidity from the DHT11 sensor, we will build a simple Flask application that returns the temperature and humidity values as HTTP responses to HTTP clients.<\/p>\n","protected":false},"author":1,"featured_media":1131,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":""},"categories":[375,4],"tags":[556,555,484,226,233,254,240,308,557,445,276],"jetpack_featured_media_url":"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/Raspberry-Pi-Model-3-B-connected-to-DHT11-sensor.jpg","jetpack_shortlink":"https:\/\/wp.me\/p245TQ-a8","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/628"}],"collection":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/comments?post=628"}],"version-history":[{"count":0,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/628\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media\/1131"}],"wp:attachment":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media?parent=628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/categories?post=628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/tags?post=628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}