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
๐ฃ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);
}
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.
Displaying BMP280 Sensor Measurement Using LCD I2C






Comments
Post a Comment