KY-052 Pressure sensor / Temperature sensor (BMP280)
This pressure sensor measures the air pressure at the sensor output (small hole on the silver sensor housing) and outputs the result coded on the I2C bus.
- Arduino
- Raspberry Pi
- Raspberry Pi Pico
- Micro:Bit
The BMP280 is a versatile sensor that measures both barometric pressure and temperature and outputs the results via the I2C bus. With this sensor you can capture precise air pressure and temperature values, making it ideal for applications such as weather stations, altimeters and mobile devices.
It covers a wide pressure range corresponding to altitudes from +9000 to -500 meters above or below sea level. The measured data is very accurate, which means you get reliable information about the ambient conditions. The sensor can operate in a wide temperature range, from -40 to +85°C, making it suitable for many environments.
Thanks to the digital interfaces (I²C and SPI), the BMP280 can be easily integrated into various microcontroller and computer systems. This facilitates the development of projects that require accurate environmental measurements. The sensor's low power consumption also makes it ideal for use in battery-powered devices.
Overall, the BMP280 provides a simple and effective solution for accurately monitoring air pressure and temperature, making it a valuable component for a variety of applications.
Technical specifications | |
---|---|
Measuring range (pressure) | 300 to 1100 hPa (equivalent to +9000 to -500 m above / below sea level) |
Relative accuracy | ± 0.12 hPa, equiv. To ± 1 m (950 to 1050 hPa at 25 ° C) |
Absolute accuracy | ± 1 hPa (950 to 1050 hPa, 0 to +40 ° C) |
Temperature coefficient offset | 1.5 Pa / K, corresponds to 12.6 cm / K (25 to 40 ° C at 900hPa) |
Digital interfaces | I²C (up to 3.4 MHz), SPI (3- and 4-wire, up to 10 MHz) |
Power consumption | 2.7µA at 1 Hz sampling rate |
Measuring range (temperature) | -40 to +85 ° C |
Pin assignment
This sensor allows to be connected and operated on 5 V systems as well as on 3.3 V systems.
Arduino | Sensor |
---|---|
5 V | SDO |
5 V | COD |
Pin A4 | SDA |
Pin A5 | SCL |
5 V | + V |
GND | GND |
Code example
This sensor does not output its measurement result as a signal on its output pin, but communicates it via I2C bus. The sensor can be controlled via this bus and the respective measurements of pressure and temperature can be started and evaluated.
To load the following code example onto your Arduino, we recommend using the Arduino IDE. In the IDE, you can select the appropriate port and the correct board for your device.
The following libraries are also used for the code example:
Adafruit_BMP280 from Adafruit | published under BSD-License
You can easily add these libraries via the library manager of the Arduino IDE. Then copy the code below into your IDE. To upload the code to the Arduino, simply click on the upload button.
/***************************************************************************
This is a library for the BMP280 humidity, temperature & pressure sensor
Designed specifically to work with the Adafruit BMEP280 Breakout
----> http://www.adafruit.com/products/2651
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
to interface.
Adafruit invests time and resources providing this open source code,
please support Adafruit andopen-source hardware by purchasing products
from Adafruit!
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
BSD license, all text above must be included in any redistribution
***************************************************************************/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>
// Define pins of the BMP280
#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 10
// Initialize BMP280
Adafruit_BMP280 bmp;
void setup() {
// Initialize serial monitor
Serial.begin(9600);
Serial.println(F("KY-052 BMP280 test"));
// Establish connection with BMP280
if (!bmp.begin()) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
while (1);
}
}
void loop() {
// Output measured values from the BMP280
Serial.print(F("Temperature = "));
Serial.print(bmp.readTemperature());
Serial.println(" °C");
Serial.print(F("Pressure = "));
Serial.print(bmp.readPressure());
Serial.println(" Pa");
Serial.print(F("Altitude = "));
// This value must be changed to the current air pressure at your location
// otherwise there will be inaccuracies
// Weather services can give you information
// 1013.25 hPa is the mean air pressure at sea level
Serial.print(bmp.readAltitude(1013.25));
Serial.println(" m");
Serial.println();
delay(2000);
}
The BMP280 is a versatile sensor that measures both barometric pressure and temperature and outputs the results via the I2C bus. With this sensor you can capture precise air pressure and temperature values, making it ideal for applications such as weather stations, altimeters and mobile devices.
It covers a wide pressure range corresponding to altitudes from +9000 to -500 meters above or below sea level. The measured data is very accurate, which means you get reliable information about the ambient conditions. The sensor can operate in a wide temperature range, from -40 to +85°C, making it suitable for many environments.
Thanks to the digital interfaces (I²C and SPI), the BMP280 can be easily integrated into various microcontroller and computer systems. This facilitates the development of projects that require accurate environmental measurements. The sensor's low power consumption also makes it ideal for use in battery-powered devices.
Overall, the BMP280 provides a simple and effective solution for accurately monitoring air pressure and temperature, making it a valuable component for a variety of applications.
Technical specifications | |
---|---|
Measuring range (pressure) | 300 to 1100 hPa (equivalent to +9000 to -500 m above / below sea level) |
Relative accuracy | ± 0.12 hPa, equiv. To ± 1 m (950 to 1050 hPa at 25 ° C) |
Absolute accuracy | ± 1 hPa (950 to 1050 hPa, 0 to +40 ° C) |
Temperature coefficient offset | 1.5 Pa / K, corresponds to 12.6 cm / K (25 to 40 ° C at 900hPa) |
Digital interfaces | I²C (up to 3.4 MHz), SPI (3- and 4-wire, up to 10 MHz) |
Power consumption | 2.7µA at 1 Hz sampling rate |
Measuring range (temperature) | -40 to +85 ° C |
Pin assignment
This sensor allows to be connected and operated on 5 V systems as well as on 3.3 V systems.
Raspberry Pi | Sensor |
---|---|
3.3 V | SDO |
3.3 V | COD |
GPIO 2 / SDA [Pin 3] | SDA |
GPIO 3 / SCL [Pin 5] | SCL |
3.3 V | + V |
GND | GND |
Code example
The program uses the corresponding BMP280 Python Librarie to control the BMP280, which is installed on this sensor module of the Adafruit company. This was published under the WITH OpenSource license .
This must be installed before use:
First install the pip3 software, which allows you to install the appropriate library:
sudo apt-get install python3-pip
The next step is to set up the virtual environment. To do this, enter the following commands:
mkdir your_project
cd your_project
python -m venv --system-site-packages env
source env/bin/activate
Use the following commands to download and install the library.
pip3 install adafruit-circuitpython-bmp280
The following Python code example can now be used. The program starts the measurement at the sensor and outputs the measured values for air pressure, temperature and altitude above sea level.
# Required modules are imported and set up
import time
import board
import adafruit_bmp280
# Create sensor object that communicates via the standard I2C bus of the RPi
i2c = board.I2C() # uses board.SCL and board.SDA
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
# Change this value so that it corresponds to the air pressure (hPa) at sea level at your location.
bmp280.sea_level_pressure = 1013.25
while True:
print("\nTemperature: %0.1f C" % bmp280.temperature)
print("Pressure: %0.1f hPa" % bmp280.pressure)
print("Altitude = %0.2f meters" % bmp280.altitude)
time.sleep(2)
The BMP280 is a versatile sensor that measures both barometric pressure and temperature and outputs the results via the I2C bus. With this sensor you can capture precise air pressure and temperature values, making it ideal for applications such as weather stations, altimeters and mobile devices.
It covers a wide pressure range corresponding to altitudes from +9000 to -500 meters above or below sea level. The measured data is very accurate, which means you get reliable information about the ambient conditions. The sensor can operate in a wide temperature range, from -40 to +85°C, making it suitable for many environments.
Thanks to the digital interfaces (I²C and SPI), the BMP280 can be easily integrated into various microcontroller and computer systems. This facilitates the development of projects that require accurate environmental measurements. The sensor's low power consumption also makes it ideal for use in battery-powered devices.
Overall, the BMP280 provides a simple and effective solution for accurately monitoring air pressure and temperature, making it a valuable component for a variety of applications.
Technical specifications | |
---|---|
Measuring range (pressure) | 300 to 1100 hPa (equivalent to +9000 to -500 m above / below sea level) |
Relative accuracy | ± 0.12 hPa, equiv. To ± 1 m (950 to 1050 hPa at 25 ° C) |
Absolute accuracy | ± 1 hPa (950 to 1050 hPa, 0 to +40 ° C) |
Temperature coefficient offset | 1.5 Pa / K, corresponds to 12.6 cm / K (25 to 40 ° C at 900hPa) |
Digital interfaces | I²C (up to 3.4 MHz), SPI (3- and 4-wire, up to 10 MHz) |
Power consumption | 2.7µA at 1 Hz sampling rate |
Measuring range (temperature) | -40 to +85 ° C |
Pin assignment
This sensor allows to be connected and operated on 5 V systems as well as on 3.3 V systems.
Micro: bit | Sensor |
---|---|
Pin 20 | SDA |
Pin 19 | SCL |
3 V | COD |
3 V | SDO |
3 V | + V |
GND | GND |
Code example
An additional library is required for the following code example:
BMP280 by makecode-extensions | published under the MIT License
Add the library to your IDE by clicking on "Extensions" and entering the following URL in the search box: ** https: //github.com/makecode-extensions/BMP280.git**. Confirm the search with [Enter].
let pressure = 0
let temperature = 0
basic.forever(function () {
pressure = BMP280.pressure()
temperature = BMP280.temperature()
serial.writeNumber(pressure)
serial.writeString("Pa, ")
serial.writeNumber(temperature)
serial.writeLine("")
basic.pause(1000)
})
Sample program download
The BMP280 is a versatile sensor that measures both barometric pressure and temperature and outputs the results via the I2C bus. With this sensor you can capture precise air pressure and temperature values, making it ideal for applications such as weather stations, altimeters and mobile devices.
It covers a wide pressure range corresponding to altitudes from +9000 to -500 meters above or below sea level. The measured data is very accurate, which means you get reliable information about the ambient conditions. The sensor can operate in a wide temperature range, from -40 to +85°C, making it suitable for many environments.
Thanks to the digital interfaces (I²C and SPI), the BMP280 can be easily integrated into various microcontroller and computer systems. This facilitates the development of projects that require accurate environmental measurements. The sensor's low power consumption also makes it ideal for use in battery-powered devices.
Overall, the BMP280 provides a simple and effective solution for accurately monitoring air pressure and temperature, making it a valuable component for a variety of applications.
Technical specifications | |
---|---|
Measuring range (pressure) | 300 to 1100 hPa (equivalent to +9000 to -500 m above / below sea level) |
Relative accuracy | ± 0.12 hPa, equiv. To ± 1 m (950 to 1050 hPa at 25 ° C) |
Absolute accuracy | ± 1 hPa (950 to 1050 hPa, 0 to +40 ° C) |
Temperature coefficient offset | 1.5 Pa / K, corresponds to 12.6 cm / K (25 to 40 ° C at 900hPa) |
Digital interfaces | I²C (up to 3.4 MHz), SPI (3- and 4-wire, up to 10 MHz) |
Power consumption | 2.7µA at 1 Hz sampling rate |
Measuring range (temperature) | -40 to +85 ° C |
Pin assignment
This sensor allows to be connected and operated on 5 V systems as well as on 3.3 V systems.
Raspberry Pi Pico | Sensor |
---|---|
3.3V | SDO |
3.3V | CSB |
GPIO0 | SDA |
GPIO1 | SCL |
3.3V | +V |
GND | GND |
This sensor does not output its measurement result as a signal on its output pin, but communicates it via I2C. The sensor can be controlled via this bus and the respective measurements of pressure and temperature can be started and evaluated.
Code example
To load the following code example onto your Pico, we recommend using the Thonny IDE. All you have to do first is go to Run > Configure interpreter ... > Interpreter > Which kind of interpreter should Thonny use for running your code? and select MicroPython (Raspberry Pi Pico).
The following library is used for the code example:
pico-bmp280 by flrrth | published under the GPL License
To use this library, you must download the bmp280 folder from the above library and load it onto the Pico in a folder called lib (you may need to create this). Afterwards you can copy the code below into your IDE and click on Run.
# Load libraries
from machine import Pin, I2C
from utime import sleep
from bmp280 import BMP280I2C
# Initialization of the I2C interface
i2c0_sda = Pin(0)
i2c0_scl = Pin(1)
i2c0 = I2C(0, sda = i2c0_sda, scl = i2c0_scl, freq = 400000)
# Initialization of the sensor object
bmp280_i2c = BMP280I2C(0x77, i2c0)
# Endless loop for reading out the sensor with serial output
while True:
readout = bmp280_i2c.measurements
print(f"Temperature: {round(readout['t'], 2)} °C \t Pressure: {round(readout['p'], 2)} hPa")
sleep(1)