Roborear

Build Your Own ESP32 DIY Weather Station: Track Temperature, Humidity & Air Quality

A high-angle close-up of a breadboard prototype featuring an ESP32 microcontroller as the core of a diy weather station. The setup includes an OLED display, a buzzer, and sensors for environmental tracking. In the background, a large monitor shows a dark terminal interface displaying live JSON data streams for "Temperature: 26.50C," "Humidity: 60.00%," and "Gas Sensor Level: 293" from the station.
A top-down view of a DIY weather station prototype built on a breadboard over a green grid mat. The setup features an ESP32 microcontroller, an MQ gas sensor with a glowing red LED, a blue temperature sensor, and a small OLED display showing "Air Quality Monitor" with live temperature and humidity data. A white USB cable provides power to the system.

The “What’s in My Air?” Moment | DIY Weather Station

I used to wonder about the air in my room.

Is it too humid? Too dry? Is the air quality actually good?

I bought an air purifier. It had a little light. Green meant good. Red meant bad.

But that’s all it told me. No numbers. No trends. No idea what was actually happening.

So I built my own.

An ESP32. A few sensors. An OLED display.

Now I know exactly what’s in my air. Temperature in degrees. Humidity as a percentage. Air quality from “Good” to “Hazardous.”

And the best part? I can check it from my phone. Anywhere. Anytime.

This is the perfect intermediate project. More complex than a simple LED blinker. But not so hard that you’ll give up.

Let’s build it.

What You’ll Build

A complete diy weather station that measures:

 
 
MeasurementSensorRange
🌡️ TemperatureDHT22-40°C to 80°C (±0.5°C accuracy)
💧 HumidityDHT220% to 100% (±2-5% accuracy)
🌫️ Air Quality (CO2, smoke, NH3)MQ2Relative measurement (Good → Hazardous)

Display options:

  • Local OLED screen shows readings instantly

  • Web server lets you check from any device on your WiFi

  • Data updates every 2 seconds

A technical block diagram for an ESP32-based diy weather station. It shows an ESP32 microcontroller connected to a DHT22 temperature/humidity sensor and an MQ135 air quality sensor. The data flows into an OLED display and simultaneously transmits via WiFi to a smartphone and a computer monitor for remote tracking.

What You’ll Need

Hardware Components

 
 
ComponentSpecs / NotesPrice (USD)
ESP32 Development BoardAny 30-pin version$5.00 – $7.00
DHT22 Temperature/Humidity SensorMore accurate than DHT11 (±0.5°C)$3.00 – $5.00
MQ135 Air Quality SensorDetects CO2, smoke, NH3, benzene$5.00 – $8.00
0.96″ OLED DisplayI2C, 128×64 pixels$2.00 – $4.00
10kΩ ResistorFor DHT22 data line (pull-up)$0.05 – $0.10
Breadboard400 points$1.00 – $2.00
Jumper WiresMale-to-female & male-to-male$1.00 – $2.00
USB CableFor power and programming$2.00 – $4.00

Total: ~$19.00 – $32.00 USD

Quick Buy Links

 
 
ComponentWhere to Find
ESP32 Development BoardAliExpress
DHT11 SensorAliExpress
MQ2 Air Quality SensorAliExpress
0.96″ OLED DisplayAliExpress
Breadboard + Jumper KitAliExpress
A collection of electronics components for a diy weather station project laid out on a white surface. The set includes a large white breadboard, a small green breadboard, an MQ gas sensor, a DHT temperature and humidity sensor, an OLED display module, a small buzzer, resistors, and several multi-colored jumper wires.

Sensor Comparison: DHT11 vs DHT22

If you’ve seen the DHT11, you might wonder why I chose the DHT22.

 
 
FeatureDHT11DHT22 (AM2302)
Temperature range0-50°C-40 to 80°C
Temperature accuracy±2°C±0.5°C
Humidity range20-80%0-100%
Humidity accuracy±5%±2-5%
Sampling rate1 Hz (1 read/sec)0.5 Hz (1 read/2 sec)
Price~$2-3~$3-5
Best forBasic projectsDIY Weather stations, accurate monitoring

For a DIY weather station that actually tells you useful information, spend the extra dollar on the DHT22.

How the Sensors Work

DHT11 (Temperature + Humidity)

The DHT11 uses a capacitive humidity sensor and a thermistor to measure temperature. It sends digital data over a single wire.

Important: The DHT11 needs a 10kΩ pull-up resistor on the data line. Without it, readings will fail or be erratic.

A technical wiring diagram in text format for a diy weather station project. It lists the connections between an MQ-2 sensor and an ESP32: VCC to 5V (or 3.3V), GND to the GND rail, A0 (Analog) to GPIO 34, and D0 (Digital) to GPIO 35.

 

MQ135 (Air Quality)

The MQ135 is a chemical sensor. It has a heating element inside that makes it sensitive to various gases:

 
 
GasDetected
Carbon dioxide (CO2)✅ Yes
Smoke✅ Yes
Ammonia (NH3)✅ Yes
Benzene✅ Yes
Formaldehyde✅ Yes

The sensor outputs a higher voltage when it detects more pollutants. We read this analog value and convert it to a simple quality rating.

Important: The MQ135 needs to “warm up” for 5-10 minutes before giving stable readings. This is normal.

Wiring It Up

I2C OLED Display – DIY Weather Station

 
 
OLED PinESP32 Pin
VCC3.3V
GNDGND
SCLGPIO 22
SDAGPIO 21

DHT11 Sensor – DIY Weather Station

 
 
DHT11 PinESP32 PinNotes
VCC3.3VUse 3.3V, not 5V
GNDGND 
DATAGPIO 4Add 10kΩ resistor from DATA to VCC

MQ2 Air Quality Sensor – DIY Weather Station

 
MQ2 PinESP32 Pin
VCC5VMQ135 needs 5V power
GNDGND
AO (Analog Out)GPIO 34ADC input
A hand places a jumper wire into a white breadboard next to a small OLED display and an ESP32 microcontroller. The workspace includes an MQ gas sensor, a DHT temperature sensor, resistors, and a buzzer. An inset box provides the specific OLED I2C pinout: VCC to 3.3V, GND to GND, SCL to GPIO 22, and SDA to GPIO 21 for a diy weather station project.

The Code – DIY Weather Station

Full code available on GitHub: https://github.com/shahrear-ab/roborear/blob/main/weather_station/weather_station.ino

Setting up VS Code and PlatformIO to Control Servo Motors – Robotics for Beginners: Learn ESP32 PlatformIO with VS Code | Blink LED Tutorial

Required Libraries – DIY Weather Station

Install these in Arduino IDE (Sketch → Include Library → Manage Libraries):

 
 
LibraryAuthorPurpose
DHT sensor libraryAdafruitReads DHT22
Adafruit Unified SensorAdafruitRequired for DHT
Adafruit SSD1306AdafruitControls OLED display
Adafruit GFXAdafruitGraphics for OLED
A digital readout from a diy weather station project showing environmental data. The text on a dark background displays a temperature of 26.50°C, humidity at 60.00%, weather as "Sunny," and an advice note saying "Wear sunscreen!". Below this, it lists a smoke level of 293 with "Smoke Detected: NO" and "Smoke Alert: NO".
A top-down view of a DIY weather station prototype built on a breadboard over a green grid mat. The setup features an ESP32 microcontroller, an MQ gas sensor with a glowing red LED, a blue temperature sensor, and a small OLED display showing "Air Quality Monitor" with live temperature and humidity data. A white USB cable provides power to the system.

 

How to Read Air Quality Values – DIY Weather Station

The MQ135 outputs an analog value from 0 to 4095. Here’s what the numbers mean:

 
 
Raw ValueAir Quality StatusWhat It Means
< 300🟢 GoodClean air, normal conditions
300 – 600🟡 ModerateAcceptable, some pollutants present
600 – 900🟠 Unhealthy for SensitiveChildren, elderly, respiratory issues may be affected
900 – 1200🔴 UnhealthyEveryone may experience effects
> 1200⚫ HazardousEmergency conditions

Important: These thresholds are approximate. Your sensor may read higher or lower depending on your environment and calibration.

Identifying resistor values – How To Read Resistor Color Codes (And Never Burn an LED Again) | 4 Easy Steps

Testing Your DIY Weather Station

After Uploading

  1. Open Serial Monitor (115200 baud)

    • Should show temperature, humidity, and air quality every 2 seconds

  2. Check the OLED display

    • Should show all three readings clearly

  3. Test the web server (if WiFi configured)

    • Open browser on phone or computer

    • Enter the ESP32’s IP address (shown in Serial Monitor)

    • See readings in a clean web page

Testing Air Quality Response – DIY Weather Station

  • Normal room air: Baseline reading (usually 100-400)

  • Near a candle or incense: Reading should increase

  • Near cooking: Reading may spike

  • Exhaling directly on sensor: CO2 from breath increases reading

    To get familiar with your MQ135 sensor, try these simple experiments. Light a match or incense stick about 30cm away from the sensor. Watch the Serial Monitor – you should see the air quality value rise within 10-15 seconds. The smoke particles are detected by the sensor, causing the voltage on the AO pin to increase. Once you move the smoke source away, the value should slowly return to baseline after 20-30 seconds.

    You can also test with common household items. A spray of deodorant or perfume will cause a sharp spike. Cooking oil fumes from the kitchen will show a gradual increase. Even opening a bottle of vinegar nearby will register because the MQ135 is sensitive to acidic gases.

    For a fun demonstration, have someone exhale directly onto the sensor from a few inches away. The carbon dioxide in their breath will cause a noticeable jump in readings. This shows how quickly air quality changes with human presence – useful for classroom demonstrations or understanding ventilation needs in a room.

    Remember that extreme values (over 1000) may take several minutes to drop back to normal because the sensor absorbs gases and needs time to “clear” itself. This is normal behavior.

Make It Your Own (Upgrades) – DIY Weather Station

 
 
UpgradeDifficultyWhat You’ll Need
Add more sensors⭐ EasyBMP280 (pressure), MQ7 (CO), MQ2 (combustible gas)
Data logging to SD card⭐⭐ MediumMicroSD card module
Send data to cloud⭐⭐ MediumThingspeak, Blynk, or Firebase
Battery powered⭐⭐ Medium18650 battery + TP4056
3D printed case⭐⭐ Medium3D printer or laser cutter
Telegram alerts⭐⭐⭐ HardTelegram bot API
Historical graphs⭐⭐⭐ HardInfluxDB + Grafana

Troubleshooting

 
 
ProblemLikely CauseFix
DHT22 reads “nan”Missing pull-up resistorAdd 10kΩ resistor between DATA and VCC
MQ135 readings unstableSensor not warmed upWait 5-10 minutes for stabilization
OLED shows nothingWrong I2C addressTry address 0x3C or 0x3D
Air quality always 4095AO pin not connectedCheck jumper from MQ135 AO to ESP32 GPIO 34
Air quality always 0MQ135 not poweredCheck VCC to 5V, GND to GND
WiFi not connectingWrong credentials or 5GHz networkUse 2.4GHz network, check SSID/password

Why DHT22 Over DHT11? – DIY Weather Station

 
 
ReasonExplanation
Accuracy matters±0.5°C vs ±2°C makes a real difference
Better rangeSub-zero temperatures and 0-100% humidity
ReliabilityFewer failed readings
Cost differenceOnly ~$2 more

The DHT11 is fine for learning. But for a real weather station, the DHT22 is worth the extra dollar.

If your DHT22 still shows “nan” after adding the pull-up resistor, try a different GPIO pin. Some ESP32 pins have better performance for one-wire sensors. GPIO 4, 13, and 14 are good alternatives. Also, the DHT22 requires precise timing. If your code has long delays or heavy WiFi operations, the sensor reading may timeout. Move sensor readings to the beginning of your loop and add a 2-second delay between reads – the DHT22 needs at least 1.8 seconds between measurements anyway.

If your MQ135 readings fluctuate wildly even after warm-up, check for airflow. The sensor is sensitive to drafts from fans, air conditioners, or open windows. Place it in a stable environment for consistent readings. You can also add software smoothing by averaging 10 readings and dividing by 10. This reduces noise without losing responsiveness.

If your OLED display works but shows garbage or random pixels, check your I2C connections. Loose wires can cause data corruption. Also verify that you have the correct display driver in your code. Some 0.96″ OLEDs use the SH1106 driver instead of SSD1306. The symptoms look similar but the fix is simply changing the library.

For WiFi issues, try powering your ESP32 from a phone charger instead of your computer’s USB port. Computer ports sometimes provide unstable power that affects the WiFi radio.

A side-by-side comparison of two popular environmental sensors for a diy weather station. On the left is the smaller, blue DHT11 sensor, and on the right is the larger, white DHT22 sensor. Both feature four connection pins and are labeled with their respective model names against a plain gray background.

Real-World Applications – DIY Weather Station

 
 
Use CaseHow It Helps
Home air quality monitorKnow when to open windows or run purifier
Greenhouse controllerMaintain optimal temp/humidity for plants
Server room monitorAlert before equipment overheats
Classroom demonstrationShow how CO2 rises when room is full
Cigar humidor monitorMaintain perfect humidity
Pet enclosure monitorKeep reptiles or amphibians healthy

🎥 Watch the Step-by-Step Video Tutorial – DIY Weather Station

Prefer watching over reading? See the complete DIY weather station build in action:

📺 ESP32 DIY Weather Station with Air Quality Monitor

👉 Don’t forget to Subscribe to Roborear on YouTube for more beginner-friendly electronics and IoT projects every week!

Your Turn – DIY Weather Station

This project taught me that you don’t need expensive commercial air quality monitors. A $20 ESP32 and a few sensors give you more control, more data, and a much better understanding of what’s actually happening.

Now go build yours. Let it run for a day. Notice how the air quality changes when you cook, when you open a window, when the room gets crowded.

That’s the fun part.

FAQs

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top