Arduino UNO Q - DHT22

The DHT22 offers more accurate temperature and humidity readings than the DHT11 — with a wider range and better precision. This tutorial shows you how to use it with Arduino UNO Q for complete environment monitoring with Telegram alerts.

In this tutorial, you will learn:

Arduino UNO Q DHT22 Temperature and Humidity Sensor

Hardware Preparation

1×Arduino UNO Q
1×USB Cable for Arduino Uno Q
1×DHT22 Temperature Humidity Sensor Module
1×10 kΩ Resistor
1×Breadboard
1×Jumper Wires
1×Recommended: Screw Terminal Block Shield for Arduino Uno
1×Recommended: Sensors/Servo Expansion Shield for Arduino Uno
1×Recommended: Breadboard Shield for Arduino Uno
1×Recommended: Enclosure for Arduino Uno
1×Recommended: Prototyping Base Plate & Breadboard Kit for Arduino UNO

Or you can buy the following kits:

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 the DHT22 Sensor

The DHT22 (also known as AM2302) is a more precise alternative to the DHT11. Both use the same library and nearly identical code — the main difference is the type constant in the constructor.

DHT22
Operating Voltage 3.3V to 6V
Temperature Range -40°C to 80°C
Temperature Accuracy ±0.5°C
Humidity Range 0% to 100%
Humidity Accuracy ±2%
Reading Rate 0.5Hz (once every 2 seconds)

Pinout

DHT22 temperature and humidity sensor Pinout

DHT22 Sensor (4-pin):

  • GND: Connect to GND (0V)
  • VCC: Connect to 3.3V or 5V
  • DATA: Communication pin — connect to a digital pin on the MCU
  • NC: Not connected

DHT22 Module (3-pin):

  • GND: Connect to GND (0V)
  • VCC: Connect to 3.3V or 5V
  • DATA: Communication pin (also labeled OUT or S on some modules)

Most DHT22 modules include a built-in pull-up resistor — no external resistor needed.

Wiring Diagram

Arduino UNO Q - DHT22 Sensor Wiring

Requires a 10kΩ pull-up resistor between DATA and VCC.

The wiring diagram between Arduino UNO Q DHT22 Sensor

This image is created using Fritzing. Click to enlarge image

Arduino UNO Q - DHT22 Module Wiring

No external resistor needed — the module includes one.

The wiring diagram between Arduino UNO Q DHT22 Module

This image is created using Fritzing. Click to enlarge image

DHT22 Pin Arduino UNO Q MCU
GND GND
VCC 3.3V or 5V
DATA D2

How To Program For DHT22

  • Include the library:
#include <DHT.h>
  • Define the pin and create a sensor object:
#define DHT22_PIN 2 DHT dht22(DHT22_PIN, DHT22);
  • Initialize the sensor:
dht22.begin();
  • Read humidity and temperature:
float humidity = dht22.readHumidity(); float tempC = dht22.readTemperature(); float tempF = dht22.readTemperature(true);
  • Always check for failed reads:
if (isnan(humidity) || isnan(tempC) || isnan(tempF)) { Serial.println("Failed to read from DHT22 sensor!"); }

Arduino UNO Q Code

The Arduino UNO Q has two processors working together:

  • The STM32 MCU reads the DHT22 sensor directly — all sensor communication runs on the MCU
  • The Qualcomm MPU runs Debian Linux and handles Wi-Fi, Python, and cloud connectivity
  • In this section, only the MCU is programmed — the Linux side stays idle. A later section shows how both processors work together via Bridge.

The MCU reads temperature and humidity every 3 seconds and prints to the Serial Monitor.

/* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-dht22 */ // COPYRIGHT newbiely.com // AUTHOR: newbiely // This code is made available for public use without restriction. // For complete instructions, tutorials, and further information, visit: // https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-dht22 #include <DHT.h> #define DHT22_PIN 2 // Arduino UNO Q MCU pin connected to DHT22 DATA pin DHT dht22(DHT22_PIN, DHT22); void setup() { Serial.begin(115200); delay(1500); dht22.begin(); Serial.println("Arduino UNO Q DHT22 ready"); } void loop() { delay(3000); // DHT22 requires at least 2 seconds between readings float humidity = dht22.readHumidity(); float tempC = dht22.readTemperature(); float tempF = dht22.readTemperature(true); if (isnan(humidity) || isnan(tempC) || isnan(tempF)) { Serial.println("Failed to read from DHT22 sensor!"); } else { Serial.print("Humidity: "); Serial.print(humidity); Serial.print("% | Temperature: "); Serial.print(tempC); Serial.print("°C ~ "); Serial.print(tempF); Serial.println("°F"); } }

Detailed Instructions

First time with Arduino UNO Q? Follow the Getting Started with Arduino UNO Q tutorial before proceeding.

  • Connect: Wire the DHT22 sensor or module to the Arduino UNO Q MCU as shown in the wiring diagram.
  • Open Arduino App Lab: Launch Arduino App Lab and wait until it detects your Arduino UNO Q.
  • Create a new App: Click the Create New App button.
Create New App in Arduino App Lab on Arduino UNO Q
  • Give the App a name, for example: Dht22
  • Click Create to confirm.
Arduino App Lab App folders and files on Arduino UNO Q
  • Paste the sketch: Copy the MCU code above and paste it into sketch/sketch.ino. Keep other files as default.
  • Install the library: Click the Add sketch library button (the open book icon with a + sign) in the left sidebar.
Add sketch library in Arduino App Lab on Arduino UNO Q
  • Search for DHT sensor library created by Adafruit and click the Install button.
My Apps / DIYables Apps
Run
Bricks
No bricks added...
Sketch Libraries
No sketch libra...
Files
python
sketch
.gitignore
README.md
app.yaml
sketch.ino
Add sketch library
DHT sensor library Adafruit

Arduino library for DHT11, DHT22, etc Temp & Humidity Sensors

1.4.6
Install
More Info
  • Upload: Click the Run button in Arduino App Lab.
Click Run button in Arduino App Lab on Arduino UNO Q
  • Breathe on the sensor or hold it — watch humidity and temperature readings update every 3 seconds.

App Lab Console Output

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
Message (Enter to send a message to "Newbiely" on usb(2820070321))
New Line
9600 baud
[2026-04-29 09:00:01] Arduino UNO Q DHT22 ready [2026-04-29 09:00:04] Humidity: 55.2% | Temperature: 26.10°C ~ 79.00°F [2026-04-29 09:00:07] Humidity: 55.8% | Temperature: 26.20°C ~ 79.16°F [2026-04-29 09:00:10] Humidity: 57.3% | Temperature: 26.50°C ~ 79.70°F [2026-04-29 09:00:13] Humidity: 61.9% | Temperature: 27.10°C ~ 80.78°F

Bridge: Linux + MCU

This section shows how to program both processors of the Arduino UNO Q so the Linux side can read temperature and humidity via Bridge:

  • The DHT22 sensor is connected to the MCU (STM32) — the MCU reads data every 3 seconds and caches the latest values
  • The MPU cannot access the DHT22 directly — it must call Bridge functions to retrieve readings
  • The MPU has Wi-Fi — running full Debian Linux, it can log data, publish to dashboards, or send alerts over the Internet
  • Arduino_RouterBridge enables RPC communication between the two processors
  • ⚠️ /dev/ttyHS1 (Linux) and Serial1 (MCU) are RESERVED by the router — never open them in user code

In short: MCU reads DHT22 every 3 seconds and caches the result → MPU polls Bridge to retrieve readings → MPU publishes or alerts over Wi-Fi.

Note: In the Bridge sketch, the loop() function reads the DHT22 every 3 seconds to keep the cached values fresh. All Bridge callbacks are read-only and return cached data without blocking.

MCU Code (Bridge)

/* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-dht22 */ // COPYRIGHT newbiely.com // AUTHOR: newbiely // This code is made available for public use without restriction. // For complete instructions, tutorials, and further information, visit: // https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-dht22 #include <DHT.h> #include "Arduino_RouterBridge.h" #define DHT22_PIN 2 DHT dht22(DHT22_PIN, DHT22); float last_humidity = 0.0; float last_temp_c = 0.0; float last_temp_f = 0.0; unsigned long last_read_ms = 0; String get_humidity(String arg) { return String(last_humidity, 1); } String get_temp_c(String arg) { return String(last_temp_c, 2); } String get_temp_f(String arg) { return String(last_temp_f, 2); } String get_status(String arg) { return "Temp: " + String(last_temp_c, 2) + "°C / " + String(last_temp_f, 2) + "°F Humidity: " + String(last_humidity, 1) + "%"; } void setup() { Bridge.begin(); Monitor.begin(); dht22.begin(); delay(2000); // allow sensor to stabilize float h = dht22.readHumidity(); float c = dht22.readTemperature(); float f = dht22.readTemperature(true); if (!isnan(h) && !isnan(c) && !isnan(f)) { last_humidity = h; last_temp_c = c; last_temp_f = f; } Bridge.provide("get_humidity", get_humidity); Bridge.provide("get_temp_c", get_temp_c); Bridge.provide("get_temp_f", get_temp_f); Bridge.provide("get_status", get_status); Monitor.println("Arduino UNO Q DHT22 Bridge ready"); } void loop() { unsigned long now = millis(); if (now - last_read_ms >= 3000) { last_read_ms = now; float h = dht22.readHumidity(); float c = dht22.readTemperature(); float f = dht22.readTemperature(true); if (isnan(h) || isnan(c) || isnan(f)) { Monitor.println("Failed to read from DHT22 sensor!"); } else { last_humidity = h; last_temp_c = c; last_temp_f = f; Monitor.println("Humidity: " + String(h, 1) + "% Temp: " + String(c, 2) + "°C / " + String(f, 2) + "°F"); } } }

Python Code (Bridge)

/* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-dht22 */ # COPYRIGHT newbiely.com # AUTHOR: newbiely # This code is made available for public use without restriction. # For complete instructions, tutorials, and further information, visit: # https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-dht22 from arduino.app_utils import * import time def loop(): status = Bridge.call("get_status") print(status) time.sleep(3) App.run(user_loop=loop)

Detailed Instructions

  • Connect: Wire the DHT22 sensor to the Arduino UNO Q as shown in the wiring diagram.
  • Open Arduino App Lab: Launch Arduino App Lab and wait for the board to be detected.
  • Create a new App: Click Create New App, name it Dht22Bridge, then click Create.
  • Paste the MCU sketch: Copy the MCU Bridge code above and paste it into sketch/sketch.ino.
  • Paste the Python code: Copy the Python Bridge code above and paste it into the Python file in the App.
  • Upload: Click the Run button in Arduino App Lab.
Click Run button in Arduino App Lab on Arduino UNO Q
  • Watch temperature and humidity readings appear in the Python console every 3 seconds.

App Lab Console Output

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
Message (Enter to send a message to "Newbiely" on usb(2820070321))
New Line
9600 baud
[2026-04-29 09:00:01] Arduino UNO Q DHT22 Bridge ready [2026-04-29 09:00:04] Humidity: 55.2% Temp: 26.10°C / 79.00°F [2026-04-29 09:00:07] Humidity: 55.8% Temp: 26.20°C / 79.16°F [2026-04-29 09:00:10] Humidity: 57.3% Temp: 26.50°C / 79.70°F
DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
[2026-04-29 09:00:04] Temp: 26.10°C / 79.00°F Humidity: 55.2% [2026-04-29 09:00:07] Temp: 26.20°C / 79.16°F Humidity: 55.8% [2026-04-29 09:00:10] Temp: 26.50°C / 79.70°F Humidity: 57.3% [2026-04-29 09:00:13] Temp: 27.10°C / 80.78°F Humidity: 61.9%

Telegram

Monitor temperature and humidity remotely. Receive automatic alerts when temperature exceeds 35°C or humidity exceeds 80%.

MCU sketch: Keep the same MCU sketch from the previous Bridge section.

Python Code (Telegram)

/* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-dht22 */ # COPYRIGHT newbiely.com # AUTHOR: newbiely # This code is made available for public use without restriction. # For complete instructions, tutorials, and further information, visit: # https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-dht22 from arduino.app_utils import * import requests import time TELEGRAM_BOT_TOKEN = "YOUR_TELEGRAM_BOT_TOKEN" CHAT_ID = "YOUR_CHAT_ID" last_update_id = 0 TEMP_ALERT_C = 35.0 HUMIDITY_ALERT = 80.0 temp_alert_sent = False humi_alert_sent = False def get_updates(): global last_update_id url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/getUpdates" params = {"offset": last_update_id + 1, "timeout": 5} try: response = requests.get(url, params=params, timeout=10) data = response.json() if data["ok"]: return data["result"] except Exception as e: print(f"Error getting updates: {e}") return [] def send_message(chat_id, text): url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage" payload = {"chat_id": chat_id, "text": text} try: requests.post(url, data=payload, timeout=10) except Exception as e: print(f"Error sending message: {e}") def loop(): global temp_alert_sent, humi_alert_sent # Auto-alerts temp_c_str = Bridge.call("get_temp_c") humi_str = Bridge.call("get_humidity") try: temp_c = float(temp_c_str) humi = float(humi_str) temp_f_str = Bridge.call("get_temp_f") if temp_c > TEMP_ALERT_C and not temp_alert_sent: temp_alert_sent = True msg = f"⚠️ High temperature: {temp_c_str}°C / {temp_f_str}°F" print(msg) send_message(CHAT_ID, msg) elif temp_c <= TEMP_ALERT_C: temp_alert_sent = False if humi > HUMIDITY_ALERT and not humi_alert_sent: humi_alert_sent = True msg = f"💧 High humidity: {humi_str}%" print(msg) send_message(CHAT_ID, msg) elif humi <= HUMIDITY_ALERT: humi_alert_sent = False except ValueError: pass # Handle Telegram commands updates = get_updates() for update in updates: last_update_id = update["update_id"] if "message" not in update: continue message = update["message"] chat_id = message["chat"]["id"] text = message.get("text", "").strip() print(f"Received: {text}") if text == "/start": send_message(chat_id, "Arduino UNO Q DHT22 Bot\n" "/temp - Read temperature (°C and °F)\n" "/humidity - Read humidity\n" "/status - Get full sensor status") elif text == "/temp": temp_c = Bridge.call("get_temp_c") temp_f = Bridge.call("get_temp_f") send_message(chat_id, f"Temperature: {temp_c}°C ~ {temp_f}°F") elif text == "/humidity": result = Bridge.call("get_humidity") send_message(chat_id, f"Humidity: {result}%") elif text == "/status": result = Bridge.call("get_status") send_message(chat_id, result) else: send_message(chat_id, "Unknown command. Send /start for help.") time.sleep(3) App.run(user_loop=loop)

Detailed Instructions

  • Replace YOUR_TELEGRAM_BOT_TOKEN with your actual bot token from BotFather.
  • Replace YOUR_CHAT_ID with your Telegram chat ID.
  • Paste this Python code into your App's Python file (keep the same MCU sketch).
  • Click the Run button. Send /temp or /humidity from Telegram, or breathe on the sensor to trigger alerts.

App Lab Console Output

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
[2026-04-29 09:10:00] Waiting for Telegram messages... [2026-04-29 09:10:10] ⚠️ High temperature: 36.00°C / 96.80°F [2026-04-29 09:10:25] 💧 High humidity: 82.3% [2026-04-29 09:10:40] Received: /temp [2026-04-29 09:10:55] Received: /humidity
Telegram
Telegram 12:45
Welcome to Telegram!
ArduinoBot 10:19
Chatting with Arduino...
telegram-botfather
BotFather Yesterday
Your bot has been created.

ArduinoBot

bot
Today
/temp
10:15 AM ✓✓
Temperature: 26.10°C ~ 79.00°F
10:16 AM
/humidity
10:17 AM ✓✓
Humidity: 55.2%
10:18 AM
/status
10:19 AM ✓✓
Temp: 26.10°C / 79.00°F Humidity: 55.2%
10:20 AM
⚠️ High temperature: 36.00°C / 96.80°F
10:21 AM
💧 High humidity: 82.3%
10:22 AM

OpenClaw

...OPENCLAW

OpenClaw support for Arduino UNO Q DHT22 sensor is coming soon.

...OPENCLAW

Project Ideas

You can build many useful projects with the DHT22 sensor and Arduino UNO Q:

  • Precision Weather Station: The DHT22's wider range and better accuracy makes it ideal for a precise indoor/outdoor station — the Linux MPU logs data every minute and charts trends over time
  • Smart HVAC Controller: Use temperature and humidity data to control a relay that switches your air conditioner or humidifier — Telegram alerts when conditions go out of range
  • Seed Germination Monitor: Maintain optimal humidity and temperature for seed germination — receive alerts if humidity drops below threshold and data is logged for review
  • Wine Cellar Monitor: The DHT22 covers the lower temperature range needed for wine storage — monitor both temp and humidity with Telegram alerts if either drifts outside safe limits
  • Server Room Environmental Monitor: Deploy with Wi-Fi for remote monitoring — the MPU sends hourly reports and instant Telegram alerts if temperature or humidity spikes

Challenge Yourself

Ready to go further with the DHT22 on Arduino UNO Q? Try these challenges:

  • Easy: Modify the MCU sketch to blink the built-in LED at different speeds depending on temperature range — slow blink below 20°C, fast blink above 35°C, no blink in between.
  • Medium: Calculate the dew point from temperature and humidity on the Python side using the Magnus formula, and include it in the Telegram /status response alongside temperature and humidity.
  • Advanced: Build a data visualization pipeline: the MPU reads DHT22 via Bridge every 5 minutes, stores readings in a JSON file, and serves a simple HTTP page with a temperature/humidity chart using Chart.js — accessible from any browser on the local network.

※ 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!