Example Code for Arduino-Read XYZ IR Data

This article guides you through the process of reading XYZ IR data using Arduino and the TCS3430 Tristimulus Color Sensor. It covers hardware and software preparation, wiring setup, and includes sample code to help you successfully read and display data. Follow the instructions to enhance your Arduino projects with precise color and infrared detection capabilities.

Hardware Preparation

  • DFRduino UNO R3 (or similar) x 1
  • Graivty: TCS3430 Tristimulus Color Sensor x1
  • Jumper wires

Software Preparation

Wiring Diagram

Connection Diagram

Other Preparation Work

Download and install the TCS3430 Library and Sample Code following the instructions in the Software Preparation section.

Sample Code

/*!
 * @file getXYZIRData.ino
 * @brief Detection of XYZ tristimulus and infrared data
 * @copyright  Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @licence     The MIT License (MIT)
 * @author [yangfeng]<[email protected]>
 * @version  V1.0
 * @date  2021-01-26
 * @get from https://www.dfrobot.com
 * @url  https://github.com/DFRobot/DFRobot_TCS3430
 */
#include <DFRobot_TCS3430.h>

DFRobot_TCS3430 TCS3430;
void setup() {
  Serial.begin(115200);

  while(!TCS3430.begin()){
    Serial.println("Please check that the IIC device is properly connected");
    delay(1000);
  }
}

void loop() {
  uint16_t XData = TCS3430.getXData();
  uint16_t YData = TCS3430.getYData();
  uint16_t ZData = TCS3430.getZData();
  uint16_t IR1Data = TCS3430.getIR1Data();
  uint16_t IR2Data = TCS3430.getIR2Data();
  String str = "X : " + String(XData) + "    Y : " + String(YData) + "    Z : " +  String(ZData) + "    IR1 : "+String(IR1Data) + "    IR2 : "+String(IR2Data);
  Serial.println(str);
  delay(1000);
}

Result

Result 1

Additional Information

Refer to the Reference section for the API Function List and more detailed product information.

Was this article helpful?

TOP