Dear friends welcome to another Arduino project tutorial!
In this tutorial we are going to take a first look at the new BME280 sensor, a new very interesting sensor. We are going to build a simple but very accurate weather station project. I have built a similar project 2 years ago, using different sensors. Now that we have a new sensor available which makes things easier, it’s time to update the project. As you can see, on the LCD display we can see the temperature, the humidity and the barometric pressure. The readings are updated every two seconds. This is a very easy project to build so it is ideal for beginners! Let’s build it!
Step 1: Get All the PartsThe parts needed in order to build this project are the following:
- An Arduino Mega ▶ http://bit.ly/ArduinoMega
- A BME280 sensor ▶ http://bit.ly/bme280
- An LCD shield for Arduino ▶ http://bit.ly/ArduinoKeypadDisplay
- A powerbank ▶ http://bit.ly/PowerBank_XiaoMi
- Some wires ▶ http://bit.ly/Wires3InOne
The cost of the project is around $18.
Step 2: BME280 SensorThe BME280 in a new great sensor from Bosch. So far I was using the BMP180 sensor which can measure temperature and barometric pressure. The BME280 sensor can measure temperature, humidity and barometric pressure! How cool is that! We just need one sensor to build a complete weather station!
In addition to that, the sensor is very small in size and very easy to use. The module we are going to use today, uses the I2C interface so it makes communication with Arduino very easy. We only to connect power and two more wires to make it work.
There are already many libraries developed for this sensor so we can use it in our projects very easily!
The cost of the sensor is about 5$.
You can get it here ▶ http://bit.ly/bme280
NOTE: We need the BME280 sensor. There is also a BMP280 sensor which does not not offer humidity measurement. Be careful to order to sensor you need.
Step 3: LCD ShieldThe LCD shield is a very useful shield. It offers a 16x2 LCD display along with some buttons. It also offers a potentiometer which controls the contrast of the display.
Althouth there is not much going on on this shield, it great shield in my opinion. You can easily connect it to an Arduino and display something on it at once. You don't even need to install a library to make it work. The LiquidCrystal library that is required was installed on your machine when you installed the Arduino IDE.
If you are new to Arduino, or if you need an easy to use display to start prototyping with it, this LCD shield is what you need. In addition to that, it costs less than 5$!
You can get it here ▶ http://bit.ly/ArduinoKeypadDisplay
Step 4: Connecting the PartsLet’s connect the sensor to Arduino.
We are using the Arduino Mega today but you can use the Arduino Uno as well if you solder some header pins to your LCD shield. The Arduino Mega make things easier for beginners.
At first we connect the LCD shield to the Arduino Mega. It is very easy, you connect just like any other shield.
Then we connect the Vin pin of the sensor to the Arduino Mega 5V output. Next we connect the GND pin of the sensor to the Arduino Mega GND. The next step is to connect the SCL pin of the sensor to the SCL pin of the Arduino Mega, and the SDA pin of the sensor to the SDA pin of the Arduino Mega. Check the attached photos.
That’s it, if we load the code and power up the project we can see that after 2 seconds the readings from the sensor are displayed on the screen. Our project is ready! You can now build your own enclosure for it, and you have a very accurate weather station! Let’s now take a look at the code of the project.
Step 5: The Code of the ProjectThe code of the project uses 3 libraries. We need to download 2 of them, since the 3rd one is already installed with the Arduino IDE.
We need to download the
- Adafruit BME280 library ▶ https://github.com/adafruit/Adafruit_BME280_Library
- Adafruit Sensor library ▶ https://github.com/adafruit/Adafruit_Sensor
In order to see how to install the libraries watch the attached video, where I explain how to do it.
Now that we have installed the libraries we need to define the altitude for our location in meters in order to get accurate barometric pressure readings.
#define ALTITUDE 216.0 // Altitude in Sparta, Greece
As you can see, the code is very simple.
void setup(void) { lcd.begin(16, 2);
lcd.print("Reading sensors"); bool status;
// default settings
status = bme.begin(0x76); //The I2C address of the sensor I use is 0x76 if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
}
At first we initialize the sensor and the display.
Then in the loop function the read the sensor every 2 seconds. After reading the sensor we print the values on the display.
delay(2000); getPressure();
getHumidity();
getTemperature();
lcd.clear();
//Printing Temperature
String temperatureString = String(temperature,1);
lcd.print("T:");
lcd.print(temperatureString);
lcd.print((char)223);
lcd.print("C ");
In this version of the code we display the temperature in degrees Celsius but I have also prepared a version of the code with the temperature measured in degrees Fahrenheit. You can find both versions of the code of the project attached to this tutorial.
Step 6: Final ThoughtsThat’s today’s project. An Arduino Weather Station project with the new BME280 sensor.
The new BME280 sensor is very easy to use since it uses the I2C interface. I am going to use it a lot in the future projects because it offers temperature, humidity and pressure sensors in one package. This makes our weather station projects easier to build and more compact. I would love to hear your opinion about this sensor. Are you going to use it any of your projects? If yes, what kind of projects are you going to build using this sensor? Please post your ideas below, I would love to read them. Thanks!
Comments