BMP180 sensor with Arduino code | BMP180 pressure sensor tutorial [Step by step instruction]
BMP180 sensor with Arduino code
Hello guys, welcome back. In this tutorial, we will learn how to work the BMP 180 pressure sensor with Arduino code. This sensor has a very small shape through which the atmospheric pressure can be measured. Also, as this pressure decreases as it rises above sea level, it can also be used to get altitude. It can also be used to monitor weather changes. We can use this sensor mainly to making things like weather monitoring systems and drones.
BMP180 sensor structure
This is a very small sensor and includes a chip called the BMP180. This chip measures both pressure and temperature. Also, this chip can measure barometric pressures between 300 hPa and 1100 hPa and temperatures between -40C and 85C. Next, if we talk about the power required for this sensor, it operates with a potential of 3.3v. However, due to the LM6206 voltage regulator included here, even a potential of 5v can be used. That is, a potential of 3.3 to 5 can be used for this. We can also get the values of this sensor through I2C communication. Through this, we can get the values of all the three factors of temperature, pressure, and altitude.
The PIN structure of this BMP180 sensor
Okay, now we will learn step by step how to activate this sensor with Arduino. The required components are as follows.
#define ALTITUDE 390.0 //Enter your country evalution
LiquidCrystal_I2C lcd(0x27, 16, 2);
SFE_BMP180 bmp;
double T, P, S, A;
char status;
void setup() {
Serial.begin(9600);
bmp.begin();
lcd.init();
lcd.backlight();
}
void loop() {
Serial.println();
Serial.print(“provided altitude: “);
Serial.print(ALTITUDE, 0);
Serial.print(” meters, “);
Serial.print(ALTITUDE * 3.28084, 0);
Serial.println(” feet”);
status = bmp.startTemperature();
if (status != 0) {
delay(status);
status = bmp.getTemperature(T);
if (status != 0) {
Serial.print(“Temperature :”);
lcd.setCursor(0, 0);
lcd.print(“Temp :”);
lcd.print(T, 2);
lcd.print(“C”);
lcd.print(” “);
Serial.print(T, 2);
Serial.println(“*c”);
}
status = bmp.startPressure(3);// 0 to 3
if (status != 0) {
delay(status);
status = bmp.getPressure(P, T);
if (status != 0) {
Serial.print(“absolute pressure: “);
lcd.setCursor(0, 1);
lcd.print(“Pres :”);
lcd.print(P, 2);
lcd.print(“mb”);
lcd.print(” “);
Serial.print(P, 2);
Serial.println(“mb”);
}
S = bmp.sealevel(P, ALTITUDE);
Serial.print(“relative (sea-level) pressure: “);
Serial.print(S);
Serial.println(“mb”);
A = bmp.altitude(P, S);
Serial.print(“computed altitude: “);
Serial.print(A, 0);
Serial.print(” meters, “);
Serial.print(A * 3.28084, 0);
Serial.println(” feet”);
delay(3000);
}
}
}
Code explanation
Firstly, three libraries are included. They are I2C, BMP180, and wire.
#include <LiquidCrystal_I2C.h>
#include <SFE_BMP180.h>
#include <Wire.h>
Secondly, you need to include your city evaluation. Use the search browser to find this.
#define ALTITUDE 390.0 //Enter your country evalution
Next, creates objects for the I2C library and BMP180 library. Afterward, several variables were created to help the program.
LiquidCrystal_I2C lcd(0x27, 16, 2);
SFE_BMP180 bmp;
double T, P, S, A;
char status;
In the setup function, the library and serial monitor are started.
void setup() {
Serial.begin(9600);
bmp.begin();
lcd.init();
lcd.backlight();
}
In the loop function, temperature, pressure, and altitude factors are print on the serial monitor and LCD. These codes are included in the library file. Please study it.
void loop() {
The provided altitude is displayed on the serial monitor.
Serial.println();
Serial.print(“provided altitude: “);
Serial.print(ALTITUDE, 0);
Serial.print(” meters, “);
Serial.print(ALTITUDE * 3.28084, 0);
Serial.println(” feet”);
The temperature value is displayed on the serial monitor and LCD.
status = bmp.startTemperature();
if (status != 0) {
delay(status);
status = bmp.getTemperature(T);
if (status != 0) {
Serial.print(“Temperature :”);
lcd.setCursor(0, 0);
lcd.print(“Temp :”);
lcd.print(T, 2);
lcd.print(“C”);
lcd.print(” “);
Serial.print(T, 2);
Serial.println(“*c”);
}
The pressure value is displayed on the serial monitor and LCD.
status = bmp.startPressure(3);// 0 to 3
if (status != 0) {
delay(status);
status = bmp.getPressure(P, T);
if (status != 0) {
Serial.print(“absolute pressure: “);
lcd.setCursor(0, 1);
lcd.print(“Pres :”);
lcd.print(P, 2);
lcd.print(“mb”);
lcd.print(” “);
Serial.print(P, 2);
Serial.println(“mb”);
}
The relative pressure is displayed on the serial monitor.
S = bmp.sealevel(P, ALTITUDE);
Serial.print(“relative (sea-level) pressure: “);
Serial.print(S);
Serial.println(“mb”);
The computed altitude displayed on the serial monitor.
A = bmp.altitude(P, S);
Serial.print(“computed altitude: “);
Serial.print(A, 0);
Serial.print(” meters, “);
Serial.print(A * 3.28084, 0);
Serial.println(” feet”);
delay(3000);
}
}
}
Step 4
OK, finally select board and port. Afterward, upload this code to the Arduino board.
So, now you can test this sensor. For that, use the video below. We will meet in the next tutorial.
Hello guys, Welcome back to my SriTu Hobby blog. Today we are going to learn the first Nodemcu lesson. This lesson mainly focuses on how to set up Arduino…
Hello and welcome back, In this project, we are going to assemble a Raspberry PI robot tank provided by Adeept. This tank is designed to work with Raspberry Pi models…
Hello and welcome back. In this project, we will learn how to assemble a simple LEGO 4WD car step by step. It’s effortless and you can do it with several…
Hello and welcome back. In this project, we will learn how to make a simple DIY solar tracking system using Arduino. Also, it moves through the dual axis. I used…
Hello and welcome back. In this project, we will learn how to make a Motorbike using LEGO parts. That is a very interesting project. For that, I have mainly used…
Hello, welcome back. In this tutorial, we will learn what is the flame sensor and how to work with an Arduino. These types of sensors are mainly used for fire…
Can we attach more than one sensor to arduino??
Yes of course