Arduino weather station with SSD1306 OLED and BME280 sensor

This post shows how to build a weather station using Arduino UNO board and BME280 barometric pressure, temperature and humidity sensor.
The Arduino reads temperature & humidity & pressure values from the BME280 sensor and prints them (respectively in °C & RH% & hPa) on SSD1306 OLED display (128×64 pixel).
The BME280 is a digital barometric pressure, temperature and relative humidity sensor from Bosch Sensortec. In this project the BME280 sensor is used in I2C mode.

The SSD1306 OLED used in this project is configured to work in I2C mode, make sure that your display is configured to work in I2C mode, some displays need jumper placing or some soldering.
To see how to interface Arduino with SSD1306 OLED display, visit the following post:
Interfacing Arduino with SSD1306 OLED display

And to see how to interface Arduino with BME280 sensor for the first time, take a look at this post:
Arduino with BME280 pressure, temperature and humidity sensor

Hardware Required:

  • Arduino uno board
  • SSD1306 OLED display (128×64 pixel)
  • BME280 sensor module with 3.3V regulator and level shifter   —->  BME280 datasheet
  • Breadboard
  • Jumper wires

Arduino with SSD1306 OLED display and BME280 sensor circuit:
The image below shows project circuit diagram.

Hint:
The BME280 chip works with maximum voltage of 3.6V (supply voltage range is from 1.71 to 3.6V) which means we’ve to use a 3V3 voltage regulator to supply it from a 5V source.
Also, if we’re working with a 5V system (development board, microcontroller …) like the Arduino UNO board (ATmega328P microcontroller), we’ve to use a voltage level shifter (level converter) which converts the 3.3V (comes from the BME280 chip) into 5V (goes to the ATmega328P) and vice versa. This level shifter is for the I2C bus lines (clock and data).
The BME280 module shown in project circuit diagram has a built-in 3.3V regulator and level shifter.

Arduino BME280 SSD1306 OLED circuit

Generally, the BME280 module has at least 4 pins because it can work in SPI mode or I2C mode. For the I2C mode we need 4 pins: VCC, GND, SDA and SCL where:
GND (ground) is connected to Arduino GND pin,
VCC is the supply pin which is connected to Arduino 5V pin,
SDA is I2C bus serial data line, connected to Arduino analog pin 4 (A4),
SCL is I2C bus serial clock line, connected to Arduino analog pin 5 (A5).

The SSD1306 OLED display is connected to the Arduino UNO board as follows:
SSD1306 OLED GND goes to Arduino GND (ground),
SSD1306 OLED VDD to Arduino 5V,
SSD1306 OLED SDA pin (serial data) to Arduino analog pin 4 (A4),
SSD1306 OLED SCK pin (serial clock) to Arduino analog pin 5 (A5),
SSD1306 OLED RES pin (reset) to Arduino pin 4.

Pins A4 and A5 are hardware I2C module SDA and SCL pins (respectively) of the Arduino UNO.

The SSD1306 OLED display DC pin is connected to VDD which means I2C slave address of the device is 0x3D. If the DC pin is connected to ground (GND) then the I2C slave address will be 0x3C.

The SSD1306 OLED and the BME280 sensor are connected to the same I2C bus (slave devices), SCL and SDA pins of the two devices are connected to SCL and SDA pins of the Arduino board.
The I2C slave address of the SSD1306 OLED differs from the one of the BME280 sensor, this difference allows the master device (Arduino microcontroller) to talk to one of them (only one at a time).

Arduino with SSD1306 OLED and BME280 sensor code:
The following Arduino code requires 3 libraries from Adafruit Industries:
The first library is a driver for the SSD1306 OLED display which can be installed from Arduino IDE library manager (Sketch —> Include Library —> Manage Libraries …, in the search box write “ssd1306” and install the one from Adafruit).

The second library is Adafruit graphics library which can be installed also from Arduino IDE library manager.
The third library is for the BME280 sensor.

The previous 3 libraries can also be installed manually, download links are below:
Adafruit SSD1306 OLED driver     —->  direct link
Adafruit graphics library             —->  direct link
Adafruit BME280 Library            —->  direct link

You may need to install the Adafruit Unified Sensor library if it’s not already installed, download link is below:
Adafruit Unified Sensor library   —->    direct link

After the download, go to Arduino IDE —> Sketch —> Include Library —> Add .ZIP Library … and browse for the .zip file (previously downloaded).
The same thing for the other library files.

In the code there are total of 4 libraries, they’re included in the code as follows:

The SSD1306 OLED display reset pin connection is defined in the code as shown below:

As any other I2C device, the BME280 sensor has an I2C slave address which may be 0x76 or 0x77. This address depends on the connection of the SDO pin (used for SPI mode as serial data out or MISO), if the SDO pin is connected (directly or through resistor) to VCC (3.3V) the address will be 0x77, and if it’s connected to GND the address will be 0x76.

The default I2C address of the BME280 library is defined as 0x77 and my device I2C address is 0x76.
In the code, the definition of the I2C slave address is shown below:

The initialization of the BME280 sensor is done using the function begin() which returns 1 if OK and 0 if error. In the code the initialization with the previously defined address is as shown below:

Reading the values of temperature and pressure is done as shown below:

Note that the BME280 sensor library returns the value of the pressure in Pa unit and to convert it to hPa we’ve to divide it by 100.

1 bar = 10000 Pa = 100 hPa. ( 1 hPa = 100 Pa = 1 millibar)
Pa: Pascal
hPa: hectoPascal

Temperature, humidity and pressure values are displayed on the SSD1306 OLED screen.
If there is a problem with the BME280 sensor (for example wrong device address) the screen will display Connection Error.

Full Arduino Code:

The following picture shows a protoboard circuit of the project:

Arduino weather station with SSD1306 OLED display and BME280 sensor


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

2 thoughts on “Arduino weather station with SSD1306 OLED and BME280 sensor”

  1. Thank you for publishing this weatherstation.
    As you may see at my albumpage https://photocws.jalbum.net/Weatherstation/ the weatherstation is running, but
    there seems to be an issue with the width/height of the characters on the Oled display SSD1306 I am using.
    It is an Oled 0,96 inch display version with only 4-pins, SSD1306, 128 X 64 characters with a SDA and a SCL pin and no reset pin.
    You are probably using the 1,3 inch version Oled display.
    Looking into the Adafruit examplesketch ssd1306_128x64_i2c.ino there are i.m.o. a few modifications needed in your sketch to get it working.

    After line 11 in your sketch I added two lines:
    #define SCREEN_WIDTH 128 // OLED display width.
    #define SCREEN_HEIGHT 64 // OLED display height.

    Because this 4-pin display has no RESET pin, I deleted the line:
    #define OLED_RESET 4 // define display reset pin
    .
    And finally I modified your line:
    Adafruit_SSD1306 display(OLED_RESET); // initialize Adafruit display library
    into:
    Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT); // initialize Adafruit display library

    Now after uploading the modified sketch the content on your display is the same as on my 4-pins display, both type SSD1306.

    I have also tested the sketch when I changed your line
    #define OLED_RESET 4 // define display reset pin into
    #define OLED_RESET -1
    and changed the line
    Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT); // initialize Adafruit display library into
    Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); // initialize Adafruit display library
    but that made no difference in the display content.

    For your information. I needed I2C address 0x3C for the Oled display and I2C address 0x76 fro the BME280. And I used an Arduino Nano (same pin names as the Uno)

    Conclusion, if anyone is using the 4-pins type SSD1306, 0,96 “, then these few modifications in your sketch should be necessary.

  2. created project using all parts and librarys and uploaded the code using arduino uno and my ssd1306 using IC2 MODE only reads hafe of the data .the bottom haft is off the screen. any help will be app.

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top