BH1750FVI是日本羅姆(ROHM)半導體生產的數字式環境光傳感IC。其主要特性有:
- I2C數字接口,支持速率最大400Kbps
- 輸出量為光照度(Illuminance)
- 測量范圍1~65535 lux,分辨率最小到1lux
- 低功耗(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 Datasheet
Arduino - Wire Library
I2C Tutorial - SparkFun