Example Code for Arduino-Continuous Data Reading in I2C Mode
Last revision 2026/02/05
The article guides users through the process of continuously reading data from a BMV080 PM2.5 sensor using an Arduino setup in I2C mode.
Hardware Preparation
- SEN0663 Fermion: BMV080 PM2.5 Sensor × 1
- DFR0654 FireBeetle 2 ESP32-E Development Board × 1
- Several Dupont Wires
Software Preparation
- Download and install Arduino IDE: Download Link
- Download DFRobot_BMV080 library: DFRobot_BMV080 Library
- Library Installation Guide: View Installation Tutorial
Wiring Diagram

Connect the BMV080 sensor to the ESP32-E as illustrated, with the key wiring correspondences outlined below:
- Sensor Pin "3V3" → ESP32-E 3.3V
- Sensor Pin "GND" → ESP32-E GND
- Sensor I2C Pin "SCL" → ESP32-E SCL (default GPIO22)
- Sensor I2C Pin "SDA" → ESP32-E SDA (default GPIO21)
Other Preparation Work
- On the sensor’s "I2C/SPI Switching Pads", solder one 0Ω resistor to the I2C side (default mode; no modification to the factory configuration is required).
- Solder one 0Ω resistor each to the pads beneath the "H" silkscreen corresponding to the CSB and MISO pins (the I2C address will be 0x57 in this configuration).
Sample Code
#include "DFRobot_BMV080.h"
// Set the stack size of the loop task to 60KB
SET_LOOP_TASK_STACK_SIZE(60 * 1024);
// I2C address selection table:
/*
* --------------------------------------
* | CSB Pin | MISO Pin | Address |
* --------------------------------------
* | 0 | 0 | 0x54 |
* --------------------------------------
* | 0 | 1 | 0x55 |
* --------------------------------------
* | 1 | 0 | 0x56 |
* --------------------------------------
* | 1 | 1 | 0x57 |
* --------------------------------------
*/
// Create an I2C sensor instance with address 0x57 (can be modified according to actual wiring)
DFRobot_BMV080_I2C sensor(&Wire, 0x57);
float pm1, pm2_5, pm10;
void setup() {
char id[13]; // Used to store the chip ID of the BMV080 sensor
Serial.begin(115200);
while (!Serial)
delay(100); // Wait for the serial port to be ready
Serial.println("Continuous reading mode started");
while (sensor.begin() != 0) {
Serial.println("Sensor initialization failed! Please check if the sensor connection is correct");
delay(1000);
}
Serial.println("Sensor initialization successful");
while (sensor.openBmv080()) {
Serial.println("Sensor opening failed");
delay(1000);
}
Serial.println("Sensor opened successfully");
// Get and print the chip ID
sensor.getBmv080ID(id);
Serial.println("Chip ID: " + String(id));
// Enable obstruction detection (a prompt will be shown if obstructed, indicating data may be invalid)
sensor.setObstructionDetection(true);
// Set measurement mode to continuous mode
if (0 == sensor.setBmv080Mode(CONTINUOUS_MODE)) {
Serial.println("Measurement mode set successfully (continuous mode)");
} else {
Serial.println("Failed to set measurement mode");
}
}
void loop() {
if (sensor.getBmv080Data(&pm1, &pm2_5, &pm10)) {
// Print PM1, PM2.5, PM10 values
Serial.print("PM1: " + String(pm1) + " ug/m³ ");
Serial.print("PM2.5: " + String(pm2_5) + " ug/m³ ");
Serial.print("PM10: " + String(pm10) + " ug/m³");
// Check if obstructed
if (sensor.ifObstructed()) {
Serial.print(" Note: Sensor is obstructed, data may be invalid");
}
Serial.println();
}
delay(100);
}
Result

Was this article helpful?
