一、模块介绍
TCS34725是一款低成本颜色识别传感器模块。其工作原理是,通过照明LED发光,照射到被测物体后,返回光经过滤镜检测RGB的比例值,根据RGB的比例值识别出颜色。模块使用IIC接口,可以进行简单的7种颜色识别,不需要计算RGB值。
二、工作参数
三、原理图
四、引脚说明
说明:最少接线只需要使用Vin、GND、SCL、SDA即可。
四、示例程序(Arduino平台)
#include <Wire.h> #include "Adafruit_TCS34725.h" /* Example code for the Adafruit TCS34725 breakout library */ // TCS34725 ESP8266 // ================================= // LED GND(板载LED不亮) 或者 悬空(板载LED亮) // SCL D1 // SDA D2 // Vin 3.3V // GND GND /* Initialise with default values (int time = 2.4ms, gain = 1x) */ // Adafruit_TCS34725 tcs = Adafruit_TCS34725(); /* Initialise with specific int time and gain values */ Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_614MS, TCS34725_GAIN_1X); void setup(void) { Serial.begin(115200); if (tcs.begin()) { Serial.println("Found sensor"); } else { Serial.println("No TCS34725 found ... check your connections"); while (1); } // Now we're ready to get readings! } void loop(void) { uint16_t r, g, b, c, colorTemp, lux; tcs.getRawData(&r, &g, &b, &c); // colorTemp = tcs.calculateColorTemperature(r, g, b); colorTemp = tcs.calculateColorTemperature_dn40(r, g, b, c); lux = tcs.calculateLux(r, g, b); Serial.print("Color Temp: "); Serial.print(colorTemp, DEC); Serial.print(" K - "); Serial.print("Lux: "); Serial.print(lux, DEC); Serial.print(" - "); Serial.print("R: "); Serial.print(r, DEC); Serial.print(" "); Serial.print("G: "); Serial.print(g, DEC); Serial.print(" "); Serial.print("B: "); Serial.print(b, DEC); Serial.print(" "); Serial.print("C: "); Serial.print(c, DEC); Serial.print(" "); Serial.println(" "); }
注:程序需要安装Adafruit TCS34725支持库
上传程序后测试,在点亮LED场合,测试西瓜霜的黄色包装,测试结果:
红色和绿色的分量值比较高,蓝色的比较低,能匹配黄色的预期结果。