ESP32 Humidity & Temperature Sensor

Interfacing DHT22 with ESP32 on Wokwi

Introduction

Learn how to simulate an ESP32 and DHT22 sensor setup using MicroPython on the Wokwi platform.

Ideal for testing and learning without the need for physical components.

Wokwi DHT22 Sensor Overview

The Wokwi DHT22 is a digital humidity and temperature sensor simulation.

Key features include customizable initial temperature and humidity values, and the ability to adjust these values during simulation.

Wokwi DHT22 Sensor Pin names

Name Description
VCC Positive voltage
SDA Digital data pin (input/output)
NC Not connected
GND Ground

Wokwi DHT22 Sensor Attributes

Name Description Default value
temperature Initial temperature value (celsius) "24"
humidity Initial relative humidity value (percentage) "40"

Setting Up the Simulation in Wokwi

Start a new project on Wokwi and include the ESP32 and DHT22 components.

Connect the DHT22's

VCC to ESP32's 3V3

GND to GND

SDA to a designated GPIO pin (e.g., GPIO5)

MicroPython Code for Interfacing DHT22 with ESP32

import machine
import dht

# Initialize the DHT22 sensor
dhtSensor = dht.DHT22(machine.Pin(5))

dhtSensor.measure()
temp = dhtSensor.temperature()
hum = dhtSensor.humidity()
print(f'\nTemperature: {temp:.2f}°C')
print(f'   Humidity: {hum:.2f}%\n')

Simulation in Wokwi for DHT22 with ESP32

Testing and Observation

Run the simulation and observe the serial output for temperature and humidity readings.

Experiment with changing the temperature and humidity values during the simulation for dynamic testing.

Interfacing DHT11 with ESP32 Kit

Hardware Components

MicroPython Code for DHT11 and ESP32

import machine
import dht

# Initialize the DHT11 sensor
dhtSensor = dht.DHT11(machine.Pin(15))

dhtSensor.measure()
temp = dhtSensor.temperature()
hum = dhtSensor.humidity()
print(f'\nTemperature: {temp:.2f}°C')
print(f'   Humidity: {hum:.2f}%\n')

ESP32 Humidity & Temperature Sensor

By wschen

ESP32 Humidity & Temperature Sensor

Explore the world of ESP32 Humidity & Temperature Sensor with this engaging presentation. Discover how to interface DHT22 and DHT11 with ESP32 using MicroPython code and simulation in Wokwi. Uncover the fascinating attributes and pin names of these sensors and witness the testing and observation process.

  • 99