基于Arduino使用 BMP180气压传感器
BMP180是当前最常用的气压传感器传感器之一,可以检测温度和气压,通过这两个数据还可以计算出当前海拔高度。BMP180气压传感器具有体积小,功耗低、精度高等优点,因此广泛的被应用于手机,手表等小型编写式设计。
技术参数
- 压力范围:300-1100hPa(海报500~9000米)
- 电源电压:1.8V-3.6V(VDDA),1.62V-3.6V(VDD),VIN3.3V/5V
- LCC8封装:无铅陶瓷载体封装(LCC)
- 低功耗:5µA(标准模式)
- 高精度:在低功耗模式下,分分辨率为0.06hPa(0.5米)
- 高线性模式下,分辨率为0.03hPa(0.25米)
- 含温度输出
- I2C接口
- 温度补偿
- 无铅,符合RoHS规范
- MSL1反应时间:7.5ms
- 待机电流:0.1µA
- 无需外部时钟电路
接线图示
1,下载库文件
文件名:SFE_BMP180-master.zip 下载链接:https://pan.baidu.com/s/1qP2Uf3XAaFYdfnY3FNctDg 提取码:2545
2,安装库文件
文件下载后无需解压,点击Arduino IDE菜单栏项目—加载库—添加.ZIP库...
选择SFE_BMP180-master.zip文件
Arduino代码:
- #include <SFE_BMP180.h>
- #include <Wire.h>
- SFE_BMP180 pressure;
- #define ALTITUDE 10.0 // 当地海拔
- void setup()
- {
- Serial.begin(9600);
- Serial.println("REBOOT");
- if (pressure.begin())
- Serial.println("BMP180 init success");
- else
- {
- Serial.println("BMP180 init fail\n\n");
- while(1); // 暂停
- }
- }
- void loop()
- {
- char status;
- double T,P,p0,a;
- Serial.println();
- Serial.print("provided altitude: ");
- Serial.print(ALTITUDE,0);
- Serial.println(" meters ");
- status = pressure.startTemperature();
- if (status != 0)
- {
- delay(status);
- status = pressure.getTemperature(T);
- if (status != 0)
- {
- Serial.print("temperature: ");
- Serial.print(T,2);
- Serial.println(" deg C ");
- status = pressure.startPressure(3);
- if (status != 0)
- {
- delay(status);
- status = pressure.getPressure(P,T);
- if (status != 0)
- {
- Serial.print("absolute pressure: ");
- Serial.print(P,2);
- Serial.println(" mb ");
- p0 = pressure.sealevel(P,ALTITUDE); // we're at 10 meters (Boulder, CO)
- Serial.print("relative (sea-level) pressure: ");
- Serial.print(p0,2);
- Serial.println(" mb ");
- a = pressure.altitude(P,p0);
- Serial.print("computed altitude: ");
- Serial.print(a,0);
- Serial.println(" meters ");
- }
- else Serial.println("error retrieving pressure measurement\n");
- }
- else Serial.println("error starting pressure measurement\n");
- }
- else Serial.println("error retrieving temperature measurement\n");
- }
- else Serial.println("error starting temperature measurement\n");
- delay(5000);
- }
复制代码
显示效果如下:
|