资讯详情

Arduino UNO测试BME280温湿度气压传感器

原文链接:https://www.yourcee.com/newsinfo/2928902.html

BME280简介

BME280是一种三合一数字环境检测传感器,可以测量周围环境的温度、湿度和压力。由于压力随高度而变化,高度可以准确估计,因此无人机和导航应用非常方便。IIC和SPI通信接口。 在这里插入图片描述

敏感元件 测量范围 误差
温度 -40 to 85 oC /- 1 oC
湿度 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导线用小刀切断,中间焊盘和下面的焊盘用锡连接。此时,设备地址为0(111011)x77

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();
}

打开串口监视器显示出传感器测量的数据

总结

通过本实验能快速直观的使用传感器获取所处环境的参数。

标签: bme280湿度传感器

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台