To measure the light intensity I use a BH1750FVI light sensor which you can buy at Ebay for about 2€.
The sensor measures the light intensity/brightness between 0 and 65535 lx and sends the measured value via I2C to your microcontroller. Measurement can be done recurring or non-recurring with a resolution of 0.5, 1 or 4 lx.
Controlling the sensor and reading the values can be done very easy using Arduino and the library created by Christopher Laws.
After connecting the sensor to 5V supply voltage and the SDA/SCL pins of your Arduino, ATmega or ATtiny you can flash the example code provided with the library:
#include <Wire.h> #include <BH1750.h> BH1750 lightMeter; void setup(){ Serial.begin(9600); lightMeter.begin(); Serial.println("Running..."); } void loop() { uint16_t lux = lightMeter.readLightLevel(); Serial.print("Light: "); Serial.print(lux); Serial.println(" lx"); delay(1000); }
The code is self-explanatory. In setup() the sensor is initliazed using the begin()-function. If you want to you can set the measurement mode here by providing different parameters. See the h-file of the library for further information. After the initialization the light intensity/brightness in Lux can read using the readLightLevel() command. And that's it, there's nothing more to say ;)
No comments:
Post a Comment