INT 21h

Hi, I am Vladimir Smagin, SysAdmin, DevOps and barely good guy. Telegram Email / GIT / Микроблог / Thingiverse / GPG

Weather station on Arduino Nano, BME280 and I2C connected 44780 display

№ 10053 В разделах: 3D printer model Программирование Электроника от May 24th, 2019,

30 minutes of programming and soldering and I have fully functional weather station for my garage. Source code at the end of page.

Arduino i2c pins: A4 data, A5 clock. BME280 must be 5V tolerant!

3D-printing model https://www.thingiverse.com/thing:3649543

Source code:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

// set i2c addresses
#define BME280_ADDRESS 0x76
#define DISP_ADDRESS 0x20

LiquidCrystal_I2C lcd(DISP_ADDRESS, 16, 2);
Adafruit_BME280 bme;

// init some values
int termoValue = 0;    //C
int pressureValue = 0; //mmHg
int humidityValue = 0; //%

void setup()
{
  lcd.init();
  lcd.backlight();
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Life support");
  lcd.setCursor(0, 1);
  lcd.print("control panel");
  delay(2000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Vladimir Smagin");
  lcd.setCursor(0, 1);
  lcd.print("21h@blindage.org");
  delay(2000);
  lcd.clear();
  Serial.begin(115200);

  if (!bme.begin(BME280_ADDRESS))
  {
    Serial.println(F("\nCould not find a valid BME280 sensor, check wiring!"));
  }
}

void loop()
{
  // read sensor
  pressureValue = bme.readPressure() / 133.32239F;
  termoValue = bme.readTemperature();
  humidityValue = bme.readHumidity();

  // send to serial port, comment after debug
  Serial.print("Termo: ");
  Serial.println(termoValue);
  Serial.print("Humidity: ");
  Serial.println(humidityValue);
  Serial.print("Pressure: ");
  Serial.println(pressureValue);

  // lcd.clear(); // comment if display flickers
  lcd.setCursor(0, 0);
  lcd.print("T: " + String(termoValue) + String((char)223) + "C");

  lcd.setCursor(9, 0);
  lcd.print("H: " + String(humidityValue) + "%");

  lcd.setCursor(0, 1);
  lcd.print("Press: " + String(pressureValue) + " mmHg");

  // check every 2 seconds
  delay(2000);
}

Нет комментариев »

Leave a Reply

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

*

Яндекс.Метрика

Fortune cookie: Today's spam: All the Hollywood guys had to make their members bigger.