Robojax

Lesson 96: Barometric Pressure, Temperature, Approximate Altitude Sensor BMP390 with LCD

Lesson 96: Barometric Pressure, Temperature, Approximate Altitude Sensor BMP390 with LCD

Please select other codes for this lecture from the links below.

  • Purchase it from Amazon USA
  • Purchase it from Amazon Canada
  • Purchase it from all other Amazon
  • Purchase it from AliExpress
  • Purchase it from Banggood
  • BMP390 Bosch Official Product page
  • Part 6: Temperatures Sensors

    In this lesson BMP390 is explained, wiring shown for I2C and SPI. Then shown to display barometric pressure, temperature and approximate altitude on the serial monitor, on LCD1602, on LCD2004. Full wiring diagram and wiring shown. Library installation shown and approximate altitude is measurged on first floor and compared it with altitude on 25th floor. Code is fully explained and demonstrated using Arduino UNO and Arduino MEGA.

    Affiliated with Amazon USA

    Affiliated with AliExpress

    
     /*
     * Lesson 96: Using Precision BMP390 Barometric Pressure and Temperatrure Sensor
     * with Arduino
     * Wath 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 contents like this
    and make 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("Temprature 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  BMPP390 
    
      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");  
    }