Include Edit BMP

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

#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 0x76

Adafruit_BME280 BME280;

// LCD module connections (RS, E, D4, D5, D6, D7)


LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

void setup() {
Serial.begin(9600);

// set up the LCD's number of columns and rows


lcd.begin(16, 2);

Serial.println(F("Arduino + BME280"));

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("Temp:");
lcd.setCursor(0, 1);
lcd.print("Pres:");
}
char text[14];

// main loop
void loop()
{
// get temperature, pressure and altitude from library
float temperature = BME280.readTemperature(); // get temperature
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
sprintf(text, "%d.%02u%cC ", (int)temperature, (int)(temperature *
100)%100, 223);
lcd.setCursor(5, 0);
lcd.print(text);
// 2: print pressure
sprintf(text, "%u.%02u hPa ", (int)(pressure/100), (int)
((uint32_t)pressure % 100));
lcd.setCursor(5, 1);
lcd.print(text);

// print data on the serial monitor software


// 1: print temperature
Serial.print("Temperature = ");
Serial.print(temperature);
Serial.println(" °C");
// 2: print pressure
Serial.print("Pressure = ");
Serial.print(pressure/100);
Serial.println(" hPa");
// 3: print altitude
Serial.print("Approx Altitude = ");
Serial.print(altitude_);
Serial.println(" m");

Serial.println(); // start a new line


delay(2000); // wait 2 seconds

}
Edit

// 1: print temperature
lcd.setCursor(0, 0);
lcd.print("Temp:");
sprintf(text, "%d.%02u %cC ", (int)temperature, (int)(temperature *
100)%100,223);//%sebelum "cC" menunjukkan simbol derajat pada lcd, "223" untuk
mempertahankan simbol degree
lcd.setCursor(6, 0);//"(6, 0)" angka 6 menunjukkan posisi awal angka yang akan muncul di
lcd, 0 merupakan baris pertama
lcd.print(text);
// 2: print pressure
lcd.setCursor(0, 1);
lcd.print("Pres:");
sprintf(text, "%u.%02u hPa ", (int)(pressure/100), (int)((uint32_t)pressure % 100));
lcd.setCursor(5, 1);
lcd.print(text);
lcd.clear ();
delay (2000);

edit
lcd.clear ();
delay(2000);
lcd.clear ();
delay (2000);
lcd.setCursor(0, 0);
lcd.print("Alt:");
lcd.setCursor(0, 1);
lcd.print("Klbb:");
// 3: print Altitude
sprintf(text, "%d.%02u %cC ", (int)temperature, (int)(temperature *
100)%100,223);//%sebelum "cC" menunjukkan simbol derajat pada lcd, "223" untuk
mempertahankan simbol degree
lcd.setCursor(6, 0);//"(6, 0)" angka 6 menunjukkan posisi awal angka yang akan muncul di
lcd, 0 merupakan baris pertama
lcd.print(text);
// 4: print Humidity
sprintf(text, "%u.%02u hPa ", (int)(pressure/100), (int)((uint32_t)pressure % 100));
lcd.setCursor(5, 1);
lcd.print(text);
lcd.clear ();
delay(2000);

You might also like