Temperature and Humidity sensor DHT22

TTN version: TTNv3
Activation: ABP
Device Class: Class A
Last updated: October 7, 2023

This article provides instructions for making a temperature and humidity sensor using Adafruit Feather 32u4 RFM95 LoRa Radio and DHT22. If you haven’t set up Adafruit Feather 32u4 yet, check out our Adafruit Feather 32u4 tutorial.

Adafruit Feather 32u4 and DHT22

Prepare

  • Adafruit Feather 32u4 RFM95 LoRa Radio
  • DHT22 (ASAIR AOSONG AM2302)
  • 4x wire
  • 4.7k resistor
  • breadboard (optional)
  • PC + micro USB cable

 

DHT22

To measure temperature and humidity, we will use the ASAIR AOSONG AM2302 (DHT22) temperature and humidity sensor. The sensor measures temperatures in the range of -40 ºC to 80 ºC and humidity in the range of 0 to 99.9%. The accuracy of temperature measurement is ± 0.5 ºC and humidity ± 2%. The temperature resolution is 0.1 ºC and the humidity 0.1%.

AOSONG AM2302

 

Sensor assembly

Connect everything according to the schematics bellow.

Wire up the Adafruit Feather 32u4’s IO1 pin with pin 6. The sensor is connected using three pins. The first DHT22 pin (VDD) is connected to the supply voltage (3V pin on Adafruit Feather 32u4), the second DHT22 pin (SDA) is used for data transmission via the bus and is connected to Feather’s digital pin 12, the third DHT22 pin (NC) is not connected and the fourth DHT22 pin (GND) is connected to ground (GND pin on Feather). Between first and second DHT22 pins is connected 4,7k resistor. The sensor requires a stabilized supply voltage in the range of 3.3 V to 5.5 V for its function.Adafruit Feather 32u4 and DHT22

 

Arduino IDE setup

  1. Run Arduino IDE.
  2. In the Arduino IDE Library Manager search TroykaDHT by Amperka and install it.
  3. In the Arduino IDE Library Manager search CayenneLPP by Electronic Cats and install it.
  4. Download as ZIP this Low-Power library by Rocketscream.
  5. In the Arduino IDE Sketch -> Include Library -> Add .ZIP Library… choose downloaded ZIP.

 

Printing measured values to Serial Monitor

  1. Copy and paste this program to your Arduino IDE.
  2. Connect Adafruit Feather 32u4 using micro USB cable to your computer.
  3. In Arduino IDE click on Upload button to upload program to your Adafruit Feather 32u4.
  4. In Arduino IDE click on Serial Monitor button and you should every 10 seconds see this:DHT22 Serial Monitor

 

Sending measured values to TTS

We have prepared four programs for measuring temperature and humidity. The first program sends the current measured values. The second program sends averages of measured values over a certain period of time. The other two programs extend the first two with a low power mode, which is great when you run this sensor on battery power.

Programs

 

Instructions

  1. Copy and paste one of this programs to your Arduino IDE.
  2. In program replace NWKSKEYAPPSKEY and DEVADDR with keys of your end device registred in TTS. Keys are in TTS -> Applications -> YourAppName -> YourEndDeviceName -> Overview -> Session information.
  3. In TTS -> Applications -> YourAppName -> YourEndDeviceName -> Payload formatters -> Uplink change Formatter type to CayenneLPP. For more information, check out our Cayenne LPP tutorial.
  4. Click on Save changes.
  5. Connect Adafruit Feather 32u4 using micro USB cable to your computer.
  6. In Arduino IDE click on Upload button to upload program to your Adafruit Feather 32u4.
  7. In TTS -> Applications -> YourAppName -> YourEndDeviceName -> Live data you should every 5 minutes (Low Power Mode – 10 minutes) see this:DHT22 - TTS console

 

Data visualization

If you want to visualize your measured data, continue with the following tutorial: