กลับหน้าหลัก
views
How to Use ESP32 with AHT20+BMP280 Temperature Humidity Pressure Module
Last updated on

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

Circuit diagram showing ESP32 connected to AHT20+BMP280 module on a breadboard

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

ESP32AHT20+BMP280
3V3VCC
GNDGND
D21SDA
D22SCL
GPIO pin reference table for ESP32 I2C connection

Library Installation

  1. Download the Library from the link provided
  2. Extract the files using WinRAR or WinZip
  3. Place the extracted folder into the libraries folder 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

  1. Open Arduino IDE and paste the code
  2. Select Port via Tools → Port → choose the COM port connected to the board
  3. Select board type via Tools → Board → choose ESP32 Dev Module
  4. Click Upload from the Sketch menu
  5. Wait for Connecting… message then press the BOOT button on the board briefly
  6. Wait for Done uploading message

Viewing Results

  1. Open Serial Monitor
  2. Set baud rate to 115200
  3. Temperature, humidity, and pressure values will display
Serial Monitor window displaying temperature humidity and air pressure readings

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

จ้างทำโปรเจคเลย

Project estimate

Want something like this? Open the estimate page.

The long form is now on a separate estimate page, so this article stays clean.

ความคิดเห็น

รีวิวจากคนใช้งานจริง

รีวิวจากลูกค้าและคนที่เคยใช้งาน

ถ้าเคยสั่งงาน เคยอ่านหน้านี้แล้วได้ประโยชน์ หรือมีข้อเสนอแนะ ฝากรีวิวไว้ได้เลย

กำลังโหลดรีวิว...