BME280简介
BME280是一个三合一数字环境检测传感器,可以测量所处周围环境的温度、湿度、气压。由于气压随高度变化,可以非常精确地估计高度,因此对于无人机和导航应用来说非常方便。支持IIC和SPI通信接口。
敏感元件 | 测量范围 | 误差 |
---|---|---|
温度 | -40 to 85 ºC | +/- 1 ºC |
湿度 | 0 to 100% RH | +/- 3 %RH |
气压 | 300 to 1100 hPa | +/- 1 hPa |
接口说明
VIN 供电输入正极3.3-5V
GND 供电负极
SCL IIC接口时钟信号输入引脚
SDA IIC接口数据输入输出引脚
电路板中间焊盘为传感器芯片SDO引脚为传感器IIC器件地址设置引脚,默认接GND(1110110)0x76,若需接高电平则需要把中间焊盘和上面焊盘的PCB导线用小刀割断,并用锡连接中间焊盘和下面焊盘,此时器件地址为(1110111)0x77
BME280与Arduino UNO接线与程序
BME280 | IIC接线方式 |
---|---|
SCL | A5 |
SDA | A4 |
Arduino IDE库管理器安装 Adafruit_BME280 library
Arduino IDE库管理器安装Adafruit Unified Sensor
打开示例代码
/***************************************************************************
This is a library for the BME280 humidity, temperature & pressure sensor
Designed specifically to work with the Adafruit BME280 Breakout
----> http://www.adafruit.com/products/2650
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
to interface. The device's I2C address is either 0x76 or 0x77.
Adafruit invests time and resources providing this open source code,
please support Adafruit andopen-source hardware by purchasing products
from Adafruit!
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
BSD license, all text above must be included in any redistribution
See the LICENSE file for details.
***************************************************************************/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
unsigned long delayTime;
void setup() {
Serial.begin(9600);
while(!Serial); // time to get serial running
Serial.println(F("BME280 test"));
unsigned status;
// default settings
status = bme.begin();
// You can also pass in a Wire library object like &Wire2
// status = bme.begin(0x76, &Wire2)
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
Serial.print(" ID of 0x60 represents a BME 280.\n");
Serial.print(" ID of 0x61 represents a BME 680.\n");
while (1) delay(10);
}
Serial.println("-- Default Test --");
delayTime = 1000;
Serial.println();
}
void loop() {
printValues();
delay(delayTime);
}
void printValues() {
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" °C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.print("Approx. Altitude = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");
Serial.println();
}
打开串口监视器显示出传感器测量的数据
总结
通过本实验能快速直观的使用传感器获取所处环境的参数。