ESP8266 BMP180 Pressure Sensor Interface
Introduction
The BMP180 is a digital barometric pressure sensor designed for high-accuracy atmospheric pressure measurements. It is widely used in weather monitoring, altitude estimation, and IoT applications. When interfaced with the ESP8266, it allows real-time data collection and transmission over Wi-Fi. In this guide, we will explore how to connect and program the BMP180 sensor with ESP8266 using the Arduino IDE.
Components Required
- ESP8266 NodeMCU
- BMP180 Pressure Sensor
- Jumper Wires
- Breadboard (optional)
BMP180 Sensor Overview
The BMP180 operates using the I2C protocol and has the following key specifications:
- Operating Voltage: 1.8V – 3.6V (typically 3.3V for ESP8266 compatibility)
- Pressure Measurement Range: 300 – 1100 hPa
- Temperature Measurement Range: -40°C to +85°C
- Communication Protocol: I2C
BMP180 Pinout:
BMP180 Pin | Description | ESP8266 Connection |
---|---|---|
VCC | Power Supply (3.3V) | 3.3V |
GND | Ground | GND |
SDA | Serial Data | D2 (GPIO4) |
SCL | Serial Clock | D1 (GPIO5) |
Setting Up the Arduino IDE
Step 1: Install the BMP180 Library
To use the BMP180 sensor with ESP8266, install the required library:
- Open Arduino IDE.
- Go to Sketch → Include Library → Manage Libraries.
- Search for Adafruit BMP085 Library (compatible with BMP180).
- Click Install.
- Also, install the Adafruit Unified Sensor Library.
Step 2: Connect ESP8266 and BMP180
Use jumper wires to connect the ESP8266 NodeMCU and BMP180 as per the pinout table above.
Writing the Code
Upload the following code to read temperature and pressure values from the BMP180 sensor and display them in the Serial Monitor:
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085.h>
// Initialize BMP180 sensor
Adafruit_BMP085 bmp;
void setup() {
Serial.begin(115200);
if (!bmp.begin()) {
Serial.println("Could not find BMP180 sensor, check wiring!");
while (1);
}
}
void loop() {
Serial.print("Temperature: ");
Serial.print(bmp.readTemperature());
Serial.println(" °C");
Serial.print("Pressure: ");
Serial.print(bmp.readPressure());
Serial.println(" Pa");
Serial.print("Altitude: ");
Serial.print(bmp.readAltitude());
Serial.println(" m");
delay(2000);
}
Explanation of Code
- Wire.h enables I2C communication between ESP8266 and BMP180.
- Adafruit_BMP085.h allows interaction with the BMP180 sensor.
- The
setup()
function initializes the sensor. - The
loop()
function reads temperature, pressure, and altitude and prints them to the Serial Monitor. - Delay of 2 seconds ensures continuous readings without excessive refresh rate.
Viewing the Output
- Open Arduino IDE.
- Select Tools → Serial Monitor.
- Set the baud rate to 115200.
- You should see real-time temperature, pressure, and altitude readings.
Sending Data to a Web Server (Optional)
To transmit sensor data over Wi-Fi using ESP8266, you can modify the code to send data to a web page or MQTT broker.
WiFiClient client;
WiFi.begin("Your_SSID", "Your_PASSWORD");
By setting up a web server, you can display the real-time pressure and temperature on a web dashboard.
Conclusion
The BMP180 is an excellent sensor for measuring atmospheric pressure and temperature. When integrated with the ESP8266, it enables IoT-based weather monitoring and altitude measurement applications. By modifying the code, you can further send data to a cloud platform for remote monitoring.