
โมดูลวัดค่าสี RGB Colour Sensor (TCS230/TCS3200) เซนเซอร์แยกสี ใช้แยกว่าสีที่อยู่หน้าเซนเซอร์นี้เป็นสีอะไร เอาต์พุตที่อ่านได้ ออกมาเป็นค่า R G B ใช้งานง่าย มีไฟ Flash สำหรับตรวจจับสีวัตถุในที่มืด สามารถสั่งควบคุมเปิดปิดไฟได้จากในโคดโปรแกรม พื้นหลังเป็นสีขาวมีกระบอกพลาสติกสีดำ กันไม่ให้สีอื่นไปรบกวน ไม่ต้องหาต่อที่กั้นแสงเพิ่ม
s0 -> 3
s1 -> 4
s2 -> 5
s3 -> 6
LED -> 7
out -> 8
Vcc -> 5V
Gnd -> Gnd*/
s1 -> 4
s2 -> 5
s3 -> 6
LED -> 7
out -> 8
Vcc -> 5V
Gnd -> Gnd*/
const int outputEnabled = 2; // write LOW to turn on Note, may not be hooked up. const int s0 = 3; // sensor pins const int s1 = 4; const int s2 = 5; const int s3 = 6; const int nLED = 7; // illuminating LED const int out = 8; // TCS230 output // variables to store color values int red = 0; int green = 0; int blue = 0; void setup() { pinMode(outputEnabled, OUTPUT); pinMode(s0, OUTPUT); pinMode(s1, OUTPUT); pinMode(s2, OUTPUT); pinMode(s3, OUTPUT); pinMode(nLED, OUTPUT); pinMode(out, INPUT); Serial.begin(9600); //This pin may be set to ground and not available on the breakout //If not available don't worry about it. digitalWrite(outputEnabled, LOW); //Set Frequency scaling to largest value digitalWrite(s0, HIGH); digitalWrite(s1, HIGH); digitalWrite(nLED, LOW); } void loop() { color(); Serial.print("R"); Serial.print(red, DEC); Serial.print(" G"); Serial.print(green, DEC); Serial.print(" B"); Serial.print(blue, DEC); Serial.println(); //Simple logic to test for color if (red < blue && red < green) Serial.println("Red"); else if (blue < red && blue < green) Serial.println("blue"); else Serial.println("green"); delay(1000); } void color() { digitalWrite(nLED,1); 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); digitalWrite(nLED,0); }

https://www.arduinoall.com/product/155/%E0%B9%82%E0%B8%A1%E0%B8%94%E0%B8%B9%E0%B8%A5-%E0%B8%A7%E0%B8%B1%E0%B8%94%E0%B8%84%E0%B9%88%E0%B8%B2%E0%B8%AA%E0%B8%B5-%E0%B8%AD%E0%B9%88%E0%B8%B2%E0%B8%99%E0%B8%84%E0%B9%88%E0%B8%B2%E0%B8%AA%E0%B8%B5-%E0%B9%80%E0%B8%8B%E0%B8%99%E0%B9%80%E0%B8%8B%E0%B8%AD%E0%B8%A3%E0%B9%8C%E0%B8%AA%E0%B8%B5-rgb-colour-sensor-tcs230-tcs3200-%E0%B8%AA%E0%B8%B3%E0%B8%AB%E0%B8%A3%E0%B8%B1%E0%B8%9A-arduino-2
ความคิดเห็น
แสดงความคิดเห็น