Introduction: Intel Edison: Lux Meter, TSL2561

About: 31 years old tinker and diy hobbyist. From Oulu, Finland. IG @mkarvonen_instructables

Lux meter done with Intel Edison and TSL2561 Lux sensor.

Step 1: Components.

I'm going to be using a Intel Edison with Arduino board. The code should work with any Arduino based board.

Then you will need the TSL2561 Lux sensor. My sensor is ordered from Adafruit.

And lastly something to print the outcome. I used a simple 2x16 LCD screen with RGB back light.

Step 2: Prepare the Sensor.

Solder pins (or wire) to the sensor.

I used pins since it is easy to re-use the component just by removing wires from the pins.

Step 3: Test the Sensor.

Hook the sensor to your board.

In this project the connections are following:

Sensor----------------Arduino Pin

SCL----------------------A5

SDA----------------------A4

ADDR-------------------GND

GND---------------------GND

Vin------------------------3.3V

The ADDR pin can be left floating or be connected to 3.3V.

Download the library for the sensor.

Install the library and run a test code to see if it works.

If you get a error when compiling, Navigate to TSL2561.cpp and add comment marks to the line.

Change

<p>#include  <util/delay.h><util delay.h=""></util></p><p>to</p><p>//#include  <util/delay.h></p><p>Save the document and </p><p><util delay.h=""></util></p>

This is only necessary if there is an error. With normal Arduino this should not be a problem tough. For Intel Edison is a little bit different.


Step 4: Set Up the Final Code.

The code i'm using is based on the example code.

First to the definitions and global variables. The line " TSL2561 tsl(TSL2561_ADDR_LOW); " means that my ADDR pin on the sensor is in ground.

<p>#include <wire.h><br>#include "TSL2561.h"
#include "rgb_lcd.h"</wire.h></p><p>TSL2561 tsl(TSL2561_ADDR_LOW); </p><p>rgb_lcd lcd;</p><p>const int colorR = 255;
const int colorG = 0;
const int colorB = 0;</p>

Then do the setup.

<p>void setup(void) {<br>  Serial.begin(9600);
  
  if (tsl.begin()) {
    Serial.println("Found sensor");
  } else {
    Serial.println("No sensor?");
    while (1);
    
    
  }
    </p><p>  tsl.setGain(TSL2561_GAIN_0X);         // set no gain (for bright situtations)
  //tsl.setGain(TSL2561_GAIN_16X);      // set 16x gain (for dim situations)
  
  
  tsl.setTiming(TSL2561_INTEGRATIONTIME_13MS);</p><p>  
 lcd.begin(16, 2);    
  lcd.home();        
  
  lcd.clear(); 
 
  
     lcd.setRGB(colorR, colorG, colorB);
     
     lcd.setRGB(255,255,255);
}</p>

And lastly the main program in loop. The three lines just under the void loop define what kind of light you want to measure. Visible setting measures all the light you can see. Witch is a small area from the Electromagnetic spectrum, That is roughly between 380nm-700nm in wavelength at the spectrum.

Then there is fullspectrum witch means that you can measure visible light and infrared light at the same time. In the spectrum this means in wavelength between 380nm-1mm (1000nm)

And the infrared setting sees infrared light in wavelength between 700nm-1mm.

<p>void loop(void) {<br> 
  //uint16_t x = tsl.getLuminosity(TSL2561_VISIBLE);     
  uint16_t x = tsl.getLuminosity(TSL2561_FULLSPECTRUM);
  //uint16_t x = tsl.getLuminosity(TSL2561_INFRARED);
  
  Serial.println(x, DEC);</p><p>  uint32_t lum = tsl.getFullLuminosity();
  uint16_t ir, full;
  ir = lum >> 16;
  full = lum & 0xFFFF;</p><p>  lcd.setCursor(0,0);
  lcd.print("Vis:");
  lcd.setCursor(4,0);
  lcd.print(full-ir);
  
  lcd.setCursor(9,0);
  lcd.print("IR:");
  lcd.setCursor(12,0);
  lcd.print(ir);
   
  lcd.setCursor(0,1);
  lcd.print("Lux:");
  lcd.setCursor(4,1);
  lcd.print(tsl.calculateLux(full, ir));
  
  
  delay(500); 
  lcd.clear();
}</p>

Step 5: Testing the Sensor.

If it works well try it out a bit.

Find some remotes and flashlights and give it a go.

Lux can be calculated to lumen witch is the mostly used value when looking at light bulbs or flashlights or even video projectors.

Illuminance (lux): Illuminance is a measurement of the light intensity at any point. The light intensity drops exponentially the further away you get from the source (distance).

Luminous Flux (Lm): The luminous flux is a measure of the total light output from a source. For example, a 1 candela light source will product 1 lumen per square meter at the distance of 1 meter.

The calculator shows that if my lux reading is at direct light roughly 66623 and the distance was about 30cm. Viewangle was about 13 degrees since the lens to led ratio was in the farthest position. (one small beam of light).

The readings show that in Lumen my light is 242.18. If i remember correctly, the package of the flaslihght stated 250 Lm. so that is pretty accurate.

That's about it.

Thanks for reading!

If you like my projects be sure to follow me to get new projects first!

On a Budget Contest

Participated in the
On a Budget Contest

Explore Science Contest

Participated in the
Explore Science Contest