ESP32 KY-052 Pressure and Temperature Sensor Module
The KY-052 module features the BMP280 sensor, offering accurate measurements of barometric pressure and temperature. It utilizes the I2C interface for communication, making it ideal for environmental monitoring projects.
🔗 Quick Links
ℹ️ About KY-052 Pressure and Temperature Sensor Module
The KY-052 module integrates the BMP280 sensor, capable of measuring both barometric pressure and temperature. It communicates via the I2C bus, providing precise environmental data suitable for applications like weather stations, altimeters, and mobile devices.⚙️ KY-052 Sensor Technical Specifications
Below you can see the KY-052 Pressure and Temperature Sensor Module Technical Specifications. The sensor is compatible with the ESP32, operating within a voltage range suitable for microcontrollers. For precise details about its features, specifications, and usage, refer to the sensor’s datasheet.
- Type: module
- Protocol: I2C
- Pressure Measuring Range: 300 to 1100 hPa (equivalent to +9000 to -500 m above/below sea level)
- Relative Accuracy: ±0.12 hPa (±1 m) within 950 to 1050 hPa at 25°C
- Absolute Accuracy: ±1 hPa within 950 to 1050 hPa, 0 to +40°C
- Temperature Coefficient Offset: 1.5 Pa/K (12.6 cm/K) from 25 to 40°C at 900 hPa
- 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
- Temperature Measuring Range: -40 to +85°C
- Dimensions: 22 x 34 x 6 mm
🔌 KY-052 Sensor Pinout
Below you can see the pinout for the KY-052 Pressure and Temperature Sensor Module. The VCC
pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND
pin is the ground connection and must be connected to the ground of your ESP32!
VCC:
Power supply pin, can be connected to 3.3V or 5V.GND:
Ground pin.SDA:
I2C data line.SCL:
I2C clock line.SDO:
Not connected in I2C mode; used for SPI communication.CSB:
Chip select for SPI; connect to VCC for I2C mode.
🛠️ KY-052 Pressure and Temperature Sensor Module Troubleshooting
This guide outlines a systematic approach to troubleshoot and resolve common problems with the . Start by confirming that the hardware connections are correct, as wiring mistakes are the most frequent cause of issues. If you are sure the connections are correct, follow the below steps to debug common issues.
❌ Sensor Not Responding
Issue: The sensor does not provide any data.
Solutions:
- Ensure proper wiring connections, especially the I2C lines (SDA and SCL).
- Verify that the CSB pin is connected to VCC to enable I2C mode.
- Check that the correct I2C address is used in the code (default is 0x76 or 0x77).
🌡️ Incorrect Temperature or Pressure Readings
Issue: The sensor outputs inaccurate environmental data.
Solutions:
- Ensure the sensor is not exposed to rapid temperature changes or drafts.
- Calibrate the sensor if necessary, especially for altitude measurements.
- Verify that the sensor is operating within its specified temperature range (-40°C to +85°C).
💻 Code Examples
Below you can find code examples of KY-052 Pressure and Temperature Sensor Module with ESP32 in several frameworks:
If you encounter issues while using the KY-052 Pressure and Temperature Sensor Module, check the Common Issues Troubleshooting Guide.

ESP32 KY-052 Arduino IDE Code Example
Fill in your main
Arduino IDE sketch file with the following code to use the KY-052 Pressure and Temperature Sensor Module:
#include <Wire.h>
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp;
void setup() {
Serial.begin(9600);
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("Altitude = "));
Serial.print(bmp.readAltitude(1013.25)); // Adjust to local sea level pressure
Serial.println(" m");
delay(2000);
}
This Arduino code initializes the BMP280 sensor and reads temperature, pressure, and altitude data. The altitude calculation requires adjusting the sea level pressure value (1013.25 hPa) to your local value for accurate readings. The sensor data is printed to the serial monitor every 2 seconds.
Connect your ESP32 to your computer via a USB cable, Ensure the correct Board and Port are selected under Tools, Click the "Upload" button in the Arduino IDE to compile and upload the code to your ESP32.

ESP32 KY-052 ESP-IDF Code ExampleExample in Espressif IoT Framework (ESP-IDF)
If you're using ESP-IDF to work with the KY-052 Pressure and Temperature Sensor Module, here's how you can set it up and read data from the sensor. Fill in this code in the main
ESP-IDF file:
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/i2c.h"
#include "bmp280.h"
#define I2C_MASTER_SCL_IO 22
#define I2C_MASTER_SDA_IO 21
#define I2C_MASTER_NUM I2C_NUM_0
#define I2C_MASTER_FREQ_HZ 100000
void app_main() {
printf("Initializing BMP280 sensor...\n");
bmp280_t bmp;
bmp280_params_t params;
bmp280_init_default_params(¶ms);
i2cdev_init();
if (bmp280_init_desc(&bmp, BMP280_I2C_ADDRESS_0, I2C_MASTER_NUM, I2C_MASTER_SDA_IO, I2C_MASTER_SCL_IO) != ESP_OK ||
bmp280_init(&bmp, ¶ms) != ESP_OK) {
printf("BMP280 sensor initialization failed!\n");
return;
}
while (1) {
float temperature, pressure, altitude;
if (bmp280_read_float(&bmp, &temperature, &pressure, &altitude) == ESP_OK) {
printf("Temperature: %.2f°C, Pressure: %.2f hPa, Altitude: %.2f m\n", temperature, pressure / 100.0, altitude);
} else {
printf("Failed to read data from BMP280\n");
}
vTaskDelay(pdMS_TO_TICKS(2000));
}
}
This ESP-IDF code initializes the BMP280 sensor using the I2C interface on GPIO21 (SDA) and GPIO22 (SCL). It reads temperature, pressure, and altitude values and prints them to the console every 2 seconds.
Update the I2C pins (I2C_MASTER_SDA_IO
and I2C_MASTER_SCL_IO
) to match your ESP32 hardware setup, Use idf.py build to compile the project, Use idf.py flash to upload the code to your ESP32.

ESP32 KY-052 ESPHome Code Example
Fill in this configuration in your ESPHome YAML configuration file (example.yml
) to integrate the KY-052 Pressure and Temperature Sensor Module
sensor:
- platform: bmp280
temperature:
name: "KY-052 Temperature"
pressure:
name: "KY-052 Pressure"
address: 0x76
update_interval: 2s
This ESPHome configuration sets up the KY-052 sensor (BMP280) to read temperature and pressure data via I2C with an update interval of 2 seconds.
Upload this code to your ESP32 using the ESPHome dashboard or the esphome run
command.

ESP32 KY-052 PlatformIO Code Example
For PlatformIO, make sure to configure the platformio.ini
file with the appropriate environment and libraries, and then proceed with the code.
Configure platformio.ini
First, your platformio.ini
should look like below. You might need to include some libraries as shown. Make sure to change the board to your ESP32:
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
adafruit/Adafruit BMP280 Library
adafruit/Adafruit Unified Sensor
ESP32 KY-052 PlatformIO Example Code
Write this code in your PlatformIO project under the src/main.cpp
file to use the KY-052 Pressure and Temperature Sensor Module:
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp;
void setup() {
Serial.begin(115200);
if (!bmp.begin(0x76)) {
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
while (1);
}
}
void loop() {
Serial.print("Temperature = ");
Serial.print(bmp.readTemperature());
Serial.println(" °C");
Serial.print("Pressure = ");
Serial.print(bmp.readPressure() / 100.0);
Serial.println(" hPa");
Serial.print("Altitude = ");
Serial.print(bmp.readAltitude(1013.25)); // Adjust sea level pressure
Serial.println(" m");
delay(2000);
}
This PlatformIO code configures the KY-052 sensor (BMP280) for temperature, pressure, and altitude measurement using I2C communication. It reads data every 2 seconds and prints it to the serial monitor.
Upload the code to your ESP32 using the PlatformIO "Upload" button in your IDE or the pio run --target upload
command.

ESP32 KY-052 MicroPython Code Example
Fill in this script in your MicroPython main.py file (main.py
) to integrate the KY-052 Pressure and Temperature Sensor Module with your ESP32.
from machine import Pin, I2C
import time
import bmp280
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
sensor = bmp280.BMP280(i2c)
while True:
temperature = sensor.temperature
pressure = sensor.pressure
altitude = sensor.altitude
print("Temperature:", temperature, "°C", "Pressure:", pressure, "hPa", "Altitude:", altitude, "m")
time.sleep(2)
This MicroPython script configures the KY-052 sensor (BMP280) using I2C on GPIO21 (SDA) and GPIO22 (SCL). It continuously reads temperature, pressure, and altitude and prints the values every 2 seconds.
Upload this code to your ESP32 using a MicroPython-compatible IDE, such as Thonny, uPyCraft, or tools like ampy
.
Conclusion
We went through technical specifications of KY-052 Pressure and Temperature Sensor Module, its pinout, connection with ESP32 and KY-052 Pressure and Temperature Sensor Module code examples with Arduino IDE, ESP-IDF, ESPHome and PlatformIO.