(SKU:SEN0212)Color Sensor-TCS34725 颜色传感器
目录 |
简介
TCS34725是一款低成本,高性价比的RGB全彩颜色识别传感器,传感器通过光学感应来识别物体的表面颜色。支持红、绿、蓝(RGB)三基色,支持明光感应,可以输出对应的具体数值,帮助您还原颜色本真。
为了提高精度,防止周边环境干扰,我们特意在传感器底部添加了一块红外遮光片,最大程度减小了入射光的红外频谱成份,让颜色管理更加准确。板载自带四个高亮LED,可以让传感器在低环境光的情况下依然能够正常使用,实现“补光”的功能。模块采用I2C通信,拥有PH2.0和XH2.54(面包板)两种接口,用户可以根据自己的需求来选择接口,更加便利。
产品参数
- 工作电压:3.3-5V
- 工作电流:65uA
- 检测距离:3-10mm
- 时钟频率:0-400KHZ
- 接 口:IIC接口和2.54间距接口
- I2C地址:0x29
- 温度范围:-30℃ ~ +70℃
- 尺 寸:18.5 mm * 23 mm
- 重量:12 g
引脚说明
|
注意:
- 本模块的IIC地址是0x29
- 使用XH2.54(面包板兼容)接口时,需要自行焊接
- 底部红外遮光片上的一层保护纸可以撕下来
使用教程
将颜色传感器放在色卡10mm处,检测不同的颜色,RGB灯显示出与色卡相应的颜色。
准备
- 硬件
- UNO x1
- 颜色传感器 x1
- RGB灯模块 x1
- 4P传感器线 x1
- 软件
- Arduino IDE 版本1.6.8 点击下载Arduino IDE
接线图
将传感器放置于被测物体正面,间距控制在3~10mm之间。
样例代码
DFRobot_TCS34725 Arduino库(Github)。如何安装库?
/*! * @file colorview.ino * @brief DFRobot's Color Sensor * @n [Get the module here] * @n This example read current R,G,B,C value by the IIC bus * @n [Connection and Diagram](http://wiki.dfrobot.com.cn/index.php?title=(SKU:SEN0212)Color_Sensor-TCS34725_%E9%A2%9C%E8%89%B2%E4%BC%A0%E6%84%9F%E5%99%A8) * * @copyright [DFRobot](http://www.dfrobot.com), 2016 * @copyright GNU Lesser General Public License * * @author [carl](carl.xu@dfrobot.com) * @version V1.0 * @date 2016-07-12 */ #include <Wire.h> #include "DFRobot_TCS34725.h" // Pick analog outputs, for the UNO these three work well // use ~560 ohm resistor between Red & Blue, ~1K for green (its brighter) #define redpin 3 #define greenpin 5 #define bluepin 6 // for a common anode LED, connect the common pin to +5V // for common cathode, connect the common to ground // set to false if using a common cathode LED #define commonAnode true // our RGB -> eye-recognized gamma color byte gammatable[256]; DFRobot_TCS34725 tcs = DFRobot_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X); void setup() { Serial.begin(115200); Serial.println("Color View Test!"); if (tcs.begin()) { Serial.println("Found sensor"); } else { Serial.println("No TCS34725 found ... check your connections"); while (1); // halt! } // use these three pins to drive an LED pinMode(redpin, OUTPUT); pinMode(greenpin, OUTPUT); pinMode(bluepin, OUTPUT); // thanks PhilB for this gamma table! // it helps convert RGB colors to what humans see for (int i=0; i<256; i++) { float x = i; x /= 255; x = pow(x, 2.5); x *= 255; if (commonAnode) { gammatable[i] = 255 - x; } else { gammatable[i] = x; } //Serial.println(gammatable[i]); } } void loop() { uint16_t clear, red, green, blue; tcs.getRGBC(&red, &green, &blue, &clear); tcs.lock(); // turn off LED Serial.print("C:\t"); Serial.print(clear); Serial.print("\tR:\t"); Serial.print(red); Serial.print("\tG:\t"); Serial.print(green); Serial.print("\tB:\t"); Serial.print(blue); Serial.println("\t"); // Figure out some basic hex code for visualization uint32_t sum = clear; float r, g, b; r = red; r /= sum; g = green; g /= sum; b = blue; b /= sum; r *= 256; g *= 256; b *= 256; Serial.print("\t"); Serial.print((int)r, HEX); Serial.print((int)g, HEX); Serial.print((int)b, HEX); Serial.println(); //Serial.print((int)r ); Serial.print(" "); Serial.print((int)g);Serial.print(" "); Serial.println((int)b ); //Set the color lamp analogWrite(redpin, 255-gammatable[(int)r]); analogWrite(greenpin, 255-gammatable[(int)g]); analogWrite(bluepin, 255-gammatable[(int)b]); } |
Mind+(基于Scratch3.0)图形化编程
1、下载及安装软件。下载地址:http://www.mindplus.cc 详细教程:Mind+基础wiki教程-软件下载安装
2、切换到“上传模式”。 详细教程:Mind+基础wiki教程-上传模式编程流程
3、“扩展”中选择“主控板”中的“Arduino Uno”或者“microbit”等其他支持的主控板,“传感器”中加载“颜色识别传感器”。 详细教程:Mind+基础wiki教程-加载扩展库流程
4、进行编程,程序如下图:
5、菜单“连接设备”,“上传到设备”
6、程序上传完毕后,打开串口即可看到数据输出。详细教程:Mind+基础wiki教程-串口打印
程序下载:点击下载
结果
红色R的值高于蓝色B和绿色G,RGB灯的的颜色偏红色。
常见问题
还没有客户对此产品有任何问题,欢迎通过qq或者论坛联系我们!
更多问题及有趣的应用,可以 访问论坛 进行查阅或发帖! |