Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO and DHT22 Temperature and Humidity Sensor with Serial Monitoring

View and Edit Project In Cirkit DesignerImage of Arduino UNO and DHT22 Temperature and Humidity Sensor with Serial Monitoring

Circuit Documentation

Summary

This circuit involves an Arduino UNO microcontroller interfaced with a DHT22 temperature and humidity sensor. The Arduino UNO reads data from the DHT22 sensor and outputs the temperature and humidity readings to the Serial Monitor.

Component List

DHT22

Arduino UNO

ESP32 (30 pin)

Wiring Details

DHT22

Arduino UNO

Documented Code

#include "DHT.h"  // Include the DHT library

#define DHTPIN 2      // GPIO pin connected to the DHT22 data pin
#define DHTTYPE DHT22 // Specify the sensor type (DHT11, DHT22, etc.)

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(115200); // Initialize serial communication
  dht.begin();          // Initialize the DHT sensor
  Serial.println("DHT22 Sensor Test");
}

void loop() {
  // Read temperature as Celsius
  float temperature = dht.readTemperature();
  // Read humidity
  float humidity = dht.readHumidity();

  // Check if any reading failed
  if (isnan(temperature) || isnan(humidity)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Print the results to the Serial Monitor
  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" °C");

  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.println(" %");

  delay(50000); // Wait for 2 seconds before reading again
}

This code initializes the DHT22 sensor and reads temperature and humidity data from it. The readings are then printed to the Serial Monitor. If the sensor fails to provide readings, an error message is displayed.