Introduction
Welcome, digital tinkerers, IoT enthusiasts, and curious minds! In this guide, we'll explore how to simulate an ESP32 microcontroller connected to a DHT22 temperature & humidity sensor using the magic of Wokwi.
Why simulate? Simple:
- No physical hardware needed
- Fast and safe testing
- Prototype from anywhere
Whether you're a student, hobbyist, or professional prototyper, let's dive into your first simulated DHT22 experimentâcomplete with randomized data. Buckle up! đ
Prerequisites
You only need a browser to run Wokwi simulations. If you plan to extend your project later with local or cloud logging, you might need developer tools (weâll cover that in future guides).
Step-by-Step: Simulate ESP32 + DHT22
Go to the ESP32 + DHT22 Template on Wokwi and click âForkâ to create your own editable version.
The ESP32 is wired to a DHT22 sensor as follows:
- Data Pin:
GPIO 15
- VCC: 3.3V
- GND: Ground
Wokwi lets you fake sensor data! Click the DHT22, then in the UI:
"humidity": "random(40, 80)",
"temperature": "random(20, 35)"
Now your sensor returns a new random value each time it's read.
Use this Arduino sketch in your sketch.ino
:
#include "DHT.h"
#define DHTPIN 15
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
dht.begin();
}
void loop() {
float temp = dht.readTemperature();
float hum = dht.readHumidity();
Serial.print("Temperature: ");
Serial.print(temp);
Serial.print(" °C\tHumidity: ");
Serial.print(hum);
Serial.println(" %");
delay(2000);
}
Then click âStart Simulationâ to see the readings flow.
Data Viewing
The Wokwi Serial Monitor emulates how the Arduino IDE would show your sensor data. Every 2 seconds, youâll see new temperature and humidity readings like:
Temperature: 27.45 °C Humidity: 65.23 %
Wrap-Up
Simulating an ESP32 + DHT22 in Wokwi grants you the freedom to:
- Prototype without physical hardware
- Quickly test sensor logic
- Control your "environment" with random data
Perfect for teaching, debugging, or planning a bigger IoT build. Next steps might include adding more sensors, storing data locally, or sending it to a cloud service.
Happy simulating!