* Interfacing Arduino with bmp280 temperature and pressure sensor


Download 8.64 Kb.
Sana14.12.2022
Hajmi8.64 Kb.
#1006060
Bog'liq
Interfacing Ard-WPS Office


/*
* Interfacing Arduino with BMP280 temperature and pressure sensor.
* Temperature and pressure values are displayed on 16x2 LCD.
* This is a free software with NO WARRANTY.
* https://simple-circuit.com/
*/
#include // include Wire library, required for I2C devices
#include // include Adafruit sensor library
#include // include adafruit library for BMP280 sensor
#include // include LCD library
// define device I2C address: 0x76 or 0x77 (0x77 is library default address)
#define BMP280_I2C_ADDRESS 0x76
Adafruit_BMP280 bmp280;
// 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 + BMP280"));
if (!bmp280.begin(BMP280_I2C_ADDRESS))
{
Serial.println("Could not find a valid BMP280 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 = bmp280.readTemperature(); // get temperature
float pressure = bmp280.readPressure(); // get pressure
float altitude_ = bmp280.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
}
// end of code.
Download 8.64 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling