How to Interface BMP180 with ESP32?
This guide will show you how to connect a BMP180 to an ESP32 DevKit Development Board. BMP180 is one of the most affordable options if you want to develop a Web-based Pressure and Temperature Monitoring System with ESP32 (there are definitely better sensors than BMP180, like BME280 for example).Â
To show the pressure and temperature data on an LCD, set up the Arduino IDE, and discover how the ESP32 BMP180 Pressure and Temperature Sensor Interface functions. A straightforward ESP32 Web Server that continuously shows the pressure and temperature from a BMP180 Sensor is also a possibility.
BMP180 Sensor
BMP180 Sensor was previously covered in the Arduino BMP180 Tutorial. However, let’s review some crucial information regarding the sensor. The digital barometric pressure sensor from Bosch is called the BMP180. It is a piezoresistive MEMS-based ultra-low power device. It is capable of measuring air pressure between 300 and 1100 hPa.
The BMP180 Sensor can monitor the temperature in the range of 00C to 650C in addition to pressure. Since BMP180 detects atmospheric pressure, it is simple to determine the point’s height (as they both are related).
The real BMP180 Sensor is a tiny device with measurements of 3.6mm x 3.8mm. It can be purchased in a 7-pin LGA package and interfaces with microcontrollers via either I2C or SPI (only one is possible in the final sensor).
The calibration of sensors is a significant consideration. To give findings that are acceptable, a sensor needs to be calibrated correctly. The Bosch BMP180 Barometric Pressure Sensors are fortunately all factory calibrated and ready to use.
Numerous independent module and sensor producers used the tiny BMP180 Sensor to create a compact Module that is ideal for Arduino and other DIY Projects. Today’s modules mostly make advantage of I2C communication. [Projects for Novice ESP32 Users]
Pin Diagram of BMP180
The Pins of the BMP180 Sensor are depicted in the next image. The pins on the back of the module are labelled.
As you can see, there are four pins on the BMP180 Module:
- VIN
- GND
- SCL
- SDA
ESP32 BMP180 Interface
After learning a little bit more about the BMP180 Pressure and Temperature Sensor, let’s move on to learning how to connect the BMP180 to the ESP32. You must first keep in mind that BMP180 is a digital sensor.
Next, keep in mind that the BMP180 Sensor communicates with a microcontroller using the I2C interface. If you recall the ESP32 pinout, GPIO 21 (SDA) and GPIO 22 are the device’s default IÂ2C pins (SCL). The ESP32 DevKit Development Board refers to them as D21 and D22, respectively.
So, in order to communicate with the BMP180 Sensor, we must use these pins.
Components Required
- ESP32 DevKit Development Board
- BMP180 Pressure and Temperature Sensor (Module)
- 16×2 LCD
- PCF8574 I2C LCD Module
- Breadboard
- Connecting Wires
- Micro USB Cable
Circuit Diagram
The connections between the ESP32 and the BMP180 are depicted in the next image. The BMP180 Module includes a 3.3V regulator on board. So, you can use 5V to power the board. Connect the ESP32 board’s VIN to the BMP180’s VIN. Additionally, join any ESP32 GND pin with the GND pin of the BMP180.
Now, moving on to the I2C pins, attach SDA to the ESP32’s GPIO 21 (labelled D21 on the board), and SCL to GPIO 22. (which is marked as D22). After that, all connections are complete.
Preparing Arduino IDE
To ensure that ESP32 and the BMP180 Sensor can interact effectively, you must download one library related to the sensor. In the Arduino IDE, select Tools -> Manage Libraries…
Enter “bmp180” in the search box and install “Adafruit BMP085 Library” from Adafruit.
Displaying Pressure and Temperature on Serial Monitor
We will now examine how to read the Pressure and Temperature data from the BMP180 Sensor using the ESP32 and display the result on the Serial Monitor after creating the right connections and installing the required libraries as indicated before.
Code
I2C bus is used by the BMP180 Sensor to communicate with the microcontroller. I created some straightforward code that would setup the BMP180 Sensor and read its data for Pressure and Temperature.
I just printed the temperature and pressure numbers in degrees Celsius and hPa on the serial monitor to see the outcome.
| Â | #include <Adafruit_BMP085.h> |
| Â | Â |
| Â | Adafruit_BMP085 bmp;; |
| Â | void setup() |
| Â | { |
| Â | Serial.begin(115200); |
| Â | if (!bmp.begin()) |
| Â | { |
| Â | Â Serial.println(“BMP180 Sensor not found ! ! !”); |
| Â | Â while (1) |
| Â | Â { |
| Â | Â Â |
| Â | Â } |
| Â | } |
| Â | } |
| Â | Â |
| Â | void loop() |
| Â | { |
| Â | Serial.print(“Pressure = “); |
| Â | Serial.print(bmp.readPressure()); |
| Â | Serial.print(” hPa”); |
|  | Serial.print(” Temp = “); |
| Â | Serial.print(bmp.readTemperature()); |
|  | Serial.println(“ºC”); |
| Â | delay(3000); |
| Â | } |
The Serial Monitor, which continuously prints the pressure and temperature readings every three seconds, is screenshotted in the following image.
ESP32 BMP180 with I2C LCD
The BMP180 Sensor’s pressure and temperature data can be shown on a serial monitor for checking the connections and the code itself. You must need a display module of some kind (OLED, 162 Character LCD, Nokia 5110 LCD, graphical LCD, etc.) to view the pressure and temperature measurements in order to create a useful “Embedded System” application.
To display the pressure and temperature information from the ESP32 BMP180 Sensor Interface, I combined a normal 162 Character LCD Display Module with a PCF8574 I2C LCD Module.
I created a specific guide on using an I2C LCD with the ESP32. For further details, see that tutorial. In that lesson, I also covered the required libraries that you must download in order to effectively connect an I2C LCD to an ESP32.
NOTE: In that tutorial, I also covered how to find the I2C LCD module’s slave address. This action is crucial.
Circuit Diagram
Two further parts are needed: a 16*2 LCD display and an I2C LCD module (based on PCF8574). Connect the I2C LCD Module to the 16*2 LCD Display’s back. Only four connections are necessary for the I2C LCD Module (two of them are for power and two are for data).
The accompanying circuit diagram shows every connection that must be made between the ESP32 and the I2C LCD Module and between the ESP32 and the BMP180 Pressure and Temperature Sensor.
Code
The ESP32 BMP180 Sensor Interface with I2C LCD code is fairly straightforward. The sensor’s initialization phase resembles the earlier code. The only additional code is for the LCD.
| Â | #include <Adafruit_BMP085.h> |
| Â | #include <Wire.h> |
| Â | #include <LiquidCrystal_I2C.h> |
| Â | /Adafruit_BMP085 bmp; |
| Â | LiquidCrystal_I2C lcd(0x3F, 16, 2); |
| Â | Â |
| Â | byte degree_symbol[8] = |
| Â | Â Â Â Â Â Â { |
| Â | Â Â Â Â Â Â Â 0b00111, |
| Â | Â Â Â Â Â Â Â 0b00101, |
| Â | Â Â Â Â Â Â Â 0b00111, |
| Â | Â Â Â Â Â Â Â 0b00000, |
| Â | Â Â Â Â Â Â Â 0b00000, |
| Â | Â Â Â Â Â Â Â 0b00000, |
| Â | Â Â Â Â Â Â Â 0b00000, |
| Â | Â Â Â Â Â Â Â 0b00000 |
| Â | Â Â Â Â Â Â }; |
| Â | void setup() |
| Â | { |
| Â | lcd.init(); |
| Â | lcd.backlight(); |
| Â | lcd.setCursor(0,0); |
|  | lcd.print(” BMP180 with “); |
| Â | lcd.setCursor(0,1); |
|  | lcd.print(” ESP32 DevKit “); |
| Â | lcd.createChar(0, degree_symbol); |
| Â | if (!bmp.begin()) |
| Â | { |
| Â | Â lcd.clear(); |
| Â | Â lcd.setCursor(0,0); |
|  |  lcd.print(” BMP180 Sensor “); |
| Â | Â lcd.setCursor(0,1); |
| Â | Â lcd.print(” not found ! ! !”); |
| Â | Â while (1) |
| Â | Â { |
| Â | Â Â |
| Â | Â } |
| Â | } |
| Â | delay(2000); |
| Â | lcd.clear(); |
| Â | } |
| Â | Â |
| Â | void loop() |
| Â | { |
| Â | lcd.setCursor(0,0); |
| Â | lcd.print(“Pressure=”); |
| Â | lcd.setCursor(9,0); |
| Â | lcd.print(bmp.readPressure()); |
| Â | lcd.setCursor(13,0); |
| Â | lcd.print(“hPa”); |
| Â | Â |
| Â | lcd.setCursor(0,1); |
|  | lcd.print(” Temp = “); |
| Â | lcd.setCursor(9,1); |
| Â | lcd.print(bmp.readTemperature()); |
| Â | lcd.write(0); |
| Â | lcd.print(“C”); |
| Â | delay(1000); |
| Â | } |
Conclusion
Hope this blog helps you to understand How to Interface BMP180 with ESP32? We, MATHA ELECTRONICSÂ will come back with more informative blogs.