Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Light Sensor with TSL2561 and LED Indicator

View and Edit Project In Cirkit DesignerImage of Arduino UNO Light Sensor with TSL2561 and LED Indicator

Circuit Documentation

Summary

This circuit consists of an Arduino UNO microcontroller, a TSL2561 Lux Sensor, a red LED, and two resistors. The Arduino UNO is used to read data from the TSL2561 Lux Sensor and control the LED. The resistors are used to limit the current through the LED.

Component List

Arduino UNO

Resistor (200 Ohms)

TSL2561 Lux Sensor

Resistor (200 Ohms)

LED: Two Pin (red)

Wiring Details

Arduino UNO

Resistor (200 Ohms)

TSL2561 Lux Sensor

Resistor (200 Ohms)

LED: Two Pin (red)

Code Documentation

Arduino UNO Code

#include <SparkFunTSL2561.h>
#include <Wire.h>

// Create an SFE_TSL2561 object, here called "light":
SFE_TSL2561 light;

// Global variables:
boolean gain;     // Gain setting, 0 = X1, 1 = X16;
unsigned int ms;  // Integration ("shutter") time in milliseconds

void setup()
{
  // Initialize the Serial port:
  Serial.begin(9600);
  light.begin();

  // If gain = false (0), device is set to low gain (1X)
  // If gain = high (1), device is set to high gain (16X)
  gain = 1;

  // If time = 0, integration will be 13.7ms
  // If time = 1, integration will be 101ms
  // If time = 2, integration will be 402ms
  // If time = 3, use manual start / stop to perform your own integration
  unsigned char time = 2;

  // setTiming() will set the third parameter (ms) to the
  // requested integration time in ms (this will be useful later):
  light.setTiming(gain, time, ms);

  // To start taking measurements, power up the sensor:
  light.setPowerUp();
}

void loop()
{
  delay(ms);
  // Retrieve the data from the device:
  unsigned int visible, infrared;
  float vis, ir;
  
  if (light.getData(visible, infrared))
  {
    // getData() returned true, communication was successful
    Serial.print("Visible: ");
    Serial.print(visible);
    Serial.print(" Infrared: ");
    Serial.print(infrared);
    vis = float(visible);
    ir = float(infrared);
    Serial.print(" Ratio (Vis/IR): ");
    Serial.println(vis / ir);
  }
  else
  {
    // getData() returned false because of an I2C error, inform the user.
    byte error = light.getError();
    Serial.print("I2C error: ");
    Serial.println(error);
  }
}

This code initializes the TSL2561 Lux Sensor and reads the visible and infrared light levels. The data is then printed to the Serial Monitor. If there is an I2C error, it is also printed to the Serial Monitor.