Community project

ESP32 WiFi Weather Station

Photo of ESP32 WiFi Weather Station
Generated with AI

Tejaswini naidu

Published December 5, 2026

This ESP32 weather station displays real-time temperature, humidity, and atmospheric pressure on a local OLED screen while serving the data over WiFi to a web browser. The BME280 sensor provides accurate environmental readings via I2C, and the built-in web server lets users check conditions from any device on the network.

This guide includes a complete wiring diagram showing how to connect the BME280 and SSD1306 display to the ESP32, a full parts list, step-by-step assembly instructions, and ready-to-deploy firmware with a responsive web interface. Makers will have everything needed to build a functional weather station from scratch.

Wiring diagram

Wiring diagram for ESP32 WiFi Weather Station
Loading diagram…

Gather all the parts

QtyComponent
1

SSD1306 OLED

0.96-inch 128 x 64 white monochrome OLED display module driven by an SSD1306 controller over I2C (address 0x3C). It runs from 3 V to 5 V and connects through a 4-pin 2.54 mm header (GND, VCC, SCL, SDA); the self-emitting pixels need no backlight.

1

Adafruit BME280 I2C or SPI Temperature Humidity Pressure Sensor

Adafruit breakout for the Bosch BME280 sensor, measuring temperature, relative humidity and barometric pressure. It talks over I2C (address 0x77, or 0x76 with SDO to ground) or SPI, runs from 3 to 5 V through an on-board regulator with level shifting, and connects through STEMMA QT/Qwiic connectors or a 7-pin 0.1 in header.

Assemble it in 4 steps

1. Lay out the modules

Unplug USB. Put the OLED and Adafruit BME280 on a solderless breadboard, with each pin on its own isolated strip. If headers are not installed, solder them before inserting the modules. If the ESP32 is too wide to leave holes free on both sides, keep it beside the breadboard and use female-to-male jumpers.

2. Connect power and ground

Run the ESP32 3V3 and GND to separate breadboard strips. Connect OLED VCC and BME280 VIN to the 3V3 strip. Connect both module GND pins to the ground strip.

  • Use 3V3
  • not 5V. Check the printed pin labels before connecting USB.

3. Connect the shared data lines

Join ESP32 GPIO21 to OLED SDA and BME280 SDI using a shared strip. Join ESP32 GPIO22 to OLED SCL and BME280 SCK using a different strip. Leave the sensor CS, SDO, and 3Vo pins unconnected.

4. Connect USB power

Use a USB data cable matching the board socket. Power the station from a computer during testing or from a regulated 5 V USB supply through the board USB socket afterward.

Review all connections

1. Connections between "oled" and "ESP32"

FunctionoledESP32
powerVCC3V3
groundGNDGND
i2cSDAGPIO 21
i2cSCLGPIO 22

2. Connections between "sensor" and "ESP32"

FunctionsensorESP32
powerVIN3V3
groundGNDGND
i2cSDI → SSD1306 OLED SDAEXT
i2cSCK → SSD1306 OLED SCLEXT

Deploy the firmware

#include <Arduino.h>
#include <Wire.h>
#include <WiFi.h>
#include <WebServer.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_BME280.h>

// Set these locally before Deploy. Do not share your password.
const char* WIFI_SSID = "";
const char* WIFI_PASSWORD = "";
constexpr int SDA_PIN = 21, SCL_PIN = 22;
Adafruit_SSD1306 oled(128,64,&Wire,-1,100000,100000);
Adafruit_BME280 bme;
WebServer server(80);
bool screen, sensor, valid;
float temperature, humidity, pressure;
String previous;
uint32_t sampled;

const char PAGE[] PROGMEM = R"HTML(<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Weather Station</title><style>
*{box-sizing:border-box}body{margin:0;background:#081626;color:#e5f2ff;font:1rem system-ui}main{max-width:960px;margin:auto;padding:clamp(20px,5vw,48px)}header{border-bottom:1px solid #325172;margin-bottom:24px}h1{font-size:clamp(2rem,6vw,3.5rem);margin:0}#status{color:#a8d4f7}section{display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:16px}article{background:linear-gradient(150deg,#203f5e,#112639);border:1px solid #325172;border-radius:20px;padding:22px}h2{font-size:1rem;color:#b7d1e9}output{display:block;font-size:2rem;font-weight:bold;margin-bottom:14px}progress{width:100%;accent-color:#56d9c1}small{display:block;color:#b7d1e9}</style><main><header><h1>Weather Station</h1><p id="status" role="status">Connecting…</p></header><section id="cards"></section><p>Pressure is measured at the station, not corrected to sea level.</p></main><script>
const fields=[['Temperature','°C',0,40],['Humidity','%',0,100],['Pressure','hPa',800,1100]];
const statusLine=document.querySelector('#status');
const cards=fields.map(([name,unit,min,max])=>{const a=document.createElement('article');a.innerHTML=`<h2>${name}</h2><output>—</output><progress aria-label="${name} gauge" max="${max-min}" value="0" hidden></progress><small>Gauge: ${min}–${max} ${unit}</small>`;document.querySelector('#cards').append(a);return [a.querySelector('output'),a.querySelector('progress'),unit,min,max];});
function show(values){cards.forEach(([label,gauge,unit,min,max],i)=>{const n=values?.[i];label.textContent=Number.isFinite(n)?`${n.toFixed(1)} ${unit}`:'—';gauge.hidden=!Number.isFinite(n);if(!gauge.hidden)gauge.value=Math.max(0,Math.min(max-min,n-min));});}
async function refresh(){const ctrl=new AbortController();const timeout=setTimeout(()=>ctrl.abort(),3000);try{const r=await fetch('/api/weather',{cache:'no-store',signal:ctrl.signal});if(!r.ok)throw Error();const data=await r.json();show(data.values);statusLine.textContent=data.values?'Live · refreshed '+new Date().toLocaleTimeString():'Sensor unavailable · check BME280 wiring';}catch{show(null);statusLine.textContent='Station unreachable · retrying';}finally{clearTimeout(timeout);setTimeout(refresh,2000);}}refresh();
</script></html>)HTML";

bool present(uint8_t address){Wire.beginTransmission(address);return Wire.endTransmission()==0;}

void sample(){
  if(!sensor) sensor=(present(0x77)&&bme.begin(0x77,&Wire)) || (present(0x76)&&bme.begin(0x76,&Wire));
  valid=false;
  if(sensor && (present(0x77)||present(0x76))){
    temperature=bme.readTemperature(); humidity=bme.readHumidity(); pressure=bme.readPressure()/100.0f;
    valid=isfinite(temperature)&&isfinite(humidity)&&isfinite(pressure)&&humidity>=0&&humidity<=100&&pressure>0;
  }
  if(valid) Serial.printf("%.1f C | %.1f %% RH | %.1f hPa\n",temperature,humidity,pressure);
  else {sensor=false;Serial.println("BME280 unavailable (check 0x77/0x76 and verify it is not a BMP280)");}
}

void render(bool online){
  if(!screen)return;
  String text="Weather Station\n\n";
  if(valid){char rows[80];snprintf(rows,sizeof(rows),"Temp: %.1f C\nRH:   %.1f %%\nPres: %.1f hPa\n",temperature,humidity,pressure);text+=rows;}
  else text+="BME280 unavailable\nCheck wiring\n\n";
  if(online){text+="WiFi: online\n";text+=WiFi.localIP().toString();}
  else text+=*WIFI_SSID?"WiFi: offline":"WiFi: not set";
  if(text==previous)return;
  previous=text;oled.clearDisplay();oled.setCursor(0,0);oled.print(text);oled.display();
}

void setup(){
  Serial.begin(115200);
  Wire.begin(SDA_PIN,SCL_PIN,100000);
  uint8_t address=present(0x3C)?0x3C:(present(0x3D)?0x3D:0);
  screen=address && oled.begin(SSD1306_SWITCHCAPVCC,address,false,false);
  Serial.println(screen?"OLED responding":"OLED not detected (check 0x3C/0x3D)");
  if(screen){oled.setTextSize(1);oled.setTextColor(SSD1306_WHITE);oled.setTextWrap(false);render(false);}
  WiFi.mode(WIFI_STA);
  WiFi.setAutoReconnect(true);
  if(*WIFI_SSID) WiFi.begin(WIFI_SSID,WIFI_PASSWORD);
  else Serial.println("Set WIFI_SSID and WIFI_PASSWORD to enable the dashboard");
  server.on("/",HTTP_GET,[]{server.send_P(200,"text/html; charset=utf-8",PAGE);});
  server.on("/api/weather",HTTP_GET,[]{
    char json[110]="{\"values\":null}";
    if(valid)snprintf(json,sizeof(json),"{\"values\":[%.2f,%.2f,%.2f]}",temperature,humidity,pressure);
    server.sendHeader("Cache-Control","no-store");server.send(200,"application/json",json);
  });
  server.begin();sample();sampled=millis();
}

void loop(){
  bool online=WiFi.status()==WL_CONNECTED;
  static bool wasOnline=false;
  if(online!=wasOnline){wasOnline=online;if(online)Serial.println("Dashboard: http://"+WiFi.localIP().toString());else Serial.println("WiFi disconnected; automatic reconnect enabled");}
  if(online)server.handleClient();
  if(millis()-sampled>=2000){sampled=millis();sample();}
  render(online);delay(20);
}

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.

Open in Schematik