Build a real-time environmental monitoring display that reads temperature, humidity, and distance on a compact OLED screen. This ESP32 project combines a DHT11 sensor for climate data and an HC-SR04 ultrasonic sensor for proximity detection, with a status LED that confirms all readings are valid.
The guide includes a complete wiring diagram, parts list, and step-by-step assembly instructions for breadboard construction. Upload the provided firmware to get a live dashboard that samples temperature and humidity every 2 seconds and distance every 500 milliseconds, with serial output for debugging.
Wiring diagram

Gather all the parts
Assemble it in 6 steps
1. Prepare the breadboard without power
Unplug USB. Use the board's printed GPIO labels, not physical pin positions. Place modules on the breadboard with jumper wires; keep the ultrasonic transducers unobstructed. Make separate 3.3 V, 5 V and ground rails. Join split rail sections where needed.
- Never join the 3.3 V and 5 V rails. Use USB power only; do not attach another power supply.
2. Connect the OLED
OLED VCC to 3V3, GND to ground, SDA to GPIO8 (data), SCL to GPIO9 (clock). Check printed VCC/GND labels because their order varies.
- Use 3.3 V so the screen's I2C pull-ups cannot put 5 V onto the ESP32 pins.
3. Connect temperature and humidity
DHT11 VCC to 3V3, GND to ground, DATA to GPIO4. Add the 10 kohm resistor between DATA and 3V3; it keeps the data line high between messages. For a bare four-leg DHT11, viewed from its perforated front with legs down: VCC, DATA, unused, GND. On a module, follow the printed labels instead. Keep it away from the warm ESP32.
4. Protect the ultrasonic echo input
HC-SR04 VCC to USB-powered 5V, GND to ground, TRIG to GPIO5. ECHO goes to one end of the 2.2 kohm resistor. Its other end is the junction connected to GPIO6 and one end of the 3.3 kohm resistor. The remaining 3.3 kohm end goes to ground. This divider reduces a 5 V echo to 3.0 V. TRIG sends the measurement pulse; ECHO reports its travel time.
- Never connect ECHO directly to GPIO6. Reversing the divider resistors raises the voltage. Use the specified values, preferably measured before powering.
5. Add the green status light
GPIO7 to the 330 ohm resistor, resistor to LED anode (usually long leg), LED cathode (short leg/flat edge) to ground. The resistor limits LED current. The LED lights when the screen and all latest sensor readings are valid.
6. Check before powering
Verify all ground connections share one rail and no power rails are shorted. Confirm OLED and DHT power is 3.3 V, sonar power is 5 V, and GPIO6 connects only to the divider junction. Aim the sonar at a broad flat object 10 to 100 cm away for the first test.
- DHT11 is a basic indoor sensor, not a precision instrument. A missing or out-of-range echo is displayed as --, not zero.
Review all connections
1. Connections between "oled" and "ESP32"
2. Connections between "climate" and "ESP32"
3. Connections between "dht_pullup" and "ESP32"
4. Connections between "sonar" and "ESP32"
5. Connections between "echo_top" and "ESP32"
6. Connections between "echo_bottom" and "ESP32"
7. Connections between "led_limit" and "ESP32"
8. Connections between "status" and "ESP32"
Deploy the firmware
#include <Arduino.h>
#include "Station.h"
ClimateSensor climate(Pins::DHT_PIN);
DistanceSensor sonar(Pins::TRIG_PIN,Pins::ECHO_PIN);
Dashboard dashboard;
Readings readings;
uint32_t lastClimate=0,lastDistance=0;
bool displayOK=false;
void setup() {
Serial.begin(115200);
pinMode(Pins::LED_PIN,OUTPUT); digitalWrite(Pins::LED_PIN,LOW);
climate.begin(); sonar.begin();
displayOK=dashboard.begin();
Serial.println(displayOK ? "OLED ready" : "OLED missing: check power/SDA/SCL");
dashboard.update(readings);
}
void loop() {
uint32_t now=millis();
bool changed=false;
if (now-lastClimate>=2000) {
lastClimate=now; climate.sample(readings); changed=true;
Serial.printf("Temperature %.1f C, RH %.1f %%\n",readings.temperature,readings.humidity);
}
if (now-lastDistance>=500) {
lastDistance=now; readings.distance=sonar.sample(); changed=true;
Serial.printf("Distance %.1f cm\n",readings.distance);
}
if (changed) {
dashboard.update(readings);
digitalWrite(Pins::LED_PIN,displayOK && !isnan(readings.temperature) && !isnan(readings.humidity) && !isnan(readings.distance));
}
delay(1);
}Remix this project
Make it yours in one click
Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.




