I had a BME280 sensor, and an extra LCD screen so why not make something that tells me the weather condition in the house.
BME280
A BME280 is a sensor that comes in multiple form factors and tells you three (technically four) data points about atmospheric conditions, temperature, air pressure, humidity, and not really altitude.
The BME280 I happened to have had 6 wires, most I see online have four pins. If you happen to get one with 6 wires simply pretend that CS and MISO aren't there and viola you have a 4 wire BME280
Hooking the BME280 up to the Arduino Uno is not too difficult: The key is getting the SCL pin to Pin A5 and the SDA to A4. (Note I use a breadboard for all this stuff, but I wanted to make the pictures easier to follow
There are several places that show how to hook up an 16x2 LCD to an UNO, so why not have one more. Like most people we only need the higher register of four pins for the LCD not all eight
The hardest part is hooking up the rotary potentiometer, which gets connected to the V0 pin on the LCD. This is for the contrast on the LCD and turning it can make things vastly easier to see.
The following code cycles through the readings. Please take altitude with a HUGGGGE grain of salt. You must know the precise sea level air pressure for the equation to work correctly
/*
* Interfacing Arduino with BME280 temperature, humidity and pressure sensor.
* Temperature, humidity and pressure values are displayed on 16x42LCD.
* This is a free software with NO WARRANTY.
*/
#include <Wire.h> // include Wire library, required for I2C devices
#include <Adafruit_Sensor.h> // include Adafruit sensor library
#include <Adafruit_BME280.h> // include adafruit library for BME280 sensor
#include <LiquidCrystal.h> // include LCD library
// define device I2C address: 0x76 or 0x77 (0x77 is library default address)
#define BME280_I2C_ADDRESS 0x77
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme280;
// LCD module connections (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
void setup()
{
Serial.begin(9600);
// set up the LCD's number of columns and rows
lcd.begin(16,2);
Serial.println(F("Arduino + BME280 sensor"));
if (!bme280.begin(BME280_I2C_ADDRESS))
{
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
lcd.setCursor(0, 0);
lcd.print("Arduino + BME280");
lcd.setCursor(0, 1);
}
char text[13];
// main loop
void loop()
{
// get temperature, pressure and altitude from library
float temperature = bme280.readTemperature(); // get temperature
float humidity = bme280.readHumidity(); // get humidity
float pressure = bme280.readPressure(); // get pressure
float altitude_ = bme280.readAltitude(1013.25); // get altitude (this should be adjusted to your local forecast)
// print data on the LCD screen
// 1: print temperature
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Arduino + BME280");
lcd.setCursor(0,1);
lcd.print("Temp =");
sprintf(text, "%d.%02u%cC ", (int)temperature, (int)(temperature * 100)%100, 223);
lcd.setCursor(7, 1);
lcd.print(text);
delay(3000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Arduino + BME280");
lcd.print(text);
// 2: print humidity
lcd.setCursor(0,1);
lcd.print("Humid =");
sprintf(text, "%d.%02u %% ", (int)humidity, (int)(humidity * 100)%100);
lcd.setCursor(8, 1);
lcd.print(text);
delay(3000);
// 3: print pressure
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Arduino + BME280");
lcd.setCursor(0,1);
lcd.print("Press =");
sprintf(text, "%u.%02u hPa ", (int)(pressure / 100), (int)((uint32_t)pressure % 100));
lcd.setCursor(8, 1);
lcd.print(text);
delay(3000);
// 4: print altitude
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Arduino + BME280");
lcd.setCursor(0,1);
lcd.print("Altitude =");
float altitude = 44330 * (1.0 - pow((pressure / 100) / 1022.96, 0.1903));
sprintf(text, "%u.%01u m ", (int)(altitude));
lcd.setCursor(11, 1);
lcd.print(text);
delay(3000);
// print data on the serial monitor software
// 1: print temperature
Serial.print("Temperature = ");
Serial.print(temperature);
Serial.println(" �C");
// 1: print humidity
Serial.print("Humidity = ");
Serial.print(humidity);
Serial.println(" %");
// 3: print pressure
Serial.print("Pressure = ");
Serial.print(pressure / 100);
Serial.println(" hPa");
// 4: print altitude
Serial.print("Approx Altitude = ");
Serial.print(altitude);
Serial.println(" m");
Serial.println(); // start a new line
delay(2000); // wait 2 seconds
}
// end of code.