Arduino Weather Station with OLED Display
Build a compact weather station that measures temperature, humidity, pressure, and displays readings on an OLED screen.
Parts List
- Arduino Nano
- BME280 Sensor
- 0.96" OLED Display
- Breadboard
- Jumper Wires
Step-by-Step Instructions
Wire BME280 Sensor
Connect the BME280 sensor to the Arduino Nano via the I2C bus. Wire the SDA pin to A4 and SCL pin to A5 on the Nano, and connect VCC to 3.3V and GND to ground. Ensure the sensor is oriented correctly and seated firmly on the breadboard for reliable readings.
Connect OLED Display
Wire the 0.96-inch OLED display to the same I2C bus by connecting its SDA and SCL pins to A4 and A5 respectively. Since both the sensor and display share the I2C bus, they can operate simultaneously using different addresses. Connect the OLED VCC to 3.3V and GND to ground, making sure the wiring is clean and free of shorts.
Install Libraries
Open the Arduino IDE Library Manager and install the Adafruit BME280 library along with its dependency, the Adafruit Unified Sensor library. Also install the Adafruit SSD1306 library for OLED display control and the Adafruit GFX Library for graphics primitives. These libraries handle all the low-level communication so you can focus on reading and displaying sensor data.
Write Display Code
Create an Arduino sketch that initializes both the BME280 sensor and the OLED display in the setup function. In the main loop, read temperature, humidity, and pressure values from the sensor every two seconds. Format the readings as readable text strings and display them on the OLED screen, updating the values continuously to create a real-time weather station display.
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <Adafruit_SSD1306.h>
Adafruit_BME280 bme;
Adafruit_SSD1306 display(128, 64, &Wire);
void setup() {
bme.begin(0x76);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}
void loop() {
float t = bme.readTemperature();
float h = bme.readHumidity();
float p = bme.readPressure() / 100.0;
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0,0);
display.printf("Temp: %.1f C\n", t);
display.printf("Hum: %.1f %%\n", h);
display.printf("Pres: %.1f hPa\n", p);
display.display();
delay(2000);
}