How to measure Temperature Pressure and Altitude using BMP280 sensor

 







             CODE 

#include <Wire.h>

#include <SPI.h>

#include <Adafruit_BMP280.h>

#include <LiquidCrystal_I2C.h>


#define BMP_SCK  (13)

#define BMP_MISO (12)

#define BMP_MOSI (11)

#define BMP_CS   (10)


Adafruit_BMP280 bmp; // I2C

//Adafruit_BMP280 bmp(BMP_CS); // hardware SPI

//Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);



LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3,POSITIVE); 

  byte degree_symbol[8] = 

              {

                0b00111,

                0b00101,

                0b00111,

                0b00000,

                0b00000,

                0b00000,

                0b00000,

                0b00000

              };

void setup() {

  Serial.begin(9600);

  Serial.println(F("BMP280 test"));


  if (!bmp.begin(0x76)) {

    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));

    while (1);

  }


  /* Default settings from datasheet. */

  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */

                  Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */

                  Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */

                  Adafruit_BMP280::FILTER_X16,      /* Filtering. */

                  Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */




  lcd.begin(16,2);

  lcd.backlight();

  lcd.clear();

  lcd.setCursor(0,0);

  lcd.print("TECH TECHNOLOGY");

  lcd.setCursor(7,1);

  lcd.print("PK");

  delay(5000);

  lcd.clear();

}


void loop() {

   

    float temp = bmp.readTemperature();

    float pressure = bmp.readPressure();

    float alt = bmp.readAltitude(1013.25);

    Serial.print(F("Temperature = "));

    Serial.print(temp);

    Serial.println(" *C");

    

    Serial.print(F("Pressure = "));

    Serial.print(pressure);

    Serial.println(" Pa");


    Serial.print(F("Approx altitude = "));

    Serial.print(alt); /* Adjusted to local forecast! */

    Serial.println(" m");




    Serial.println();

   // delay(2000);


    lcd.setCursor(0,0);

    lcd.print("Temperature "); 

    lcd.setCursor(0,1);

    lcd.print(temp);

    lcd.setCursor(6,1);

    lcd.write(1);

    lcd.createChar(1, degree_symbol);

    lcd.setCursor(7,1);

    lcd.print("C");

    delay(8000);

    lcd.clear();

    lcd.setCursor(0, 0);

    lcd.print("Pressure    ");

    lcd.setCursor(0,1);

    lcd.print(pressure);

    lcd.print(" pa");

    delay(8000);

    lcd.clear();

    lcd.setCursor(0, 0);

    lcd.print("Altitude "); 

    lcd.setCursor(0,1);    

    lcd.print(alt);

    lcd.print(" m");

    delay(8000);

    lcd.clear();

    

  

}

Post a Comment

Previous Post Next Post

Contact Form