Introduction
This experiment demonstrates how to use the TSL2561 light sensor with Arduino to measure light intensity.
Components Needed
- TSL2561 Light Sensor
- Arduino (e.g., Uno, Nano)
- Jumper wires
Circuit Setup
- Connect the TSL2561 sensor to the Arduino using the I2C pins (SDA, SCL).
- Connect the sensor's VCC and GND pins to the Arduino's 5V and GND pins, respectively.
This setup allows the Arduino to communicate with the sensor over I2C.
Code for Light Intensity Measurement
Upload the following code to your Arduino to read light intensity values:
#include
#include
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, &Wire);
void setup() {
Serial.begin(9600);
if (!tsl.begin()) {
Serial.println("Couldn't find TSL2561 sensor");
while (1);
}
tsl.setGain(TSL2561_GAIN_16X); // Set the gain for the sensor
}
void loop() {
sensors_event_t event;
tsl.getEvent(&event);
if (event.light) {
Serial.print("Light Intensity: ");
Serial.print(event.light);
Serial.println(" lux");
} else {
Serial.println("No light detected");
}
delay(500);
}
Explanation
The code reads the light intensity from the TSL2561 sensor and displays the value in lux on the Serial Monitor.
Troubleshooting
- If the sensor is unresponsive, check the I2C connections and ensure the sensor is powered correctly.
- If the readings are not correct, try adjusting the sensor's gain setting in the code.