BMP280 Sensor Module Documentation
The BMP280 Sensor Module is a high-precision, low-power digital barometric pressure sensor designed for various IoT applications. It provides accurate temperature and atmospheric pressure measurements, making it suitable for environmental monitoring, weather stations, and drones.
Temperature range: -40C to 85C
Pressure range: 300 to 1100 hPa
Resolution: 0.01 hPa (pressure), 0.01C (temperature)
Supply voltage: 1.8V to 5.5V
Communication protocol: I2C or SPI
Dimensions: 12 x 12 mm
To use the BMP280 Sensor Module, connect it to your microcontroller or development board as follows:
VCC to 3.3V or 5V power supply
GND to ground
SCL (clock) to I2C clock pin (or SPI clock pin)
SDA (data) to I2C data pin (or SPI data pin)
### Example 1: Reading Temperature and Pressure using Arduino and I2C
```c++
#include <Wire.h>
#include <BMP280.h>
void setup() {
Serial.begin(9600);
Wire.begin();
bmp.begin();
}
void loop() {
if (bmp.measure()) {
float temperature = bmp.getTemperature();
float pressure = bmp.getPressure();
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" C");
Serial.print("Pressure: ");
Serial.print(pressure);
Serial.println(" hPa");
delay(1000);
}
}
```
In this example, we use the BMP280 Arduino library to communicate with the sensor module via I2C. We read the temperature and pressure values using `getTemperature()` and `getPressure()` functions and print them to the serial monitor.
### Example 2: Reading Temperature using Raspberry Pi and Python
```python
import smbus
import time
bus = smbus.SMBus(1) # Use I2C bus 1
bmp_address = 0x76 # BMP280 address
def read_temperature():
bus.write_byte(bmp_address, 0xF4) # Select temperature measurement
time.sleep(0.05) # Wait for measurement to complete
temp_msbl = bus.read_byte(bmp_address, 0x01)
temp_lsbl = bus.read_byte(bmp_address, 0x02)
temperature = (temp_msbl << 8 | temp_lsbl) / 16.0
return temperature
while True:
temperature = read_temperature()
print("Temperature: {:.2f} C".format(temperature))
time.sleep(1)
```
In this example, we use the `smbus` library to communicate with the BMP280 sensor module via I2C on a Raspberry Pi. We read the temperature value using a custom `read_temperature()` function, which sends a command to the sensor to start a temperature measurement, waits for the measurement to complete, and then reads the result.
### Example 3: Reading Pressure using ESP32 and MicroPython
```python
import machine
import utime
i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21)) # Use I2C pins 22 and 21
bmp280 = machine.I2C_BMP280(i2c)
while True:
pressure = bmp280.pressure
print("Pressure: {:.2f} hPa".format(pressure))
utime.sleep(1)
```
In this example, we use the `machine` module in MicroPython to communicate with the BMP280 sensor module via I2C on an ESP32 board. We create an `I2C_BMP280` object, which provides a simple interface to read the pressure value using the `pressure` property.
Note: Make sure to install the required libraries and modules for each example, and adjust the I2C pins and addresses according to your specific setup.