How to collect the data from multiple TSL2561 sensors in one arduino board??

Hi, I am now working on my final year project and I am messed up by the programming works :’(

I was able to collect the data from one sensor by using the following program which is copied from the forum.

#include<Wire.h>

// TSL2561 I2C address is 0x39(57)
#define Addr 0x39

void setup()
{
  // Initialise I2C communication as MASTER 
  Wire.begin();
  // Initialise serial communication, set baud rate = 9600
  Serial.begin(9600);

  // Starts I2C communication
  Wire.beginTransmission(Addr);
  // Select control register
  Wire.write(0x00 | 0x80);
  // Power ON mode
  Wire.write(0x03);
  // Stop I2C Transmission
  Wire.endTransmission();

  // Starts I2C communication
  Wire.beginTransmission(Addr);
  // Select timing register
  Wire.write(0x01 | 0x80);
  // Nominal integration time = 402ms
  Wire.write(0x02);
  // Stop I2C Transmission
  Wire.endTransmission();
  delay(300);
  
}

void loop()
{ 
  unsigned int data[4];
  for(int i = 0; i < 4; i++)
  {
    // Starts I2C communication
    Wire.beginTransmission(Addr);
    // Select data register
    Wire.write((140 + i));
    // Stop I2C Transmission
    Wire.endTransmission();
    
    // Request 1 byte of data
    Wire.requestFrom(Addr, 1);
    
    // Read 1 bytes of data
    if(Wire.available() == 1)
    {
      data[i] = Wire.read();
     }
     delay(100);
  }
  
  // Convert the data
  double ch0 = ((data[1] & 0xFF) * 256) + (data[0] & 0xFF);
  double ch1 = ((data[3] & 0xFF) * 256) + (data[2] & 0xFF);

  // Output data to serial monitor
  Serial.print("Full Spectrum(IR + Visible) :");
  Serial.println(ch0);
  Serial.print("Infrared Value :");
  Serial.println(ch1);
  Serial.print("Visible Value :");
  Serial.println(ch0-ch1);}

But in my project, I need to use 2 sensors to monitor the lux level in the room.
What changes required in the program so I can have the data in both sensors in one serial monitor?
I am totally new to the electronic field and it would be much appreciated if you guys can give me a little help :’(

According to this, that sensor has 3 selectable addresses.

So the first thing to do is to change the address on one of yours and run the i2c scanner to verify that you can see them both.

Then basically do what you're already doing but with Addr1 and Addr2 I'd surmise, along with more data variables say ch0-ch3?

andyhihi:
I am now working on my final year project

I am totally new to the electronic field

Just me being nosy but I'm curious why you chose an electronics project then. (Perhaps the actual topic is not the electronics, and the electronics is a means to your project end?)

In fact, if you look at the code in the adafruit link I gave, it seems easier to use multiple sensors if you use her library and then just create multiple instances ts1, ts2 or whatever.

(But I'd still use the scanner first to check they're visible.)

blomcrestlight:
Just me being nosy but I'm curious why you chose an electronics project then. (Perhaps the actual topic is not the electronics, and the electronics is a means to your project end?)

I am in Building Services major, my fyp topic is lighting control. I want to use the sensors to monitor the daylight level and to control the brightness of the LED lights (dimmer when more sunlight, vice versa).
So this is basically the starting point of my project. And I am also wondering if the arduino can do all the things that I have mentioned? (Adjust the brightness of the lights). Thank you.

Ok that makes sense.

I think the Arduino would in principle be able to adjust the lights, but exactly how I'm not able to say, I daresay others will. It would surely depend on voltages and currents and the types of lights (I'm no expert but I would think the electrical requirements of adjusting incandescents, fluorescents, leds etc differ?), not to mention the feasibility of getting at the mains wiring in the walls.