How to Use ESP8266 with BMP280 to Read Temperature and Pressure
How to Use ESP8266 with BMP280 to Read Temperature and Pressure
In this guide, you’ll wire a NodeMCU ESP8266 to a BMP280 sensor and read temperature, atmospheric pressure, and altitude through the Arduino IDE Serial Monitor.
Components Needed
- NodeMCU ESP8266 V2 (CP2102)
- BMP280 3.3V sensor module
- Micro USB cable for programming and power
- Breadboard MB-102 (830 points)
- Jumper wires (male-male, male-female, female-female)
Wiring ESP8266 to BMP280
Connect the ESP8266 to the BMP280 as follows:
| ESP8266 | BMP280 |
|---|---|
| 3V3 | VCC |
| GND | GND |
| D2 | SDA |
| D1 | SCL |
Note: The 3.3V BMP280 module draws power directly from the ESP8266’s 3V3 pin. No voltage divider or level shifter is required.
Installing the Library
- Open Arduino IDE
- Go to Sketch > Include Library > Manage Libraries
- Search for
Adafruit BMP280 - Click Install on the Adafruit BMP280 Library by Adafruit
Code for Reading BMP280
#include <Wire.h>
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp;
void setup() {
Serial.begin(115200);
Serial.println(F("BMP280 Test"));
if (!bmp.begin(0x76)) {
Serial.println(F("Could not find BMP280 sensor!"));
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));
Serial.println(" m");
Serial.println();
delay(1000);
}
Adjust this: The value
1013.25inreadAltitude()represents the local sea-level pressure in hPa. Adjust it to your actual atmospheric pressure for more accurate altitude readings.
Uploading and Testing
- Connect your ESP8266 via USB
- Select the correct Board and Port from the Tools menu
- Click Upload and wait for Done Uploading
- Open Serial Monitor, set baud rate to 115200
- You will see temperature, pressure, and altitude values printed every second
[image: Serial Monitor window displaying live BMP280 readings for temperature, pressure, and altitude]
Testing the Sensor Response
With Serial Monitor open, use a hair dryer to blow warm air toward the BMP280 sensor. You should see the temperature reading rise quickly. When you stop, the value will gradually return to room temperature, confirming the sensor works correctly.
Summary
Connecting ESP8266 to BMP280 requires just four wires. After installing the library and uploading the sketch, you get real-time temperature, pressure, and altitude data. From here, you can extend this to display on an LCD screen or send data to a web server.
อยากทำโปรเจคแบบนี้?
รับทำโปรเจค Arduino / IoT จบงานไว ส่งงานครบ พร้อมสอน
If you need Arduino project service or urgent IoT development, see full service details on the services page
จ้างทำโปรเจคเลย