Arduino Nano 33 IoT - DHT22

This guide shows you how to use the Arduino Nano 33 IoT to measure the temperature and humidity using a DHT22 sensor, and display the readings on the Serial Monitor. It includes steps for both the DHT22 sensor and module.

Arduino Nano 33 IoT DHT22 Temperature and humidity Sensor

Hardware Preparation

1×Arduino Nano 33 IoT
1×Micro USB Cable
1×DHT22 Temperature Humidity Sensor Module
1×10 kΩ resistor
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack
1×Recommended: Screw Terminal Expansion Board for Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter for Arduino Nano

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of DHT22 Temperature and Humidity Sensor

DHT22
Operating Voltage3 to 5V
The humidity range 0% to 100%
The humidity accuracy ± 2% to 5%
The temperature range -40°C to 80°C
The temperature accuracy ± 0.5°C
The reading rate 0.5Hz (one time per 2 seconds)

DHT22 Pinout

The DHT22 comes in two versions: one as a raw sensor and the other as a module.

DHT22 sensor module Pinout

The DHT22 sensor has four pins:

  • GND pin: Connect this pin to ground (0V)
  • VCC pin: Connect this pin to power (3.3V or 5V)
  • DATA pin: This pin lets the sensor talk with the Arduino Nano 33 IoT
  • NC pin: Do not connect anything to this pin

We strongly recommend using the DHT22 module. This module has a built-in resistor and only three pins: VCC, GND, and DATA (or alternatively: +, -, and OUT).

Wiring Diagram between DHT22 and Arduino Nano 33 IoT

Wiring the Arduino Nano 33 IoT is the same for both sensors. In its original design, you need a resistor between 5K and 10K ohms to keep the data line high and allow communication between the sensor and the Arduino Nano 33 IoT.

Arduino Nano 33 IoT - DHT22 Sensor Wiring

The wiring diagram between Arduino Nano and 33 IoT DHT22 Temperature and humidity Sensor

This image is created using Fritzing. Click to enlarge image

Arduino Nano 33 IoT - DHT22 Module Wiring

Most DHT22 sensor modules already include a resistor, so you don’t have to add one. This means less wiring and soldering work.

The wiring diagram between Arduino Nano and 33 IoT DHT22 Temperature and humidity Module

This image is created using Fritzing. Click to enlarge image

Arduino Nano 33 IoT Code - DHT22

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-dht22 */ #include <DHT.h> #define DHT22_PIN 3 // The Arduino Nano 33 IoT pin D31 connected to DHT22 sensor DHT dht22(DHT22_PIN, DHT22); void setup() { Serial.begin(9600); dht22.begin(); // initialize the DHT22 sensor } void loop() { // read humidity float humi = dht22.readHumidity(); // read temperature in Celsius float temperature_C = dht22.readTemperature(); // read temperature in Fahrenheit float temperature_F = dht22.readTemperature(true); // check whether the reading is successful or not if ( isnan(temperature_C) || isnan(temperature_F) || isnan(humi)) { Serial.println("Failed to read from DHT22 sensor!"); } else { Serial.print("Humidity: "); Serial.print(humi); Serial.print("%"); Serial.print(" | "); Serial.print("Temperature: "); Serial.print(temperature_C); Serial.print("°C ~ "); Serial.print(temperature_F); Serial.println("°F"); } // wait a 2 seconds between readings delay(2000); }

Detailed Instructions

If you are new to the Arduino Nano 33 IoT, be sure to check out our Getting Started with Arduino Nano 33 IoT tutorial. Then, follow these steps:

  • Connect the components to the Arduino Nano 33 IoT board as depicted in the diagram.
  • Use a USB cable to connect the Arduino Nano 33 IoT board to your computer.
  • Launch the Arduino IDE on your computer.
  • Select the Arduino Nano 33 IoT board and choose its corresponding COM port.
  • Open the Library Manager by clicking on the Library Manager icon on the left side of the Arduino software.
  • Type DHT in the search box and find the DHT sensor library made by Adafruit.
  • Click on the Install button to add the library.
Arduino Nano 33 IoT DHT sensor library
  • A window will open asking if you want to install extra software needed by the library.
  • To install all the extra software, just click the Install All button.
Arduino Nano 33 IoT Adafruit Unified sensor library
  • Copy one of the code examples above and open it in the Arduino program.
  • Compile and send the code to your Arduino Nano 33 IoT board by clicking the Upload button.
  • Change the sensor's temperature by making it colder or warmer, for example, by placing it near a hot cup of coffee.
  • See the result on the Serial Monitor. It should look like the picture shown below.
COM6
Send
Humidity: 31.00% | Temperature: 27.00°C ~ 80.60°F Humidity: 31.00% | Temperature: 27.00°C ~ 80.60°F Humidity: 31.00% | Temperature: 27.00°C ~ 80.60°F Humidity: 31.00% | Temperature: 27.00°C ~ 80.60°F Humidity: 31.00% | Temperature: 28.00°C ~ 82.40°F Humidity: 31.00% | Temperature: 28.00°C ~ 82.40°F Humidity: 31.00% | Temperature: 28.00°C ~ 82.40°F Humidity: 31.00% | Temperature: 28.00°C ~ 82.40°F Humidity: 32.00% | Temperature: 28.00°C ~ 82.40°F Humidity: 31.00% | Temperature: 29.00°C ~ 84.20°F Humidity: 32.00% | Temperature: 29.00°C ~ 84.20°F Humidity: 31.00% | Temperature: 29.00°C ~ 84.20°F
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!