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!
BMP180
Overview
In this tutorial, we delve into the GY-87 IMU module, focusing on the BMP180 sensor for measuring temperature, pressure, and altitude. Ideal for applications like weather monitoring and altitude tracking, this lesson covers interfacing the GY-87 with an Arduino Uno and using the Adafruit BMP085 library. You’ll learn how to initialize the BMP180 sensor and read its data on the Arduino Serial Monitor, a crucial skill for projects that require environmental data.
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 |
|---|---|---|
Elite Explorer Kit |
300+ |
You can also buy them separately from the links below.
COMPONENT INTRODUCTION |
PURCHASE LINK |
|---|---|
- |
|
- |
Wiring
Schematic Diagram
Code
Note
You can open the file
09-gy87_bmp180.inounder the path ofelite-explorer-kit-main\basic_project\09-gy87_bmp180directly.Or copy this code into Arduino IDE.
Note
To install the library, use the Arduino Library Manager and search for “Adafruit BMP085 Library” and install it.
1/*
2 This Arduino code interfaces with the GY-87 IMU (Inertial Measurement Unit) module,
3 specifically using the BMP180 sensor for measuring temperature, pressure, and
4 calculating altitude. It initializes the BMP180 sensor and continuously outputs its
5 readings to the Serial Monitor.
6
7 Board: Arduino Uno R4
8 Component: GY-87 IMU Module
9 Library: https://github.com/adafruit/Adafruit-BMP085-Library (Adafruit BMP085 Library by Adafruit)
10*/
11
12// Include required libraries
13#include <Adafruit_BMP085.h>
14
15// Initialize sensor objects
16Adafruit_BMP085 bmp;
17
18void setup() {
19 // Initialize the serial communication with a baud rate of 9600
20 Serial.begin(9600);
21
22 // Initialize BMP180 barometric sensor
23 initializeBMP180();
24}
25
26void loop() {
27 // Print BMP180 data
28 printBMP180();
29
30 delay(500);
31}
32
33void initializeBMP180() {
34 // Start BMP180 initialization
35 if (!bmp.begin()) {
36 Serial.println("Could not find a valid BMP180 sensor, check wiring!");
37 while (1)
38 ; // Halt if sensor not found
39 }
40 Serial.println("BMP180 Found!");
41}
42
43void printBMP180() {
44 Serial.println();
45 Serial.println("BMP180 ------------");
46 Serial.print("Temperature = ");
47 Serial.print(bmp.readTemperature());
48 Serial.println(" *C");
49
50 Serial.print("Pressure = ");
51 Serial.print(bmp.readPressure());
52 Serial.println(" Pa");
53
54 // Calculate altitude assuming 'standard' barometric
55 // pressure of 1013.25 millibar = 101325 Pascal
56 Serial.print("Altitude = ");
57 Serial.print(bmp.readAltitude());
58 Serial.println(" meters");
59
60 Serial.print("Pressure at sealevel (calculated) = ");
61 Serial.print(bmp.readSealevelPressure());
62 Serial.println(" Pa");
63 Serial.println("BMP180 ------------");
64 Serial.println();
65}
Code Analysis
initializeBMP180()Initialize the BMP180 sensor.
void initializeBMP180() { // Start BMP180 initialization if (!bmp.begin()) { Serial.println("Could not find a valid BMP180 sensor, check wiring!"); while (1) ; // Halt if sensor not found } Serial.println("BMP180 Found!"); }
printBMP180()Print the values read by the BMP180 sensor.
void printBMP180() { Serial.println(); Serial.println("BMP180 ------------"); Serial.print("Temperature = "); Serial.print(bmp.readTemperature()); Serial.println(" *C"); Serial.print("Pressure = "); Serial.print(bmp.readPressure()); Serial.println(" Pa"); // Calculate altitude assuming 'standard' barometric // pressure of 1013.25 millibar = 101325 Pascal Serial.print("Altitude = "); Serial.print(bmp.readAltitude()); Serial.println(" meters"); Serial.print("Pressure at sealevel (calculated) = "); Serial.print(bmp.readSealevelPressure()); Serial.println(" Pa"); Serial.println("BMP180 ------------"); Serial.println(); }