BH1750FVI是日本罗姆(ROHM)半导体生产的数字式环境光传感IC。其主要特性有:
- I2C数字接口,支持速率最大400KHz
- 输出量为光照度(Illuminance)
- 测量范围1~65535 lux,分辨率最小到
- 低功耗(Power down)功能
- 屏蔽50/60Hz市电频率引起的光照变化干扰
- 支持两个I2C地址,通过ADDR引脚选择
- 较小的测量误差(精度误差最大值+-20%)
电路连接
由于模块本身已经带有了3.3V稳压芯片和I2C电平转换电路,因此可将模块直接与UNO板的I2C接口相连。对于UNO板,I2C总线的SDA信号线对应A4管脚,SCL时钟线对应A5管脚。
功能测试
BH1750FVI支持单次或连续两种测量模式,每种测量模式又提供了0.5lux、1lux、4lux三种分辨率供选择。分辨力越高,一次测量所需的时间就越长。在单次测量模式时,每次测量之后传感器都自动进入Power Down模式。
以下代码测试了传感器在One Time H-Resolution Mode模式时的功能。
1 /* 2 Measurement of illuminance using the BH1750FVI sensor module 3 Connection: 4 Module UNO 5 VCC <-----> 5V 6 GND <-----> GND 7 SCL <-----> A5 8 SDA <-----> A4 9 ADD <-----> NC 10 11 */ 12 #include <Wire.h> 13 14 #define ADDRESS_BH1750FVI 0x23 //ADDR="L" for this module 15 #define ONE_TIME_H_RESOLUTION_MODE 0x20 16 //One Time H-Resolution Mode: 17 //Resolution = 1 lux 18 //Measurement time (max.) = 180ms 19 //Power down after each measurement 20 21 byte highByte = 0; 22 byte lowByte = 0; 23 unsigned int sensorOut = 0; 24 unsigned int illuminance = 0; 25 26 27 void setup() 28 { 29 Wire.begin(); 30 Serial.begin(115200); 31 } 32 33 void loop() 34 { 35 Wire.beginTransmission(ADDRESS_BH1750FVI); //"notify" the matching device 36 Wire.write(ONE_TIME_H_RESOLUTION_MODE); //set operation mode 37 Wire.endTransmission(); 38 39 delay(180); 40 41 Wire.requestFrom(ADDRESS_BH1750FVI, 2); //ask Arduino to read back 2 bytes from the sensor 42 highByte = Wire.read(); // get the high byte 43 lowByte = Wire.read(); // get the low byte 44 45 sensorOut = (highByte<<8)|lowByte; 46 illuminance = sensorOut/1.2; 47 Serial.print(illuminance); Serial.println(" lux"); 48 49 delay(1000); 50 }
参考资料
什么是“光照度(Illuminance)”BH1750FVI DatasheetArduino - Wire LibraryI2C Tutorial - SparkFun
时间: 2024-10-27 13:20:54