Arduino TCS34725 颜色传感器
相关资料链接获取
1.1 介绍:
本模块主要用到TCS34725 颜色传感器,TCS34725是一款低成本,高性价比的RGB全彩颜色识别传感器,传感器通过光学感应来识别物体的表面颜色。支持红、绿、蓝(RGB)三基色,支持明光感应,可以输出对应的具体数值,帮助您还原颜色本真。色敏光电二极管集成片裁和局部化的红外遮光滤光片,最大程度减小了入射光的红外频谱成份,让颜色管理更加准确。 高敏感性、宽动态范围以及红外遮光滤光片使得 TCS34725 成为光线条件变化和通过衰减材料条件下的理想色敏元件解决方案。TCS34725 彩色传感器有着广泛的应用,包括 RGB LED 背光控制,固态照明、 健康产品、 工业过程控制和医疗诊断设备等。
1.2 模块相关资料:
工作电压: |
5V(DC) |
|
工作电流: |
100mA |
|
最大功率: |
0.5W |
|
工作温度: |
-10℃~+50℃ |
|
通信协议: |
IIC(地址:0x29) |
|
检测距离: |
3-10mm |
|
时钟频率: |
0-400KHZ |
|
尺寸: |
31.6mmx23.7mm |
|
原理:
|
1.3 实验组件:
|
|
|
|
控制板* 1 |
USB线*1 |
TCS34725 颜色传感器*1 |
5P 转杜邦线母*1 |
1.4模块接线图:
1.5 实验代码:
/* TCS34725颜色识别传感器 */
#include <Wire.h> #include "Adafruit_TCS34725.h" /* Example code for the Adafruit TCS34725 breakout library */
/* Connect SCL to analog 5 Connect SDA to analog 4 Connect VDD to 3.3V DC Connect GROUND to common ground */
/* 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_700MS, TCS34725_GAIN_1X);
void setup(void) { Serial.begin(9600);
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); 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(" "); }
|
程序编译前需要导入库文件,否则编译不通过,具体操作参考
资料的第四小节:库文件的添加(若前面已添加,无需重复)
1.6测试结果
按照接线图,接好线,上传好代码,上电后,打开串口监视器,设置波特率为9600,就可以看到你检测的物体的颜色(白色)数据,如下图。