Skip to content

Instantly share code, notes, and snippets.

@patrykgruszka
Created April 13, 2020 09:53
Show Gist options
  • Save patrykgruszka/7cc3e3983681efe4c9cbea3358d34c2c to your computer and use it in GitHub Desktop.
Save patrykgruszka/7cc3e3983681efe4c9cbea3358d34c2c to your computer and use it in GitHub Desktop.
Arduino weather station BMP280 sensor
#include <LiquidCrystal.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp; // I2C
// VCC -> 3.3V
// GND -> GND
// SCL -> A5
// SDA -> A4
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
byte degChar[8] = {
0b00010,
0b00101,
0b00010,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};
uint8_t bmp280address = 0x76;
uint8_t bmp280chipid = 0x60;
void setup() {
Serial.begin(9600);
if (!bmp.begin(bmp280address, bmp280chipid)) {
Serial.println(F("BMP280 SENSOR IS DEAD"));
while (1);
}
bmp.setSampling(
Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
Adafruit_BMP280::FILTER_X16, /* Filtering. */
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
lcd.createChar(0, degChar);
lcd.begin(16, 2);
}
void loop() {
float temp = bmp.readTemperature();
float pressure = bmp.readPressure() / 100;
lcd.clear();
lcd.setCursor(0, 0);
if (temp > 30) {
lcd.print("Hot ");
} else if (temp > 20) {
lcd.print("Warm ");
} else if (temp > 15) {
lcd.print("Cool ");
} else {
lcd.print("Cold ");
}
lcd.print(temp);
lcd.print(" ");
lcd.write((uint8_t)0); // deg symbol
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print(pressure);
lcd.print(" hPa");
Serial.println();
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment