- TCS230 颜色传感器模块基本介绍
- 板载TCS3200颜色传感器.
- 支持3V-5V电压输入
- 芯片的引脚全部已经引出,插针为标准100mil(2.54mm),方便用于点阵板
- PCB尺寸:31.6(mm)x24.4(mm)
- Arduino驱动TCS230 颜色传感器模块 程序代码 (可双击代码全选程序内容)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
/* Arduino Uno TCS230 Color Recongnition Sensor V 1.0 Created 2014 by 太极创客 http://www.taichi-maker.com 使用Arduino Uno R3驱动TCS230 颜色识别传感器模块。 程序运行后,传感器将识别的颜色RGB信息反馈给Arduino. Arduino将通过红,蓝,绿三个LED显示所识别到的颜色。 Arduino连接设置 TCS230 Arduino ----------- -------- VCC 5V GND GND s0 8 s1 9 s2 12 s3 11 OUT 10 OE GND 红色Led 连接到Arduino D2引脚 蓝色Led 连接到Arduino D3引脚 绿色Led 连接到Arduino D4引脚 获得TCS230颜色识别传感器模块和Arduino的更多信息 请参阅太极创客网站:http://www.taichi-maker.com */ //TCS230连接设置 const int s0 = 8; const int s1 = 9; const int s2 = 12; const int s3 = 11; const int out = 10; // LED连接设置 int redLed = 2; int greenLed = 3; int blueLed = 4; // Variables int red = 0; int green = 0; int blue = 0; void setup() { Serial.begin(9600); pinMode(s0, OUTPUT); pinMode(s1, OUTPUT); pinMode(s2, OUTPUT); pinMode(s3, OUTPUT); pinMode(out, INPUT); pinMode(redLed, OUTPUT); pinMode(greenLed, OUTPUT); pinMode(blueLed, OUTPUT); digitalWrite(s0, HIGH); digitalWrite(s1, HIGH); } void loop() { color(); Serial.print("R Intensity:"); Serial.print(red, DEC); Serial.print(" G Intensity: "); Serial.print(green, DEC); Serial.print(" B Intensity : "); Serial.print(blue, DEC); //Serial.println(); if (red < blue && red < green && red < 20) { Serial.println(" - (Red Color)"); digitalWrite(redLed, HIGH); //点亮红色LED digitalWrite(greenLed, LOW); digitalWrite(blueLed, LOW); } else if (blue < red && blue < green) { Serial.println(" - (Blue Color)"); digitalWrite(redLed, LOW); digitalWrite(greenLed, LOW); digitalWrite(blueLed, HIGH); // 点亮蓝色LED } else if (green < red && green < blue) { Serial.println(" - (Green Color)"); digitalWrite(redLed, LOW); digitalWrite(greenLed, HIGH); // 点亮绿色LED digitalWrite(blueLed, LOW); } else{ Serial.println(); } delay(300); digitalWrite(redLed, LOW); digitalWrite(greenLed, LOW); digitalWrite(blueLed, LOW); } void color() { digitalWrite(s2, LOW); digitalWrite(s3, LOW); //count OUT, pRed, RED red = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH); digitalWrite(s3, HIGH); //count OUT, pBLUE, BLUE blue = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH); digitalWrite(s2, HIGH); //count OUT, pGreen, GREEN green = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH); } |