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.
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.
Name | Description |
---|---|
VCC | Positive voltage |
SDA | Digital data pin (input/output) |
NC | Not connected |
GND | Ground |
Name | Description | Default value |
---|---|---|
temperature | Initial temperature value (celsius) | "24" |
humidity | Initial relative humidity value (percentage) | "40" |
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)
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')
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.
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')