DHT22 Replacement: The BME280

1. The Design

The BME280 is a cheap I2C/ SPI compatible unit capable of displaying temperature, barometric pressure, elevation, & humidity of its environment. I find that its a lot more useful than the DHT22 in that it not only requires just four wires to operate, but also doesn’t require a 10KΩ resistor & is less prone to failing. Its also a lot smaller that the DHT22 as pictured below & is overall sleeker & has a more professional look.

 

There are two types of the 280, the 5 volt version (BME280) & the 3.3 volt version (BMP280). I’ve determined through testing that the 5v version far superior of the two. The chief difference being that the 5v version can determine the environmental humidity while the 3.3v cannot for whatever reason. Though a small difference, this makes the 5v BME280 deployable for drone projects in which knowing the enclosure’s internal temperature can avoid system overheating or the activation of ventilation fans or automated pet keeping where the temperature & humidity go hand in hand to maintain optimal parameters for your pet’s health & safety.

BMP280 3.3v & BMP280 5v
The BME280 5v version (right) is superior than the BMP280 3.3v (left) as it can determine environmental humidity.

The pin designations are the same no matter the version you choose, as we will only use I2C to communicate sensor data to the arduino. The chart below shows the required connections from the BMP280 on the Arduino:

.tg {border-collapse:collapse;border-spacing:0;} .tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;} .tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;} .tg .tg-k50t{font-family:"Times New Roman", Times, serif !important;;background-color:#ffffff;color:#000000;border-color:inherit;text-align:center;vertical-align:top} .tg .tg-8soa{font-family:"Times New Roman", Times, serif !important;;background-color:#ffffff;color:#000000;text-align:center;vertical-align:top}
BME 280 Pin Arduino Pin
Vin 5V
GND GND
SCL A5
SDA A4

 

2. The Code

The required library can be found below:

Add the .zip file to your library by opening the IDE & navigating to Sketch> Add Library> Add .zip Library> (.zip library file path)> Select

The last task is to open a blank sketch and copy/paste the BME280 code & upload it to the arduino.

BME280 Code

#include <Wire.h>
#include “SparkFunBME280.h”
BME280 mySensorB;
void setup()
{
Serial.begin(9600);
Serial.println(“Reading basic values from BME280”);
Wire.begin();
mySensorB.setI2CAddress(0x76); //Connect to a second sensor
if (mySensorB.beginI2C() == false) Serial.println(“Sensor B connect failed”);
}
void loop()
{
Serial.print(“Humidity: “);
Serial.print(mySensorB.readFloatHumidity(), 0);

Serial.print(” Pressure: “);
Serial.print(mySensorB.readFloatPressure(), 0);

Serial.print(” Alt: “);
//Serial.print(mySensorB.readFloatAltitudeMeters(), 1);
Serial.print(mySensorB.readFloatAltitudeFeet(), 1);

Serial.print(” Temp: “);
//Serial.print(mySensor.readTempC(), 2); // Remove “//” if you want to read in Celsius, keep if you’re American.
Serial.print(mySensorB.readTempF(), 2);
Serial.println();
Serial.println();
delay(1000);
}

You can customize the display output by commenting out sensor readings you don’t need. If you’re using this unit for an animal enclosure, you won’t need pressure or altitude settings.

###

Note that the altitude readings depend on the weather of your local area & is liable to change from day to day weather. This sensor can still be used for a drone if you lay it on the ground & set the code to take its first reading as being ground level despite not matching the exact altitude for your location. Have the code execute a math equation so that the newest reading is subtracted from the ground elevation to give you the drone’s new elevation in feet or meters.

 

3. The Results

Open the serial monitor after uploading the code & you should see the following:

If you cannot see the displayed picture, verify you have the correct BME280 type & have it connected to the appropriate voltage source. Note that even the 5v version will operate if connected to 3.3v without any issues, so use it if you’re having issues identifying what version you’re using (Remember there’s a picture above identifying both units.)