• Arduino
  • Raspberry Pi
  • Raspberry Pi Pico
  • Micro:Bit

KY-052

This pressure sensor measures the air pressure at the sensor output and outputs the result coded on the I2C bus.

A corresponding library is required for this module - see code examples below.

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.

Code example Arduino

Pin assignment Arduino

Arduino Sensor
5 V SDO
5 V COD
Pin A4 SDA
Pin A5 SCL
5 V + V
GND GND

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.

There are several ways to control this sensor module - the Adafruit_BMP280 library has proven to be particularly accessible, which is provided by Adafruit published under the OpenSource BSD license.

The example below is based on this library. For this we recommend to download it, unzip it and copy it in the Arduino library folder, which is located by default in (C:\User[username]\Documents\Arduino\libraries), so that it is available for the code example and following projects. Alternatively, the library is also included in the download package below.

/ ************************************************* **************************
  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 and open-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 BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 10
 
Adafruit_BMP280 bmp; // I2C
// Adafruit_BMP280 bmp (BMP_CS); // hardware SPI
// Adafruit_BMP280 bmp (BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
 
void setup () {
  Serial.begin (9600);
  Serial.println (F ("BMP280 test"));
   
  if (! bmp.begin ()) {
    Serial.println (F ("Could not find a valid BMP280 sensor, check wiring!"));
    while (1);
  }
}
 
void loop () {
    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 ("Approx altitude ="));
    Serial.print (bmp.readAltitude (1013.25)); // this should be adjusted to your local forcase
    Serial.println ("m");
     
    Serial.println ();
    delay (2000);
}

Sample program download

KY052-Arduino.zip

KY-052

This pressure sensor measures the air pressure at the sensor output and outputs the result coded on the I2C bus.

A corresponding library is required for this module - see code examples below.

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.

Code example Raspberry Pi

Pin assignment Raspberry Pi

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

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

Additionally the installation of the I2C libraries is necessary. Install them via the following command:

sudo apt-get install python3-smbus i2c-tools -y

Now install the library using the following command:

sudo pip3 install adafruit-circuitpython-bmp280

To enable communication between the sensor and the Raspberry Pi, the I2C interface of the Raspberry Pi must also be activated. To do this, open the config.txt file via the following command:

sudo nano /boot/config.txt

Add the following line to the end of the file:

dtparam=i2c_arm=on

Save the file with the key combination [CTRL+O], confirm with [Enter] and exit the editor with the key combination [CTRL+X].

After this, the following Python code example can be used. The program starts the measurement at the sensor and outputs the measured values for the air pressure, the temperature and the height above sea level.

# Required modules are imported and set up
import time
import board
# import digitalio # for use with SPI
import adafruit_bmp280

# Create a sensor object that communicates via the RPi's standard I2C bus
i2c = board.I2C () # uses board.SCL and board.SDA
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C (i2c)

# OR create a sensor object that communicates via the RPi's standard SPI bus
# spi = board.SPI ()
# bmp_cs = digitalio.DigitalInOut (board.D10)
# bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI (spi, bmp_cs)

# 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)

Sample program download

KY052-RPi.zip

To start with the command

sudo python3 KY052-RPi.py

KY-052

This pressure sensor measures the air pressure at the sensor output and outputs the result coded on the I2C bus.

A corresponding library is required for this module - see code examples below.

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.

Code example Micro: Bit

Pin assignment Micro: Bit:

Micro: bit Sensor
Pin 20 SDA
Pin 19 SCL
3 V COD
3 V SDO
3 V + V
GND GND

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].

Sample program download

microbit-KY-052.zip

KY-052

This pressure sensor measures the air pressure at the sensor output and outputs the result coded on the I2C bus.

A corresponding library is required for this module - see code examples below.

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.

Code example Raspberry Pi Pico

Pin assignment Raspberry Pi Pico

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.

For the following code example an additional library is needed:

pico-bmp280 by flrrth | published under the GPL License

# 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)  # address may be different

# Endless loop for reading out the sensor with serial output
while True:
    readout = bmp280_i2c.measurements
    print(f"Temperature: {readout['t']} °C, pressure: {readout['p']} hPa.")
    sleep(1)

Example program download

KY052-Pico.zip