The BMP180 Arduino Library provides an easy-to-use interface for the BMP180 Barometric Pressure and Temperature Sensor. With support for multiple metric systems, including Imperial and International units, this library offers temperature, pressure, and altitude data with customizable unit conversions.
Saurav Sajeev
- Features
- Hardware Requirements
- Installation
- Library Structure
- Getting Started
- Detailed API Reference
- Constants Reference
- Examples
- Troubleshooting
- Contributing
- License
- Temperature, Pressure, and Altitude Measurement
- Custom Metric System Support:
- Use Imperial or International systems
- Pressure Oversampling Configuration
- Unit Conversion Utilities:
- Convert between °C/°F/K, Pa/psi/bar/inHg/atm, meters/feet
- Sensor Connectivity Check
- Sensor: BMP180 Digital Pressure Sensor
- Microcontroller: Arduino-compatible board (UNO, Mega, Nano)
- Communication Protocol: I2C
- Connections:
- VCC → 3.3V or 5V
- GND → GND
- SDA → A4 (on UNO)
- SCL → A5 (on UNO)
- Open Arduino IDE
- Go to Sketch → Include Library → Manage Libraries
- Search for
BMP180
and click Install
- Download the library from GitHub
- Open Arduino IDE
- Go to Sketch → Include Library → Add .ZIP Library
- Select the downloaded ZIP file
BMP180.h / .cpp
: Main class for reading sensor dataMetricSystem.h
: Handles unit conversion logicBMP180DEFS.h
: Constants for unit types and values
#include <BMP180.h>
BMP180 bmp;
void setup() {
Serial.begin(9600);
if (bmp.begin()) {
Serial.println("BMP180 initialized!");
} else {
Serial.println("Sensor not found!");
}
bmp.setMetricSystem(ImperialSystem()); // You don't need to create a long lasting variable. RValues are also supported.
}
void loop() {
Serial.print("Temperature: ");
Serial.println(bmp.readTemperature());
Serial.print("Pressure: ");
Serial.println(bmp.readPressure());
Serial.print("Altitude: ");
Serial.println(bmp.readAltitude());
delay(1000);
}
BMP180()
Default constructor with I2C communication.
bool begin()
Initializes the sensor and reads calibration data.
-
float readTemperature()
Returns the temperature in °C (or converted unit). -
float readPressure()
Returns pressure in Pascals (or converted unit). -
float readAltitude()
Returns altitude in meters (or converted unit).
-
void setPressureOverSampling(uint8_t os)
Set oversampling (0 to 3) for more accurate pressure readings. -
void setMetricSystem(MetricSystem &metricSystem)
Set a custom unit system. UseInternationalSystem
orImperialSystem
.
You may also directly pass a dynamically declared object:bmp.setMetricSystem(ImperialSystem());
bool isConnected()
Returnstrue
if sensor is detected on the I2C bus.
-
String getTemperatureUnit()
Returns current temperature unit ("°C"
,"°F"
,"K"
) -
String getPressureUnit()
Returns current pressure unit ("Pa"
,"psi"
,"bar"
,"inHg"
,"atm"
) -
String getAltitudeUnit()
Returns current altitude unit ("m"
,"ft"
)
Constant | Unit |
---|---|
BMP180_UNIT_CELSIUS |
°C |
BMP180_UNIT_FAHRENHEIT |
°F |
BMP180_UNIT_KELVIN |
K |
Constant | Unit |
---|---|
BMP180_UNIT_PASCAL |
Pa |
BMP180_UNIT_PSI |
psi |
BMP180_UNIT_BAR |
bar |
BMP180_UNIT_INCH_HG |
inHg |
BMP180_UNIT_ATM |
atm |
Constant | Unit |
---|---|
BMP180_UNIT_METRE |
meter |
BMP180_UNIT_FEET |
feet |
#include <BMP180.h>
BMP180 bmp;
ImperialSystem imperial;
void setup() {
Serial.begin(9600);
bmp.setMetricSystem(imperial);
bmp.begin();
}
void loop() {
Serial.print("Temp: ");
Serial.print(bmp.readTemperature());
Serial.println(" " + imperial.temperatureUnit);
Serial.print("Pressure: ");
Serial.print(bmp.readPressure());
Serial.println(" " + imperial.pressureUnit);
Serial.print("Altitude: ");
Serial.print(bmp.readAltitude());
Serial.println(" " + imperial.altitudeUnit);
delay(1000);
}
#include <BMP180.h>
BMP180 bmp;
void setup() {
Serial.begin(9600);
bmp.begin();
bmp.setPressureOverSampling(3); // Highest oversampling
}
void loop() {
Serial.println("Pressure: " + String(bmp.readPressure()) + " Pa");
delay(1000);
}
Issue | Solution |
---|---|
No sensor detected | Check I2C wiring and address |
Constant 0 readings | Ensure begin() is called and returns true |
Wrong values for units | Ensure correct MetricSystem is used |
Compilation errors | Check if all dependencies are installed |
Want to contribute? Here's how:
- Fork the repo
git clone https://github.com/<your-repo>/BMP180.git
- Create a feature branch
git checkout -b your-feature
- Push and create a Pull Request
This library is licensed under the MIT License.
See the LICENSE file for full terms.