Close Menu
  • 3D Printing
    • Reviews
    • Buying Guides
    • How-To
  • ESP32 & Arduino
  • IoT
    • IoT Basics
    • Roadmaps
  • Electronics
  • Projects
    • Mini IoT Projects
  • About
    • Our Authors
    • Get In Touch
What's Hot

Bambu Lab A1: Specs, Features, Price in India & Who Should Buy It

October 26, 2026

Best 3D Printer for Beginners in India (2026)

October 26, 2026

ESP32 Weather Station with DHT22: Step-by-Step Project (Code + Wiring)

October 26, 2026
Instagram YouTube LinkedIn WhatsApp
Authorised Bambu Lab reseller in India  ·  Shop 3D printers & ESP32 kits at KSPElectronics →
  • Terms and Conditions
  • Disclaimer
  • Privacy Policy
Instagram WhatsApp
TheSkypediaTheSkypedia
  • 3D Printing
    • Reviews
    • Buying Guides
    • How-To
  • ESP32 & Arduino
  • IoT
    • IoT Basics
    • Roadmaps
  • Electronics
  • Projects
    • Mini IoT Projects
  • About
    • Our Authors
    • Get In Touch
Subscribe
TheSkypediaTheSkypedia
Home»ESP32 & Arduino»ESP32 Weather Station with DHT22: Step-by-Step Project (Code + Wiring)
ESP32 & Arduino

ESP32 Weather Station with DHT22: Step-by-Step Project (Code + Wiring)

Sai PreethamBy Sai PreethamOctober 26, 2026Updated:October 26, 20264 Comments5 Mins Read
Share Facebook WhatsApp Twitter Email LinkedIn Telegram
ESP32 weather station with DHT22 sensor and phone dashboard
Share
WhatsApp Facebook Twitter LinkedIn Pinterest Email

Disclosure: TheSkypedia is run by the team behind KSPElectronics, an authorised Bambu Lab reseller in India. We test the products we review ourselves. Links to kspelectronics.in go to our own store, and we may earn from purchases made there. Read our full disclosure.

In this project you will build a Wi-Fi weather station that shows live temperature and humidity on a web page you can open from any phone or laptop on your network. It takes about 30 minutes, costs under ₹600 in parts, and needs no soldering.

In this article

Toggle
  • What you will learn
  • Parts used in this project
  • Wiring
  • Step 1: Set up the Arduino IDE
  • Step 2: Upload the code
  • Step 3: Open your weather station
  • Troubleshooting
  • Ideas to take it further
  • Related guides

What you will learn

How the ESP32 weather station sends sensor data to your phone over Wi-Fi
ESP32 Weather Station with DHT22: Step-by-Step Project (Code + Wiring) 1
  • Reading a DHT22 temperature and humidity sensor with an ESP32
  • Connecting the ESP32 to Wi-Fi
  • Serving a live web page and a JSON API from the board

Parts used in this project

PartQtyPriceBuy
ESP32 Development Board (CP2102, 30-pin)1₹400KSPElectronics
DHT22 temperature & humidity sensor module1₹130KSPElectronics
Breadboard + 3 female-to-male jumper wires1 set—KSPElectronics
Micro-USB data cable1——

Wiring

DHT22 module pinESP32 pin
VCC / +3V3
DATA / OUTGPIO 4 (D4)
GND / −GND

The DHT22 module (on a small PCB with 3 pins) already has a pull-up resistor. If you use the bare 4-pin sensor instead, add a 10 kΩ resistor between DATA and 3V3, and leave pin 3 unconnected.

Advertisement

Step 1: Set up the Arduino IDE

  1. Install the Arduino IDE 2.
  2. Go to File → Preferences and add this URL to Additional boards manager URLs: https://espressif.github.io/arduino-esp32/package_esp32_index.json
  3. Open Boards Manager, search “esp32” and install esp32 by Espressif Systems.
  4. Open Library Manager and install DHT sensor library by Adafruit (accept the prompt to also install Adafruit Unified Sensor).
  5. Install the CP2102 USB driver if your computer does not detect the board.

Step 2: Upload the code

Paste the sketch below, replace the Wi-Fi name and password, select Tools → Board → ESP32 Dev Module and the correct port, then click Upload. If the upload stops at “Connecting…”, hold the BOOT button on the board until it starts.

#include <WiFi.h>
#include <WebServer.h>
#include <DHT.h>

#define DHTPIN 4        // DHT22 data pin -> GPIO 4
#define DHTTYPE DHT22

const char* ssid     = "YOUR_WIFI_NAME";
const char* password = "YOUR_WIFI_PASSWORD";

DHT dht(DHTPIN, DHTTYPE);
WebServer server(80);

float temperature = NAN;
float humidity = NAN;
unsigned long lastRead = 0;

void readSensor() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();   // Celsius
  if (!isnan(h) && !isnan(t)) {
    humidity = h;
    temperature = t;
  } else {
    Serial.println("DHT22 read failed - check wiring");
  }
}

void handleRoot() {
  String html = "<!DOCTYPE html><html><head>"
                "<meta name='viewport' content='width=device-width,initial-scale=1'>"
                "<meta http-equiv='refresh' content='10'>"
                "<title>ESP32 Weather Station</title>"
                "<style>body{font-family:sans-serif;text-align:center;padding:2em}"
                ".v{font-size:2.5em;margin:.2em}</style></head><body>"
                "<h1>ESP32 Weather Station</h1>";
  if (isnan(temperature)) {
    html += "<p>Waiting for the first reading...</p>";
  } else {
    float heatIndex = dht.computeHeatIndex(temperature, humidity, false);
    html += "<p>Temperature</p><p class='v'>" + String(temperature, 1) + " &deg;C</p>";
    html += "<p>Humidity</p><p class='v'>" + String(humidity, 1) + " %</p>";
    html += "<p>Feels like " + String(heatIndex, 1) + " &deg;C</p>";
  }
  html += "</body></html>";
  server.send(200, "text/html", html);
}

void handleData() {
  String json = "{\"temperature\":";
  json += isnan(temperature) ? String("null") : String(temperature, 1);
  json += ",\"humidity\":";
  json += isnan(humidity) ? String("null") : String(humidity, 1);
  json += "}";
  server.send(200, "application/json", json);
}

void setup() {
  Serial.begin(115200);
  dht.begin();

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.print("Connecting to Wi-Fi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println();
  Serial.print("Open this in your browser: http://");
  Serial.println(WiFi.localIP());

  server.on("/", handleRoot);
  server.on("/data", handleData);
  server.begin();

  delay(2000);       // DHT22 needs ~2 s after power-up
  readSensor();
}

void loop() {
  server.handleClient();
  if (millis() - lastRead > 2000) {   // DHT22: max one reading every 2 s
    lastRead = millis();
    readSensor();
  }
}

Step 3: Open your weather station

ESP32 weather dashboard open on a smartphone
ESP32 Weather Station with DHT22: Step-by-Step Project (Code + Wiring) 2
  1. Open Tools → Serial Monitor and set it to 115200 baud.
  2. Press the EN/RST button on the ESP32. After it connects, it prints an address such as http://192.168.1.45.
  3. Open that address on a phone or laptop on the same Wi-Fi. The page refreshes every 10 seconds.
  4. For raw data (to use in apps or Home Assistant), open http://<your-ip>/data, which returns JSON like {"temperature":28.4,"humidity":61.0}.

Troubleshooting

ProblemFix
“DHT22 read failed” in Serial MonitorCheck the DATA wire is on GPIO 4 and VCC is on 3V3. With the bare sensor, add the 10 kΩ pull-up.
Stuck on “Connecting to Wi-Fi…”The ESP32 supports only 2.4 GHz Wi-Fi. Check the name and password, and that your router is not 5 GHz-only.
Board not showing in Tools → PortUse a data cable (many charging cables have no data lines) and install the CP2102 driver.
Readings jump or read too highKeep the sensor away from the ESP32 and its regulator, which warm up. Mount it on short wires, out of direct sunlight.
Random resetsUse a better USB cable or a 5 V 1 A supply. Wi-Fi draws current peaks the board needs to handle.

Ideas to take it further

Battery-powered outdoor ESP32 weather sensor in a 3D-printed enclosure
ESP32 Weather Station with DHT22: Step-by-Step Project (Code + Wiring) 3
  • Add a 20×4 LCD or an OLED screen to show readings without a phone.
  • Swap the DHT22 for a BME280 to add air pressure.
  • Send readings to Google Sheets, ThingSpeak or Telegram every 10 minutes.
  • Use deep sleep and a Li-ion battery to make a wireless outdoor sensor.

New to these boards? Read ESP32 vs Arduino Uno first.

Related guides

  • ESP32 vs Arduino Uno: Which Board Should You Choose? (2026)
  • An Introduction to Arduino IDE and ESP32: A Powerful Combination for IoT Projects
  • What is IoT? A Beginner’s Guide to the Internet of Things
  • What is Raspberry Pi? Beginner Friendly Guide (2026)
Get the parts at KSPElectronics
Was this helpful? Rate this post

Advertisement
Share. Facebook Twitter Pinterest LinkedIn Email WhatsApp
Previous ArticleESP32 vs Arduino Uno: Which Board Should You Choose? (2026)
Next Article Best 3D Printer for Beginners in India (2026)
Sai Preetham
  • Website

Sai Preetham is a tech entrepreneur and M.Tech researcher from Hyderabad with a lifelong love for electronics. He builds and tests ESP32, Arduino, IoT and 3D printing projects in his own workshop, and shares what he learns here as hands-on, step-by-step guides.

Related Posts

Electronics Basics

ESP32 vs Arduino Uno: Which Board Should You Choose? (2026)

October 26, 2026
ESP32 & Arduino

An Introduction to Arduino IDE and ESP32: A Powerful Combination for IoT Projects

May 21, 2023
View 4 Comments

4 Comments

  1. Pingback: Best 3D Printer for Beginners in India (2026)

  2. Pingback: IoT Developer Roadmap: Embedded and Application Paths (Step-by-Step)

  3. Pingback: Arduino IDE and ESP32: Beginner's Introduction

  4. Pingback: What is IoT? A Beginner’s Guide to the Internet of Things

Leave A Reply Cancel Reply

Top Posts

Bambu Lab A1: Specs, Features, Price in India & Who Should Buy It

October 26, 2026

Best 3D Printer for Beginners in India (2026)

October 26, 2026

ESP32 Weather Station with DHT22: Step-by-Step Project (Code + Wiring)

October 26, 2026
Advertisement
Stay In Touch
  • YouTube
  • WhatsApp
  • Instagram 51
  • LinkedIn 45

Subscribe to Updates

Get new 3D printer reviews, ESP32 projects and electronics tutorials straight to your inbox.

About TheSkypedia

Hands-on 3D printer reviews and step-by-step ESP32, Arduino, IoT and electronics tutorials, built and tested in our own workshop.

About us
Most Popular

Bambu Lab A1: Specs, Features, Price in India & Who Should Buy It

October 26, 2026

Best 3D Printer for Beginners in India (2026)

October 26, 2026

ESP32 Weather Station with DHT22: Step-by-Step Project (Code + Wiring)

October 26, 2026

Subscribe to Updates

Get new 3D printer reviews, ESP32 projects and electronics tutorials straight to your inbox.

Instagram YouTube LinkedIn WhatsApp
  • About Us
  • Get In Touch
  • Privacy Policy
  • Terms and Conditions
  • Disclaimer
  • JNTUH Results
  • Disclosure
© 2026 TheSkypedia · 3D printer reviews & electronics tutorials.

Type above and press Enter to search. Press Esc to cancel.