BH1750FVI is a high presion lux sensor with IIC interface.You can react to the illuminate measured.
The lux (symbol: lx) is the SI unit of illuminance and luminous emittance, measuring luminous flux per unit area.It is equal to one lumen per square metre.
#include <Wire.h> #define ADDR 0b0100011 void setup() { // put your setup code here, to run once: Serial.begin(9600); Wire.begin(); Wire.beginTransmission(ADDR); Wire.write(0b00000001); Wire.endTransmission(); } void loop() { // put your main code here, to run repeatedly: int val = 0; // reset Wire.beginTransmission(ADDR); Wire.write(0b00000111); Wire.endTransmission(); delay(100); Wire.beginTransmission(ADDR); Wire.write(0b00100000); Wire.endTransmission(); // typical read delay 120ms delay(120); Wire.requestFrom(ADDR, 2); // 2byte every time for (val=0; Wire.available()>=1; ) { char c = Wire.read(); //Serial.println(c, HEX); val = (val << 8) + (c & 0xFF); } val = val / 1.2; Serial.print("lx: "); Serial.println(val); Serial.println("OK"); digitalWrite(13, HIGH); delay(100); }