Note

Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.

Why Join?

  • Expert Support: Solve post-sale issues and technical challenges with help from our community and team.

  • Learn & Share: Exchange tips and tutorials to enhance your skills.

  • Exclusive Previews: Get early access to new product announcements and sneak peeks.

  • Special Discounts: Enjoy exclusive discounts on our newest products.

  • Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.

👉 Ready to explore and create with us? Click [here] and join today!

Lesson 20: Temperature, Humidity & Pressure Sensor (BMP280)

In this lesson, you will learn how to use the BMP280 sensor with an Arduino Uno to read atmospheric pressure, temperature, and approximate altitude. We’ll cover integrating the sensor with Arduino using the Adafruit BMP280 library and displaying readings on the Serial Monitor. This session is ideal for beginners in electronics and programming who want to understand sensor interfacing and data acquisition on the Arduino platform.

Required Components

In this project, we need the following components.

It’s definitely convenient to buy a whole kit, here’s the link:

Name

ITEMS IN THIS KIT

LINK

Universal Maker Sensor Kit

94

Universal Maker Sensor Kit

You can also buy them separately from the links below.

Component Introduction

Purchase Link

Arduino UNO R3 or R4

BUY

Temperature, Humidity & Pressure Sensor (BMP280)

BUY

Wiring

../_images/Lesson_20_bme280_module_circuit_uno_bb.png

Code

Note

To install the library, use the Arduino Library Manager and search for “Adafruit BMP280” and install it.

Code Analysis

  1. Including Libraries and Initialization. Necessary libraries are included and the BMP280 sensor is initialized for communication using the I2C interface.

    Note

    To install the library, use the Arduino Library Manager and search for “Adafruit BMP280” and install it.

    • Adafruit BMP280 Library: This library provides an easy-to-use interface for the BMP280 sensor, allowing the user to read temperature, pressure, and altitude.

    • Wire.h: Used for I2C communication.


    #include <Wire.h>
    #include <Adafruit_BMP280.h>
    #define BMP280_ADDRESS 0x76
    Adafruit_BMP280 bmp;  // use I2C interface
    
  2. The setup() function initializes the Serial communication, checks for the BMP280 sensor, and sets up the sensor with default settings.

    void setup() {
      Serial.begin(9600);
      while (!Serial) delay(100);
      Serial.println(F("BMP280 test"));
      unsigned status;
      status = bmp.begin(BMP280_ADDRESS);
      // ... (rest of the setup code)
    
  3. The loop() function reads data from the BMP280 sensor for temperature, pressure, and altitude. This data is printed to the Serial Monitor.

    void loop() {
      // ... (read and print temperature, pressure, and altitude data)
      delay(2000);  // 2-second delay between readings.
    }