Measuring Light Intensity

Any camera buffs out there? Sometimes it is handy to be able to measure the amount of light at a particular spot. This is needed sometimes so you can adjust your camera to take the ‘perfect’ picture. Or perhaps you are calculating the amount of solar energy your solar panels will be producing given the amount of light available.

In any case, there  are a couple of components that are very useful for this, the TSL235R light to frequency converter and the BH1750 digital light sensor.

 

TSL235R

TSL235R

BH1750

BH1750

 

 

 

 

 

 

 

 

 

Here are both components on a DIY Arduino breadboard (click on the image to enlarge it):

Arduino LUX Meter

Arduino LUX Meter

Here is the Arduino sketch (code) to get the readings from these components. (Note: the code comments show how these components are wired.) Two libraries are need for this sketch (Wire and BH1750).  The BH1750 library can be downloaded here.  The Wire library is included in the standard Arduino IDE.

 

/*
Arduino Lux Meter
From earl@microcontrollerelectronics.com

BH1750 Connection:
 VCC-5v
 GND-GND
 SCL-SCL(analog pin 5)
 SDA-SDA(analog pin 4)
 ADD-NC or GND

TSL235R Connection:
 PIN 1 - GND
 PIN 2 - VDD - 5V
 PIN 3 - SIGNAL IRQ 0

*/

#include <Wire.h>
#include <BH1750.h>

BH1750 lightMeter;

#define led 9

volatile unsigned long cnt = 0;
unsigned long oldcnt = 0;
unsigned long t = 0;
unsigned long last;

void irq1()
{
 cnt++;
}
void setup(){
 pinMode(led, OUTPUT); 
 Serial.begin(115200);
 Serial.println("START");
 pinMode(2, INPUT);
 digitalWrite(2, HIGH);
 attachInterrupt(0, irq1, RISING);
 lightMeter.begin();
}

void loop() {
 if (millis() - last >= 1000) {
 last = millis();
 t = cnt;
 unsigned long hz = t - oldcnt;
 digitalWrite(led, HIGH);
 Serial.print("FREQ: ");
 Serial.print(hz);
 Serial.print(" = ");
 Serial.print((hz+50)/100); // +50 == rounding last digit
 Serial.print(" mW/m2");
 oldcnt = t;

 uint16_t lux = lightMeter.readLightLevel();
 Serial.print(" Lux: ");
 Serial.println(lux);

 delay(500);
 digitalWrite(led, LOW);

}

2 comments

    • HAIAN QIU on November 14, 2016 at 3:40 pm
    • Reply

    We are trying to figure out how to measure light intensity of a small light spot(0.5 mm in diameter). Do you have any idea?

      • earl on November 15, 2016 at 7:02 am
        Author
      • Reply

      The sensors mentioned in this post are really useful for ‘hobby’ applications. Typically, in that scenario, there can be multiple light sources which all add up. To measure light from a specific source is a whole different matter. I’d image to be very specific, you’d need a lab environment (darkness) and then the only source of light would be the source you are wanting to measure.

Leave a Reply

Your email address will not be published.