Home LCD Projects TSL2561 based lux meter

TSL2561 based lux meter

by shedboy71

Another project – this time were building another lux meter, we will use a TSL2561 sensor and display the readings on an LCD keypad shield

Lets recap some information regarding the sensor

This TSL2561 is an I2C light-to-digital converter TSL2561 that transforms light intensity to a digital signal. The TSL2561 features a selectable light spectrum range due to its dual light sensitive diodes: infrared and full spectrum. You can switch among three detection modes to take your readings. They are infrared mode, full spectrum and human visible mode.

When running under the human visible mode, this sensor will give you readings just close to your eye feelings.

Features

Selectable detection modes
High resolution 16-Bit digital output at 400 kHz I2C Fast-Mode
Wide dynamic range: 0.1 – 40,000 LUX
Wide operating temperature range: -40°C to 85°C
Programmable interrupt function with User-Defined Upper and lower threshold settings

Here is a typical module that makes it easier to work with the sensor

 

Parts List

Description Product links
Arduino Uno 1pcs UNO R3 CH340G+MEGA328P for Arduino UNO R3 (NO USB CABLE)
LCD Keypad shield 1PCS LCD Keypad Shield LCD 1602 Module Display For Arduino
TSL2561 module 1pcs GY-2561 TSL2561 Luminosity Sensor Breakout infrared Light Sensor module
Connecting wire 40pcs Dupont jumper wire cable 30cm male to male,female to female,male to female Dupont jump wire line 2.54mm breadboard cable

Connection

lcd keypad and tsl2561

lcd keypad and tsl2561

 

Code

You need to install the Adafruit TSL2561 and unified sensor libraries in the Arduino library manager

[codesyntax lang=”cpp”]

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>
#include <LiquidCrystal.h>

//setup for the LCD keypad shield
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);

void setup() 
{
  //init serial for some debug
  Serial.begin(9600);
  Serial.println("Light Sensor Test"); 
  Serial.println("");
  // setup sensor and configure
  if(!tsl.begin())
  {
    Serial.print("no TSL2561 detected!");
    while(1);
  }
  
  configureSensor();
  //init LCD
  delay(1000);
  lcd.begin(16,2);
  //line 1 - temperature
  lcd.setCursor(0,0);
  lcd.print("Lux: ");
}

void loop() 
{
  // put your main code here, to run repeatedly:
  delay(1000);
  /* Get a new sensor event */ 
  sensors_event_t event;
  tsl.getEvent(&event);
  lcd.setCursor(7,0);
  /* Display the results (light is measured in lux) */
  if (event.light)
  {
    Serial.print(event.light); 
    lcd.print(event.light);
  }
  else
  {
    Serial.println("Sensor overload");
  }
  delay(500);
}

   
void configureSensor(void)
{
  tsl.enableAutoRange(true);            /* Auto-gain ... switches automatically between 1x and 16x */
  tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);      /* fast but low resolution */
}

[/codesyntax]

Link

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More