BH1750FVI是一個帶有16bit ADC的數位式光強度感測器, 採用I2C傳輸通訊, 可以感測1 - 65535 lx的光強度.
規格
控制時序
採用ADDR=L或ADDR=H的控制指令不同,此點要注意。
1.硬體操作
控制板:Arduino UNO
材料: GY-30模組(感測器BH1750FVI)
2.I/O規劃與Library
(1) 1個輸出控制腳位D13或接VCC,作為ADDRESS控制。2個硬體的IC2腳位,分別控制SDA A4及SCL A5。
(2) Arduino Library: BH1750FVI
3. 程式
#include /* This is a simple example to test the BH1750 Light sensor Connect the sensor to a NodeMCU ESP8266 as follows: VCC <-> 3V3 grijs GND <-> Gnd paars SDA <-> D2 groen SCL <-> D1 blauw ADDR <-> RX geel Arduino UNO VCC <-> 3V3 grijs GND <-> Gnd paars SDA <-> A4 groen SCL <-> A5 blauw ADDR <-> D13 geel */ #include #include // Settings uint8_t ADDRESSPIN = 13; BH1750FVI::eDeviceAddress_t DEVICEADDRESS = BH1750FVI::k_DevAddress_H; BH1750FVI::eDeviceMode_t DEVICEMODE = BH1750FVI::k_DevModeContHighRes; // Create the Lightsensor instance BH1750FVI LightSensor(ADDRESSPIN, DEVICEADDRESS, DEVICEMODE); void setup() { Serial.begin(115200); LightSensor.begin(); Serial.println("Running..."); } void loop() { uint16_t lux = LightSensor.GetLightIntensity(); // Serial.print("Light: %d lux", lux); Serial.println(lux); delay(250); }
時序分析
因採ADDR=H模式,因此運算結果為讀取值228/1.2=190,與UART顯示的數值一致。
全站熱搜