Installing DHT11/ DHT22 libraries for Arduino/ NodeMCU

by Jun 13, 2020Arduino IDE Programming, Arduino Uno, NodeMCU

Many times you might wish to sense the temperature around you. But you can not directly use the sensor just by making the circuit and writing code. You need to use the specific library for the sensor which has many pre-defined functions used by the sensor. In this article we will discuss how to install the library and use the DHT11/ DHT22 temperature sensor for both Arduino and NodeMCU.

Contents:

DHT11 sensor

How DHTxx sensor works ?

The DHT11/ DHT22 consist of a humidity sensing component and a NTC temperature sensor (or thermistor). Furthermore, there is an IC on the back side of the sensor. For measuring humidity, humidity sensing component is used. It has two electrodes with moisture holding substrate between them.

Almost all sensors have an Analog Interface which defines the way they extract information. Consider the DHT11 sensor. It senses all the temperatures that lie in a particular range. This is the analog input which the sensor gives to the microcontroller. But since the controller is a digital device, so this analog is first converted to digital by ADC (Analog to Digital Converter).

Use of a Library

The Arduino environment can be extended through the use of libraries, just like most programming platforms. Libraries provide extra functionality for use in sketches, e.g. working with hardware or manipulating data. 

After getting the inputs, various functions in the library process it further. This is where a library plays a role. It stores the data in registers and processes it to output in the user understandable form. However, many times, a DAC (Digital to Analog Converter) is used after the controller has processed the data.

Downloading DHT11/ DHT22 library for an Arduino board

Libraries are majorly downloaded in two ways. First, they can be downloaded directly from the Library Manager. Alternatively, you can download the zipped format from the Internet. Many libraries are not present in the manager. For them, you need to use the second method. Furthermore, you can also create your own libraries. See the API Style Guide for information on making a good Arduino-style API for your library.

However, in our case we can use the first method as the library is available in the manager. So let us begin!

Open the Arduino IDE and click on the Sketch option. In the options listed below, click on the ‘Include Library‘ option. You will see the list of all the libraries installed in your IDE. Now, have a look at the first two options. This is what we discussed in the above paragraph. The second option of Zipped file is used when we want to install a library downloaded from the internet. For using library manager, click on the ‘Manage Libraries‘ option.

Follow these steps

After this, you will see the window shown above. Search for the DHTxx library and then install the ‘DHT sensor library‘ as shown.

Install this library

Great, you have successfully installed the library for the Arduino board.

Downloading the library for NodeMCU

The library used for the ESP8266 is not this same. Rather, there is a different library used for it. You first need to set your ESP board in the IDE. Read this, for how to do so. After that, refer the same steps as above and go to the Library manager. Then install the library named “DHT sensor library for ESPx” as shown below.

For NodeMCU

Using it with the IDE and extracting code

After successful installation, we can now use the libraries in whatever code we wish to. Also, we can use some inbuilt examples present in the both the libraries. Although they consist of some basic code, but it is enough to see the functionality of the sensor. Refer the image given below.

Extracting code

I hope you were able to get through the article and able to use the libraries for the two boards. Feel free to write in the comment section if you face any difficulty. Happy Learning!

Creating a multiplication Skill in Alexa using python

Written By Anmol Punetha

Hey, I am Anmol. I am a tech blogger and an electronics engineering student at the same time. As you're reading my blog, you are getting a generous amount of information in simpler words. Hope it's of use. Thank you for visiting. Keep reading!

RELATED POSTS

How to use simulators to build Arduino Projects

How to use simulators to build Arduino Projects

Introduction In this tutorial, let's learn how to use simulators for building Arduino projects for beginners. In addition to it, We shall learn how to configure it and how to get started with simulation tools. Here, We shall take an example of blinking an led using...

Arduino and its various development boards

Arduino and its various development boards

1. What is Arduino? Arduino is an open-source software and software company, project, and user community that designs and manufactures single-board microcontrollers and microcontroller kits for building digital devices....

MIT app inventor with Arduino

MIT app inventor with Arduino

MIT app inventor is a platform developed to help you expand your ideas into mobile applications that can be used throughout various devices. Arduino, as you most probably have heard of is mainly used to develop and implement many projects. When you put together the...

Arduino Compatible Temperature Sensors

Arduino Compatible Temperature Sensors

In this article, we will look at Arduino's popular temperature sensors which are the foundation for Arduino's entry level projects. Temperature Sensor Temperature sensors are designed to measure the temperature of an object or substance using the properties and...

Coding  MicroPython using NodeMCU ESP8266

Coding MicroPython using NodeMCU ESP8266

Before diving into the NodeMCU with MicroPython we should know some key concepts of embedded programming such as flashing , firmware etc. Development platforms for NodeMCU_ESP8266: ESPlorerLuaIDEArduino IDE etc Programming languages for NodeMCU_ESP8266:...

Introduction to MicroPython and ESP8266

Introduction to MicroPython and ESP8266

For ages, C and C++ have ruled over the embedded system industry. Fast prototyping is an important aspect of the industry today. In fact MicroPython is the best suited for fast prototyping. Students and engineers are becoming very familiar with the Python programming...

VIDEOS – FOLLOW US ON YOUTUBE

EXPLORE OUR IOT PROJECTS

IoT Smart Gardening System – ESP8266, MQTT, Adafruit IO

Gardening is always a very calming pastime. However, our gardens' plants may not always receive the care they require due to our active lifestyles. What if we could remotely keep an eye on their health and provide them with the attention they require? In this article,...

How to Simulate IoT projects using Cisco Packet Tracer

In this tutorial, let's learn how to simulate the IoT project using the Cisco packet tracer. As an example, we shall build a simple Home Automation project to control and monitor devices. Introduction Firstly, let's quickly look at the overview of the software. Packet...

All you need to know about integrating NodeMCU with Ubidots over MQTT

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

All you need to know about integrating NodeMCU with Ubidots over Https

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

How to design a Wireless Blind Stick using nRF24L01 Module?

Introduction Let's learn to design a low-cost wireless blind stick using the nRF24L01 transceiver module. So the complete project is divided into the transmitter part and receiver part. Thus, the Transmitter part consists of an Arduino Nano microcontroller, ultrasonic...

Sending Temperature data to ThingSpeak Cloud and Visualize

In this article, we are going to learn “How to send temperature data to ThingSpeak Cloud?”. We can then visualize the temperature data uploaded to ThingSpeak Cloud anywhere in the world. But "What is ThingSpeak?” ThingSpeak is an open-source IoT platform that allows...

Amaze your friend with latest tricks of Raspberry Pi and Firebase

Introduction to our Raspberry Pi and Firebase trick Let me introduce you to the latest trick of Raspberry Pi and Firebase we'll be using to fool them. It begins with a small circuit to connect a temperature sensor and an Infrared sensor with Raspberry Pi. The circuit...

How to implement Machine Learning on IoT based Data?

Introduction The industrial scope for the convergence of the Internet of Things(IoT) and Machine learning(ML) is wide and informative. IoT renders an enormous amount of data from various sensors. On the other hand, ML opens up insight hidden in the acquired data....

Smart Display Board based on IoT and Google Firebase

Introduction In this tutorial, we are going to build a Smart Display Board based on IoT and Google Firebase by using NodeMCU8266 (or you can even use NodeMCU32) and LCD. Generally, in shops, hotels, offices, railway stations, notice/ display boards are used. They are...

Smart Gardening System – GO GREEN Project

Automation of farm activities can transform agricultural domain from being manual into a dynamic field to yield higher production with less human intervention. The project Green is developed to manage farms using modern information and communication technologies....