/* Example of BH1750 library usage. This example initialises the BH1750 object using the default high resolution continuous mode and then makes a light level reading every second. Connections - VCC to 3V3 or 5V - GND to GND - SCL to SCL (A5 on Arduino Uno, Leonardo, etc or 21 on Mega and Due, on esp8266 free selectable) - SDA to SDA (A4 on Arduino Uno, Leonardo, etc or 20 on Mega and Due, on esp8266 free selectable) - ADD to (not connected) or GND ADD pin is used to set sensor I2C address. If it has voltage greater or equal to 0.7VCC voltage (e.g. you've connected it to VCC) the sensor address will be 0x5C. In other case (if ADD voltage less than 0.7 * VCC) the sensor address will be 0x23 (by default). */ #include <BH1750.h> #include <Wire.h> BH1750 lightMeter; void setup() { Serial.begin(9600); // Initialize the I2C bus (BH1750 library doesn't do this automatically) Wire.begin(); // On esp8266 you can select SCL and SDA pins using Wire.begin(D4, D3); // For Wemos / Lolin D1 Mini Pro and the Ambient Light shield use // Wire.begin(D2, D1); lightMeter.begin(); Serial.println(F("BH1750 Test begin")); } void loop() { float lux = lightMeter.readLightLevel(); Serial.print("Light: "); Serial.print(lux); Serial.println(" lx"); delay(1000); } 用arduino运行后为什么会出现[BH1750] Device is not configured! Light: -2.00 lx 错误
时间: 2024-04-28 13:20:42 浏览: 157
基于Arduino UNO的BH1750照度测试程序
4星 · 用户满意度95%
这个错误可能是因为BH1750传感器没有正确初始化导致的。在BH1750库的使用中,需要调用`lightMeter.begin()`来初始化传感器。请确保你已经正确地连接了传感器,并且使用的是正确的I2C地址。你还可以尝试重新插拔传感器,或者检查你的代码是否正确。如果问题仍然存在,你可以尝试使用其他的库或者检查传感器是否损坏。
阅读全文