In this quick tutorial, we are going to learn, how to interface BMP 280 with ESP32 and also learn how to solve errors like “Could not find a valid bmp 280 sensor, check wiring.” or got any garbage values instead of the sensor values, while interfacing them.
- 1X ESP 32 WiFi and bluetooth development board
- 1X BMP280 Temperature, barometric pressure and approx altitude sensor
- Few connecting wires
- Micro USB cable
BMP 280 Temperature and pressure sensor Overview:
The BMP280 sensor integrates atmospheric pressure, temperature and relative humidity sensors in a single device, with great precision, low energy consumption and an ultra compact format. Based on BOSCH piezo-resistive technology with great EMC robustness, high precision and linearity, as well as long-term stability. It connects directly to a microcontroller via I2C or SPI.
The pressure sensing stage is similar to the BMP280 sensor, and therefore superior to the BMP180. Regarding the relative humidity sensor, it presents an outstanding performance compared to the DHT22 or DHT21 sensors.
This type of sensor can be used to calculate altitude with great precision (barometer), making it a widely used sensor in Autopilot systems for Drones (UAVs), delivering altitude measurements with an accuracy of up to 1m. Other applications are: Climate Monitoring, Health / Fitness Monitor, Home Automation or Domotics and Air Conditioning.
Datasheet : link
- Communication interface: I2C or SPI (3.3V)
- Operating Voltage: 1.8V – 3.3V DC
- Absolute accuracy: 1 hPa
- Temperature range: -40 ° C to 85 ° C
- Temperature accuracy: 1 ° C
- Temperature resolution: 0.01 ° C
- RH Accuracy: + -3%
- Relative Humidity Range: 0-100% RH
- Ultra-low power consumption
Circuit diagram of interfacing BMP280 and ESP32 on I2C communication
Here we are connecting both the boards by using only 4 connecting wires using I2C connection. For detailed connection check the blow schematic diagram.
In the above image, BMP 280 has 6 pins, 2 pins for 3.3 volts input and Ground respectively. and another 2 pins for SCL, and SDA. As we are connecting them through i2c interface so leave the other two pins CSB, and SDO untouched.
On ESP32, we are connecting the VCC pin to 3.3 volts, and GND pin to GND pin of ESP32. Next, we need to connect, SDA, and SCL pins of BMP 280 to ESP32. but on ESP32, those pin values are not printed. so, lets have a look on, E S P 32 pinout diagram, where SDA, is on Pin D21, and SCL, is on D22.
Now lets connect, those pins to the D21 and D22. That’s it for connection. now, to upload the sample code, to display temperature and pressure. we need to connect, the ESP32 with Micro USB cable to your PC, where Arduino IDE is installed.
Now lets have a look onto the PC, where we compile and execute the code. First, open Arduino IDE, and click on file-> examples -> BMP 280 library and click on Bmp 280 test, to load the sample code.
If you don’t find this, you need to download and install, Adafruit Bmp 280 library, Link here
So, below is the code, which mention, i2c connection, and initializing the bmp280, and printing the values on serial monitor.
Before uploading, select the board as ESP32 Wrover module. and select, the COM port of the device. you can get that, from the device manager ports. now press, the upload button.
After compiling and uploading. Open serial monitor, to check the output. Select the correct baud rate of serial monitor, mentioned in the code.
But unfortunately, we got an error, saying, “Could not find a valid bmp 280 sensor, check wiring.”
To solve this, first we need to find the, i2c address of the bmp sensor, with i2c scanner, like our previous tutorials, link for the code here. upload the code, and open serial monitor, to check the i2c address, where it was 0x76. note it down, and get back to our previous sample code, and type the address, in the sensor initialization line, as shown.
Now upload the code again, and check the serial monitor, where the sensor value like temperature, barometric pressure and approximate altitude is printed as shown in the below image.
Thanks for watching. If you like this tutorial, please like, share, and subscribe to our channel, circuit schools, to help us make, more interesting projects and tutorial videos.