How to Measure Temperature, Pressure, Humidity, and Altitude With BME280 and the Arduino Nano Every
by mahmoodmustafashilleh in Circuits > Arduino
754 Views, 3 Favorites, 0 Comments
How to Measure Temperature, Pressure, Humidity, and Altitude With BME280 and the Arduino Nano Every
In this tutorial, we'll explore how to connect the BME280 sensor to the Arduino Nano Every. By combining these two powerful components, you can unlock a wealth of environmental data for your projects. Whether you're a beginner or an experienced Arduino enthusiast, this guide will walk you through the simple steps required to establish the connection and start collecting valuable data. Let's dive in and unleash the potential of the BME280 and Arduino Nano Every!
Before we get started do not forget to subscribe or donate to the platform here.
Subscribe:
Support:
https://www.buymeacoffee.com/mmshilleh
You can purchase the BME280 from here:
Supplies
Make a Connection As Follows
Simply connect 4 jumper wires
Code
In the Arduino IDE make sure you are connected to your board.
Go to Library Manager and download the Adafruit BME package
Once the package is downloaded you can open the example code they have in
File > Examples > Adafruit BME280 Library > bme280test
I modified the code slightly shown here
/***************************************************************************
This is a library for the BME280 humidity, temperature & pressure sensor
Designed specifically to work with the Adafruit BME280 Breakout
----> http://www.adafruit.com/products/2650
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
to interface. The device's I2C address is either 0x76 or 0x77.
Adafruit invests time and resources providing this open source code,
please support Adafruit andopen-source hardware by purchasing products
from Adafruit!
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
BSD license, all text above must be included in any redistribution
See the LICENSE file for details.
***************************************************************************/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
#define SEALEVELPRESSURE_HPA (1012.7)
Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
unsigned long delayTime;
void setup() {
Serial.begin(9600);
while(!Serial); // time to get serial running
Serial.println(F("BME280 test"));
unsigned status;
// default settings
// status = bme.begin();
// You can also pass in a Wire library object like &Wire2
status = bme.begin(0x76);
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
Serial.print(" ID of 0x60 represents a BME 280.\n");
Serial.print(" ID of 0x61 represents a BME 680.\n");
while (1) delay(10);
}
Serial.println("-- Default Test --");
delayTime = 1000;
Serial.println();
}
void loop() {
printValues();
delay(delayTime);
}
void printValues() {
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" °C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.print("Approx. Altitude = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");
Serial.println();
}
I simply added status = bme.begin(0x76);
This allows us to use the bme280 sensor I have in the description. If this does not work for your BME280 try using 77 instead of 76 and that should work.
Another thing we have to adjust is the SEALEVELPRESSURE_HPA. You can get this value by googling your city; it may not be available in your area but this is what the algorithm needs to determine your altitude more accurately.
Once you have this setup you should be able to upload it to the Arduino to start getting values.
Conclusion:
Let me know if you have any issues with altitude or any other questions/comments. Hope you enjoyed the tutorial do not forget to subscribe to my channel for more simple sensor tutorials to help you in your sensor journeys.