How to Use ESP32 with AHT20+BMP280 Temperature Humidity Pressure Module
How to Use ESP32 with AHT20+BMP280 Temperature Humidity Pressure Module
This guide walks through wiring the circuit and writing code to read temperature, humidity, and air pressure from the AHT20+BMP280 module using ESP32 board via I2C communication
Required Components
- ESP32 NodeMCU ESP-WROOM-32 board
- AHT20+BMP280 Temperature Humidity Air Pressure Module
- Micro USB Type B to USB 2.0 Type A cable 1 meter
- Power Adapter micro USB 5V 2A
- Breadboard 170 holes
- Jumper wires M-M, M-F, F-F 20cm each, 40 pieces per type
Wiring Diagram
Connect wires between ESP32 and AHT20+BMP280 module as follows
| ESP32 | AHT20+BMP280 |
|---|---|
| 3V3 | VCC |
| GND | GND |
| D21 | SDA |
| D22 | SCL |
Library Installation
- Download the Library from the link provided
- Extract the files using WinRAR or WinZip
- Place the extracted folder into the
librariesfolder of Arduino IDE
Example path: This PC > Document > Arduino > libraries
Example Code
#include <Wire.h>
#include <AHT20.h>
#include <BMP280.h>
AHT20 aht20;
BMP280 bmp280;
void setup() {
Serial.begin(115200);
Wire.begin();
// Initialize AHT20
if (aht20.begin()) {
Serial.println("AHT20 initialized");
} else {
Serial.println("AHT20 failed to initialize");
}
// Initialize BMP280
if (bmp280.begin()) {
Serial.println("BMP280 initialized");
} else {
Serial.println("BMP280 failed to initialize");
}
}
void loop() {
// Read from AHT20
float tempAHT = aht20.readTemperature();
float humiAHT = aht20.readHumidity();
// Read from BMP280
float tempBMP = bmp280.readTemperature();
float pressure = bmp280.readPressure();
Serial.print("AHT20 - Temp: ");
Serial.print(tempAHT);
Serial.print("C, Humidity: ");
Serial.print(humiAHT);
Serial.println("%");
Serial.print("BMP280 - Temp: ");
Serial.print(tempBMP);
Serial.print("C, Pressure: ");
Serial.print(pressure);
Serial.println(" Pa");
delay(1000);
}
Note: This code is a skeleton for reference. If the downloaded Library has different class names or methods, open the example files within the Library to check the correct usage
Upload Procedure
- Open Arduino IDE and paste the code
- Select Port via Tools → Port → choose the COM port connected to the board
- Select board type via Tools → Board → choose ESP32 Dev Module
- Click Upload from the Sketch menu
- Wait for Connecting… message then press the BOOT button on the board briefly
- Wait for Done uploading message
Viewing Results
- Open Serial Monitor
- Set baud rate to 115200
- Temperature, humidity, and pressure values will display
Testing the Sensor
Use a hair dryer with hot air pointed at the sensor. The temperature value will increase noticeably. Stop the hot air and wait a moment for the value to return to normal
Reference Video
อยากทำโปรเจคแบบนี้?
รับทำโปรเจค Arduino / IoT จบงานไว ส่งงานครบ พร้อมสอน
If you need Arduino project service or urgent IoT development, see full service details on the home page
จ้างทำโปรเจคเลย