Room Weather Station Using Arduino & BME280
by Harsh Dethe in Circuits > Microcontrollers
4643 Views, 15 Favorites, 0 Comments
Room Weather Station Using Arduino & BME280
Previously I shared a simple weather station which displayed the Temperature and Humidity of local area. The problem with it was that it would take time to update and the data was not accurate. In this tutorial we will make an Indoor weather monitoring system which can be helpful for keeping the note of temperature, humidity and pressure within the room.
So without wasting any more time, let's get started.
Requirements:
Here is the list of parts we will be using for the build.
- GY-BME280 Sensor...............(Amazon US / Amazon EU)
- Arduino UNO..........................(Amazon US / Amazon EU)
- Arduino Pro Mini.....................(Amazon US / Amazon EU)
- OLED 128*64 Display.............(Amazon US / Amazon EU)
- Breadboard with Jumpers.......(Amazon US / Amazon EU)
Along with the above components, we also need some libraries too:
- Arduino IDE
- Adafruit_BME280.h Library
- Adafruit_SH1106.h Library
- Adafruit_GFX.h Library
Connections:
We will use I2C connection for communication between the devices. I2C uses 2 pins Serial Data (SDA) and Serial Clock (SCL) to communicate. So in the connections I have connected the pins in following configuration:
- SDA = A5
- SCL = A4
- GND = GND
- VCC = 3.3v
The connections are same for Arduino UNO and Pro Mini.
Coding:
Before uploading any code, we need to install the required libraries.
To install libraries Goto >> Tools >> Manage Libraries
In the search box enter the name of libraries and install all one by one.
After installing libraries restart the IDE.
NOTE: The libraries and code is for the Sensor and OLED module I have used (Links provided in previous step). If you are using any other modules, refer the datasheets to know what libraries are used.
Write the code given below in a new file in Arduino IDE:
#include <Adafruit_BME280.h> #include <Adafruit_SH1106.h> #include <Adafruit_GFX.h> #include <Fonts/FreeSerif9pt7b.h> #define OLED_RESET 4 Adafruit_SH1106 display(OLED_RESET); Adafruit_BME280 bme; void setup() { Serial.begin(9600); display.begin(SH1106_SWITCHCAPVCC, 0x3C); display.setFont(&FreeSerif9pt7b); display.display(); delay(2000); display.clearDisplay(); if (!bme.begin(0x76)) { Serial.println("Could not find a valid BME280 sensor, check wiring!"); while (1); } } void loop() { display.clearDisplay(); Serial.print("Temperature = "); Serial.print(bme.readTemperature()); //prints in *C //Serial.print(bme.readTemperature() * 9 / 5 + 32); //prints in *F Serial.println("*C"); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0,15); display.print("Temp:"); display.print((int)bme.readTemperature()); //prints in *C //display.print(bme.readTemperature() * 9 / 5 + 32); //prints in *F display.println("*C"); display.display(); Serial.print("Pressure = "); Serial.print(bme.readPressure()/100.0F); Serial.println("hPa"); display.setTextSize(1); display.setTextColor(WHITE); display.print("Press:"); display.print(bme.readPressure()/100.0F); display.println("Pa"); display.display(); Serial.print("Humidity = "); Serial.print(bme.readHumidity()); Serial.println("%"); display.setTextSize(1); display.setTextColor(WHITE); display.print("Hum:"); display.print((int)bme.readHumidity()); display.println("%"); display.display(); Serial.println(); delay(1000); }
Connect the arduino to your computer, select the right port and hit upload.
After a few seconds you should see the display turn on.
Final Note:
The display will show Temperature, Humidity and Atmospheric Pressure. You can also see the data in Serial Monitor. You can make changes to the code or design as you wish. In next tutorial I will make this circuit on a PCB and build an enclosure for it. Make sure you follow for more updates.
If you are interested in robotics and want to make a simple robot, Checkout my ebook "Mini WiFi Robot". It has step by step instruction to build a simple robot that can be controlled over WiFi network.
Hope this instructable is informative. If you have any doubt, feel free to ask in comments.