Build Your Own Weather Station with ESP32

Building your own weather station is one of the most rewarding IoT projects you can undertake. With the ESP32 microcontroller, you can create a sophisticated weather monitoring system that measures temperature, humidity, pressure, and more—all while sending data to the cloud for remote monitoring. This comprehensive tutorial will guide you through building a professional-grade weather station from scratch.

ESP32 Weather Station

Why Build Your Own Weather Station?

Commercial weather stations can cost hundreds of dollars and often come with proprietary limitations. Building your own ESP32-based station offers several advantages: complete customization, open-source flexibility, real-time data access, and the satisfaction of creating something useful with your own hands. Plus, you will learn valuable skills in IoT development, sensor integration, and data visualization along the way.

Components Required

ComponentSpecificationPurpose
ESP32 DevKitAny ESP32 boardMain controller with WiFi
BME280 SensorI2C interfaceTemperature, humidity, pressure
OLED DisplaySSD1306 128x64Local data display
Breadboard400 pointsPrototyping
Jumper WiresMale-to-femaleConnections
Power Supply5V USB or batteryPower

Understanding the BME280 Sensor

Weather Sensors

The BME280 is an integrated environmental sensor developed by Bosch Sensortec. It combines temperature, humidity, and pressure sensing in a single tiny package, making it perfect for weather station applications. The sensor communicates via I2C or SPI, with I2C being the simpler option for most projects.

BME280 Specifications

  • Temperature: -40°C to +85°C, ±0.5°C accuracy
  • Humidity: 0-100% RH, ±2% accuracy
  • Pressure: 300-1100 hPa, ±1 hPa accuracy
  • Interface: I2C (address 0x76 or 0x77)
  • Operating Voltage: 1.8V to 3.6V

Wiring Diagram

Connect the components as follows:

BME280 PinESP32 PinFunction
VCC3.3VPower
GNDGNDGround
SCLGPIO 22I2C Clock
SDAGPIO 21I2C Data

OLED Display Connections

OLED PinESP32 PinFunction
VCC3.3VPower
GNDGNDGround
SCLGPIO 22I2C Clock
SDAGPIO 21I2C Data

Complete Code

Weather Station Display
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <WiFi.h>
#include <HTTPClient.h>

// WiFi credentials
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";

// API endpoint (ThingSpeak example)
const char* server = "http://api.thingspeak.com/update";
String apiKey = "YOUR_API_KEY";

// BME280 object
Adafruit_BME280 bme;

// OLED display object
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// Sensor variables
float temperature, humidity, pressure, altitude;

void setup() {
  Serial.begin(115200);
  
  // Initialize BME280
  if (!bme.begin(0x76)) {
    Serial.println("BME280 not found!");
    while (1);
  }
  
  // Initialize OLED
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println("OLED not found!");
    while (1);
  }
  
  // Connect to WiFi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println(" WiFi connected!");
}

void loop() {
  // Read sensor data
  temperature = bme.readTemperature();
  humidity = bme.readHumidity();
  pressure = bme.readPressure() / 100.0F;
  altitude = bme.readAltitude(1013.25);
  
  // Display on OLED
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  
  display.setCursor(0, 0);
  display.print("Temp: ");
  display.print(temperature, 1);
  display.println(" C");
  
  display.setCursor(0, 16);
  display.print("Humidity: ");
  display.print(humidity, 1);
  display.println(" %");
  
  display.setCursor(0, 32);
  display.print("Pressure: ");
  display.print(pressure, 1);
  display.println(" hPa");
  
  display.setCursor(0, 48);
  display.print("Altitude: ");
  display.print(altitude, 1);
  display.println(" m");
  
  display.display();
  
  // Send to cloud
  sendToCloud();
  
  delay(60000); // Update every minute
}

void sendToCloud() {
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    String url = server + "?api_key=" + apiKey +
                 "&field1=" + String(temperature) +
                 "&field2=" + String(humidity) +
                 "&field3=" + String(pressure);
    
    http.begin(url);
    int httpCode = http.GET();
    
    if (httpCode > 0) {
      Serial.println("Data sent successfully!");
    } else {
      Serial.println("Error sending data");
    }
    http.end();
  }
}

Installing Required Libraries

Open the Arduino IDE and install these libraries through the Library Manager:

  • Adafruit BME280 Library
  • Adafruit Unified Sensor
  • Adafruit SSD1306
  • Adafruit GFX Library

Cloud Integration Options

PlatformFree TierFeaturesBest For
ThingSpeakYesCharts, MATLAB analysisBeginners
BlynkYesMobile app, widgetsMobile monitoring
InfluxDBYesTime-series databaseData analysis
Home AssistantSelf-hostedSmart home integrationHome automation

Adding Additional Sensors

Want to expand your weather station? Consider adding these sensors:

  • Anemometer: Wind speed measurement
  • Rain Gauge: Precipitation monitoring
  • UV Sensor: Ultraviolet index reading
  • Air Quality Sensor: PM2.5 and gas detection
  • Light Sensor: Lux measurement for solar applications

Power Options

For outdoor deployment, consider these power solutions:

  • Solar Panel + Battery: Self-sustaining operation with 5W panel and 18650 battery
  • Deep Sleep Mode: ESP32 can sleep between readings, extending battery life to months
  • USB Power: Simplest option for indoor deployment near power outlet

Enclosure Considerations

For accurate readings, your weather station needs proper ventilation while protecting electronics from rain:

  • Use a Stevenson screen design for professional results
  • 3D-printed enclosures with ventilation slots work well
  • Ensure the BME280 has airflow but is shielded from direct sunlight
  • Consider IP65 rated enclosures for outdoor deployment

Troubleshooting Common Issues

Incorrect Temperature Readings

If temperature reads too high, the sensor may be affected by heat from the ESP32. Add ventilation or reposition the sensor away from the microcontroller.

WiFi Connection Issues

Ensure your WiFi credentials are correct. For outdoor deployment, verify the WiFi signal reaches your location. Consider using an external antenna for better range.

I2C Device Not Found

Run an I2C scanner to verify device addresses. Some BME280 modules use 0x76, others use 0x77. Adjust your code accordingly.

Conclusion

Building an ESP32 weather station is an excellent project that combines hardware skills, software development, and cloud integration. The finished station provides valuable environmental data while teaching you fundamental IoT concepts that apply to countless other projects.

Start with the basic configuration described here, then expand with additional sensors and features as your skills grow. The modular nature of this project makes it easy to iterate and improve over time.

Need components for your weather station?
We have ESP32 boards, BME280 sensors, OLED displays, and all the components you need at competitive prices.

Request a Quote

Last updated: March 2026