Lesson 96-1: Barometric Pressure, Temperature, and Approximate Altitude Sensor BMP390 with Arduino Basic Code
In this lesson, the BMP390 is explained, with wiring shown for I2C and SPI. It then shows how to display barometric pressure, temperature, and approximate altitude on the serial monitor, on an LCD1602, and on an LCD2004. A full wiring diagram is shown. Library installation is shown, and approximate altitude is measured on the first floor and compared with the altitude on the 25th floor. The code is fully explained and demonstrated using an Arduino UNO and an Arduino MEGA.
434-Lesson 96: Barometric Pressure, Temperature, and Approximate Altitude Sensor BMP390 with LCD
语言: C++
++
/*
* Lesson 96: Using Precision BMP390 Barometric Pressure and Temperature Sensor
* with Arduino
* Watch video instruction on YouTube: https://youtu.be/XevQYG_A5xA
*
* Code updated by Ahmad Shamshiri for Robojax.com
* on Jan 13, 2022 at 17:10 in Ajax, Ontario, Canada
This video is part of Arduino Step by Step Course which starts here: https://youtu.be/-6qSrDUA5a8
If you found this tutorial helpful, please support me so I can continue creating content like this
and make a donation using PayPal http://robojax.com/L/?id=64
This is a library for the BMP390 temperature & pressure sensor
Designed specifically to work with the Adafruit BMP388 Breakout
----> http://www.adafruit.com/products/3966
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
to interface.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing products
from Adafruit!
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
BSD license, all text above must be included in any redistribution
**************************************************************************
*/
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BMP3XX.h"
#define SEALEVELPRESSURE_HPA (1013.25)
float temperatureC, temperatureK, temperatureF, pressure, altitude;
Adafruit_BMP3XX bmp;
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("Adafruit BMP388 / BMP390 test");
if (!bmp.begin_I2C()) { // hardware I2C mode, can pass in address & alt Wire
Serial.println("Could not find a valid BMP3 sensor, check wiring!");
while (1);
}
// Set up oversampling and filter initialization
bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);
bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);
bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
bmp.setOutputDataRate(BMP3_ODR_50_HZ);
}
void loop() {
if (! bmp.performReading()) {
Serial.println("Failed to perform reading :(");
return;
}
readValues();
Serial.print("Temperature C: ");
Serial.print(temperatureC);
printDegree();
Serial.println(" C");
Serial.print("Pressure: ");
Serial.print(pressure);
Serial.println(" hPa");
Serial.print("Approximate Altitude: ");
Serial.print(altitude);
Serial.println(" m");
Serial.println();
if(temperatureC >38.0)
{
digitalWrite(10, HIGH);
}else{
digitalWrite(10, LOW);
}
delay(2000);
}
/*
* readValues()
* @brief reads the temperature based on the TEMPERATURE_UNIT
* @param average temperature
* @return returns one of the values above
* Written by Ahmad Shamshiri for robojax.com
* on Jan 15, 2022 at 08:02 in Ajax, Ontario, Canada
*/
void readValues()
{
//Robojax.com BMP390
temperatureC = bmp.temperature;// return Celsius
temperatureF = bmp.temperature *9/5 + 32;//convert to Fahrenheit
temperatureK = bmp.temperature + 273.15;//convert to Kelvin
altitude = bmp.readAltitude(SEALEVELPRESSURE_HPA);// read altitude
pressure = bmp.pressure / 100.0F; // get pressure in hecto pascal
}// readValues()
/*
* @brief prints degree symbol on serial monitor
* @param none
* @return returns nothing
* Written by Ahmad Shamshiri on July 13, 2019
* for Robojax Tutorial Robojax.com
*/
void printDegree()
{
Serial.print("\\xC2");
Serial.print("\\xB0");
}
|||您可能需要的东西
-
全球速卖通从AliExpress购买它s.click.aliexpress.com
-
Banggood从Banggood购买它banggood.com
资源与参考
-
外部BMP390 博世官方产品页面bosch-sensortec.com
-
外部从AliExpress购买它s.click.aliexpress.com
-
外部从Banggood购买它banggood.com
-
外部从亚马逊美国购买。amzn.to
-
外部从加拿大亚马逊购买它amzn.to
-
外部从所有其他亚马逊网站购买。amzn.to
文件📁
没有可用的文件。