Project 6 : Displaying BMP280 Sensor Measurement using LCD I2C

๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ

Welcome back to my blogspot dear

Where we share stories far and near

From one project to another project we share

Join  and let's explore without a care

๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ๐Ÿ’ฌ


๐Ÿ‘‹๐Ÿ‘‹๐Ÿ‘‹ Hello guys, welcome back to my blog. In this blog, I will create a project that measures temperature, pressure and altitude using the BMP 280 sensor and uses an I2C LCD to display the measurements on the LCD monitor. let's get started straight now.๐Ÿ˜€




๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข๐Ÿ’ข

๐Ÿ”จSET UP๐Ÿ”จ

1. 1 Pcs of ESP32


2. 9 Pcs of Male to Female Cable Jumper


3.  3 Pcs of Male to Male Cable Jumper


4. 1 Pcs of Micro USB cable


5.1 Pcs of LCD i2c 16 x 2

6. 1 Pcs Of .Barometetric Pressure Sensor (BMP280)



๐Ÿ‘ฃSTEP BY STEP๐Ÿ‘ฃ

Temperature, pressure, and altitude were all measured. The initial step is to take temperature and pressure readings, which will be displayed on the LCD monitor using a horizontal scrolling text technique. The second phase is to display the altitude measurement, accompanied by the remark "thank you."

1.Set up the sensor circuit as illustrated in Figure .




2.To facilitate the preparation of the circuit, adopt the following LCD and BMP schemes


3.Launch our Arduino IDE and copy this code below

/* 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/
 */

 // ESP32 SDA to D21 SCL to D22
 // ESP8266 SDA to D2 SCL to D1
 
#include <Wire.h>             // include Wire library, required for I2C devices
#include <Adafruit_Sensor.h>  // include Adafruit sensor library
#include <Adafruit_BMP280.h>  // include adafruit library for BMP280 sensor
 
// define device I2C address: 0x76 or 0x77 (0x77 is library default address)
#define BMP280_I2C_ADDRESS  0x76
 
Adafruit_BMP280 bmp280;

const int ledPin = 26;
const int ledPin2 = 27;
 
#include <LiquidCrystal_I2C.h>

// set the LCD number of columns and rows
int lcdColumns = 16;
int lcdRows = 2;

// set LCD address, number of columns and rows
// if you don't know your display address, run an I2C scanner sketch
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);  


void scrollText(String message, String message2, int delayTime, int lcdColumns) {
  for (int i=0; i < lcdColumns; i++) {
    message = " " + message;
    message2 = " " + message2;
  }
  message = message + " ";
  message2 = message2 + " ";
  for (int pos = 0; pos < message.length(); pos++) {
    lcd.setCursor(0, 0);
    lcd.print(message.substring(pos, pos + lcdColumns));
    lcd.setCursor(0,1);
    lcd.print(message2.substring(pos, pos + lcdColumns));
    delay(delayTime);
  }
}

void setup() {

  Serial.begin(115200);
 
  Serial.println(F("Arduino + BMP280"));
 
  if (!bmp280.begin(BMP280_I2C_ADDRESS))
  {  
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    while (1);
  }
  Serial.println("Found BMP280 sensor!");

  lcd.init();
  // turn on LCD backlight                      
  lcd.backlight();

 
}

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)

 
String messageToScroll, messageToScroll2;
lcd.setCursor(0, 0);
lcd.clear();
 
messageToScroll = "Temperature: " + String(temperature) + " C";
messageToScroll2 = "Press " + String(pressure) + " hPa";
scrollText(messageToScroll, messageToScroll2, 150, lcdColumns);
delay(1000);

lcd.clear();
lcd.setCursor(0,0);
lcd.print("Altitude: ");
lcd.print(altitude);
lcd.print(" m");
lcd.setCursor(0,1);
lcd.print("Thank You !");
delay(1000);
 
}
       


The explanation of the above code is as follows

void scrollText(String message, String message2, int delayTime, int lcdColumns) {
  for (int i=0; i < lcdColumns; i++) {
    message = " " + message;
    message2 = " " + message2;
  }
  message = message + " ";
  message2 = message2 + " ";
  for (int pos = 0; pos < message.length(); pos++) {
    lcd.setCursor(0, 0);
    lcd.print(message.substring(pos, pos + lcdColumns));
    lcd.setCursor(0,1);
    lcd.print(message2.substring(pos, pos + lcdColumns));
    delay(delayTime);
  }
}
}
The code above is a function to make scrolling text horizontally. Please note that message 1 will be displayed on the top row of the I2C LCD monitor, while message 2 will be displayed on the bottom row of the I2C LCD monitor.

void setup() {

  Serial.begin(115200);

  Serial.println(F("Arduino + BMP280"));
 
  if (!bmp280.begin(BMP280_I2C_ADDRESS))
  {  
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    while (1);
  }
  Serial.println("Found BMP280 sensor!");

  lcd.init();
  // turn on LCD backlight                      
  lcd.backlight();

}

The code above is a function to prepare the IDE so that it can accept input from external ESP32 devices such as I2C LCDs and BMP280 sensors.

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)

 
String messageToScroll, messageToScroll2;
lcd.setCursor(0, 0);
lcd.clear();
 
messageToScroll = "Temperature: " + String(temperature) + " C";
messageToScroll2 = "Press " + String(pressure) + " hPa";
scrollText(messageToScroll, messageToScroll2, 150, lcdColumns);
delay(1000);

lcd.clear();
lcd.setCursor(0,0);
lcd.print("Altitude: ");
lcd.print(altitude);
lcd.print(" m");
lcd.setCursor(0,1);
lcd.print("Thank You !");
delay(1000);
 
}

The code above is a function for looping the esp32 output process. The intended output is in the form of text that sends measurement data on the temperature, pressure, and altitude variables measured by the sensor. Then there is the scrollText() function which functions to call the scroll text function that was created earlier

4.Make sure you already have the library for LCD I2C and also the BMP280 sensor. If you don't have it yet, you can see how to download it in Project 4 and Project 5 on my blog.

5. Click the Upload button and wait a few seconds for the words "Done Uploaded" to display. 


6.Look at your LCD screen and heat our BMP sensor and see if the measurement of the BMP temperature on our LCD monitor changes. The result will be more or less like the video in link below :
Displaying BMP280 Sensor Measurement Using LCD I2C


๐ŸŽ‰๐ŸฅณHooray, we've finished the project

๐Ÿ˜„That's all from me ๐Ÿ‘Œ

๐Ÿ‘‹ See you in my next blog with ESP32. 

๐Ÿ‘‹ Bye Bye !




Comments

Popular posts from this blog

Project 7 : Connecting ESP32 and our smartphone with bluetooth connection