Example Code for Arduino-I2C Data Reading

Last revision 2025/12/19

Read color temperature, illuminance, and xy color coordinates data from the sensor using I2C communication. Users can learn how to connect the sensor to Arduino via I2C and use the DFRobot_ColorTemperature library to retrieve data.

Hardware Preparation

  • DFRduino UNO Controller x1
  • SEN0611 Gravity: Color Temperature Illuminance Sensor x1

Software Preparation

Wiring Diagram

Other Preparation Work

  • Connect the module to the UNO controller according to the above wiring diagram, of course, you can also use the expansion board, which can be more convenient and faster to complete the project prototype.
  • Switch the selector switch on the sensor to the I2C side.
  • Download and install DFRobot_ColorTemperature library. How to Install Library?
  • Note: Power off when switching the switch

Sample Code

#include "DFRobot_ColorTemperature.h"
DFRobot_ColorTemperature CT(&Wire);

void setup()
{
  Serial.begin(115200);
  while(CT.begin() != 0){
    Serial.println(" Sensor initialize failed!!");
    delay(1000);
  }
  Serial.println(" Sensor  initialize success!!");
}

void loop()
{
  Serial.println("-------------------------------");
  Serial.print("LUX: ");
  Serial.println(CT.readLUX());
  Serial.print("CCT: ");
  Serial.println(CT.readCCT());
  Serial.print("X: ");
  Serial.println(CT.readX());
  Serial.print("Y: ");
  Serial.println(CT.readY());
  Serial.println("-------------------------------");
  delay(500);
}

Result

Open the serial monitor of Arduino IDE, adjust the baud rate to 115200, and observe the serial print result to obtain the final color temperature, illuminance, and X, Y color coordinates data.

Additional Information

  • Ensure the sensor is connected correctly and the I2C mode is selected.
  • Power off before switching the communication mode switch.

Was this article helpful?

TOP