공개: 이 포스팅 에 제공된 일부 링크는 아마존 제휴 링크입니다. 이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.
TCS3200D/TCS230 컬러 센서에 대하여
8×8 포토다이오드 배열을 기반으로 한 TCS3200D/TCS230은 특수 광학 필터링을 통해 색상을 식별합니다. 64개의 다이오드 격자에는 빨간색 필터 포토다이오드 16개, 녹색 필터 16개, 파란색 필터 센서 16개, 필터 없음(투명) 포토다이오드 16개가 포함됩니다. 색상 감지는 필터 유형을 전환하고 빛의 강도를 나타내는 구형파 주파수 출력을 분석하여 이루어집니다.
대부분의 모듈에 내장된 흰색 LED는 일관된 대상 조명을 제공하여 다양한 주변 조건에서 안정적인 측정을 보장하고 저조도 성능을 향상시킵니다.
핀아웃
TCS3200D/TCS230 모듈의 연결 핀:
VCC 핀: 전원 공급 연결(+5V).
GND 핀: 접지 연결(0V).
S0, S1 핀: 주파수 스케일링 제어 입력.
S2, S3 핀: 색상 필터 선택 입력.
OUT 핀: 주파수 출력(구형파).
OE 핀: 출력 활성화 제어(LOW일 때 활성). 대부분의 상용 모듈은 이 핀을 내부적으로 접지시켜 외부 배선을 생략합니다. 미리 연결되어 있지 않은 경우 GND에 수동으로 연결합니다.
작동 원리
센서를 작동하려면 두 가지 핵심 매개변수를 구성해야 합니다: 활성 색상 채널과 신호 강도. 제어 핀 쌍이 이 설정을 관리합니다:
S0과 S1을 통한 출력 스케일링:
둘 다 LOW: 전원 끄기 모드
S0 LOW, S1 HIGH: 2% 주파수 스케일링
S0 HIGH, S1 LOW: 20% 주파수 스케일링
둘 다 HIGH: 전체 100% 스케일링
S2와 S3을 통한 필터 선택:
둘 다 LOW: 빨간색 채널 활성
S2 LOW, S3 HIGH: 파란색 채널 활성
S2 HIGH, S3 LOW: 투명 채널(필터 없음)
둘 다 HIGH: 녹색 채널 활성
OUT 핀은 약 2Hz에서 500kHz 범위의 구형파 신호를 생성합니다. 주파수가 높을수록 선택된 채널의 빛 강도가 강합니다. pulseIn()으로 펄스 폭을 측정하면 역 관계를 얻습니다 — 펄스가 짧을수록 색상이 밝습니다. 보정 후 변환하면 표준 RGB 값을 얻을 수 있습니다.
환경 보정은 원시 센서 출력이 여러 요소(온보드 LED 강도, 대상 거리, 표면 반사 특성, 주변 조명)에 따라 달라지기 때문에 필수적입니다. 이러한 변수를 측정 간섭으로 생각할 수 있습니다. 보정은 각 색상 채널의 최소 및 최대 경계를 설정하여 이 간섭을 정량화하고, 특정 설정에 맞는 표준 0~255 RGB 스케일로 정확한 변환을 가능하게 합니다.
/* * 이 아두이노 코드는 newbiely.kr 에서 개발되었습니다 * 이 아두이노 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino/arduino-tcs3200d-tcs230-color-sensor */// Define color sensor pins#define PIN_S0 4#define PIN_S1 3#define PIN_S2 6#define PIN_S3 5#define PIN_sensorOut 7// Variables for Color Pulse Width Measurementsint redPW = 0;int greenPW = 0;int bluePW = 0;// Variables to track min and max pulse widths for calibrationint redMin = 10000, redMax = 0;int greenMin = 10000, greenMax = 0;int blueMin = 10000, blueMax = 0;voidsetup() {// Set S0 - S3 as outputspinMode(PIN_S0, OUTPUT);pinMode(PIN_S1, OUTPUT);pinMode(PIN_S2, OUTPUT);pinMode(PIN_S3, OUTPUT);// Set Pulse Width scaling to 20%digitalWrite(PIN_S0, HIGH);digitalWrite(PIN_S1, LOW);// Set Sensor output as inputpinMode(PIN_sensorOut, INPUT);// Setup Serial MonitorSerial.begin(9600);Serial.println("=== TCS3200 Calibration ===");Serial.println("Point the sensor at different objects (white, black, colors).");Serial.println("Min and Max values are tracked automatically.");Serial.println("When values look stable, note them down for the next code.");Serial.println("------------------------------------------");}voidloop() {// Read Red Pulse Width redPW = getRedPW();// Delay to stabilize sensordelay(200);// Read Green Pulse Width greenPW = getGreenPW();// Delay to stabilize sensordelay(200);// Read Blue Pulse Width bluePW = getBluePW();// Delay to stabilize sensordelay(200);// Update min and max valuesif (redPW < redMin) redMin = redPW;if (redPW > redMax) redMax = redPW;if (greenPW < greenMin) greenMin = greenPW;if (greenPW > greenMax) greenMax = greenPW;if (bluePW < blueMin) blueMin = bluePW;if (bluePW > blueMax) blueMax = bluePW;// Print the pulse width values with min/maxSerial.print("Red PW = ");Serial.print(redPW);Serial.print(" - Green PW = ");Serial.print(greenPW);Serial.print(" - Blue PW = ");Serial.println(bluePW);Serial.print(" Min -> R:");Serial.print(redMin);Serial.print(" G:");Serial.print(greenMin);Serial.print(" B:");Serial.println(blueMin);Serial.print(" Max -> R:");Serial.print(redMax);Serial.print(" G:");Serial.print(greenMax);Serial.print(" B:");Serial.println(blueMax);Serial.println("------------------------------------------");delay(1000);}// Function to read Red Pulse Widthsint getRedPW() {// Set sensor to read Red onlydigitalWrite(PIN_S2, LOW);digitalWrite(PIN_S3, LOW);// Read the Pulse Widthint PW = pulseIn(PIN_sensorOut, LOW);// Return the valuereturn PW;}// Function to read Green Pulse Widthsint getGreenPW() {// Set sensor to read Green onlydigitalWrite(PIN_S2, HIGH);digitalWrite(PIN_S3, HIGH);// Read the Pulse Widthint PW = pulseIn(PIN_sensorOut, LOW);// Return the valuereturn PW;}// Function to read Blue Pulse Widthsint getBluePW() {// Set sensor to read Blue onlydigitalWrite(PIN_S2, LOW);digitalWrite(PIN_S3, HIGH);// Read the Pulse Widthint PW = pulseIn(PIN_sensorOut, LOW);// Return the valuereturn PW;}
빠른 단계
Arduino IDE에서 보정 코드를 엽니다
Upload 버튼을 사용하여 Arduino 보드에 업로드합니다
시리얼 모니터를 열어 Min/Max 추적이 포함된 실시간 판독값을 확인합니다
센서로 다양한 물체를 스캔합니다: 흰색 표면(종이), 검은색 물체, 다양한 색상 물체
극값이 기록되면서 자동으로 Min/Max 값이 업데이트되는 것을 관찰합니다
숫자가 안정화되면(일반적으로 10~20초), 여섯 가지 보정 상수를 모두 기록합니다
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno
Newbiely.ino
···
8Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno' on 'COM15')
New Line
9600 baud
=== TCS3200 Calibration ===
Point the sensor at different objects (white, black, colors).
Min and Max values are tracked automatically.
When values look stable, note them down for the next code.
------------------------------------------
Red PW = 42 - Green PW = 55 - Blue PW = 60
Min -> R:42 G:55 B:60
Max -> R:42 G:55 B:60
------------------------------------------
Red PW = 210 - Green PW = 185 - Blue PW = 172
Min -> R:42 G:55 B:60
Max -> R:210 G:185 B:172
------------------------------------------
Red PW = 44 - Green PW = 57 - Blue PW = 61
Min -> R:42 G:55 B:60
Max -> R:210 G:185 B:172
------------------------------------------
Ln 11, Col 1
Arduino Uno on COM15
2
예를 들어 위의 출력에서 보정 값은 다음과 같습니다:
RedMin = 42, redMax = 210
GreenMin = 55, greenMax = 185
BlueMin = 60, blueMax = 172
Arduino 코드 - RGB 색상 값 읽기
/* * 이 아두이노 코드는 newbiely.kr 에서 개발되었습니다 * 이 아두이노 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino/arduino-tcs3200d-tcs230-color-sensor */// Define color sensor pins#define PIN_S0 4#define PIN_S1 3#define PIN_S2 6#define PIN_S3 5#define PIN_sensorOut 7// Calibration Values// Replace these values with your actual calibration data from the previous stepint redMin = 0; // Red minimum pulse widthint redMax = 0; // Red maximum pulse widthint greenMin = 0; // Green minimum pulse widthint greenMax = 0; // Green maximum pulse widthint blueMin = 0; // Blue minimum pulse widthint blueMax = 0; // Blue maximum pulse width// Variables for Color Pulse Width Measurementsint redPW = 0;int greenPW = 0;int bluePW = 0;// Variables for final Color valuesint redValue;int greenValue;int blueValue;voidsetup() {// Set S0 - S3 as outputspinMode(PIN_S0, OUTPUT);pinMode(PIN_S1, OUTPUT);pinMode(PIN_S2, OUTPUT);pinMode(PIN_S3, OUTPUT);// Set Pulse Width scaling to 20%digitalWrite(PIN_S0, HIGH);digitalWrite(PIN_S1, LOW);// Set Sensor output as inputpinMode(PIN_sensorOut, INPUT);// Setup Serial MonitorSerial.begin(9600);}voidloop() {// Read Red value redPW = getRedPW();// Map to value from 0-255 redValue = map(redPW, redMin, redMax, 255, 0);// Delay to stabilize sensordelay(200);// Read Green value greenPW = getGreenPW();// Map to value from 0-255 greenValue = map(greenPW, greenMin, greenMax, 255, 0);// Delay to stabilize sensordelay(200);// Read Blue value bluePW = getBluePW();// Map to value from 0-255 blueValue = map(bluePW, blueMin, blueMax, 255, 0);// Delay to stabilize sensordelay(200);// Print output to Serial MonitorSerial.print("Red = ");Serial.print(redValue);Serial.print(" - Green = ");Serial.print(greenValue);Serial.print(" - Blue = ");Serial.println(blueValue);}// Function to read Red Pulse Widthsint getRedPW() {// Set sensor to read Red onlydigitalWrite(PIN_S2, LOW);digitalWrite(PIN_S3, LOW);// Read the Pulse Widthint PW = pulseIn(PIN_sensorOut, LOW);// Return the valuereturn PW;}// Function to read Green Pulse Widthsint getGreenPW() {// Set sensor to read Green onlydigitalWrite(PIN_S2, HIGH);digitalWrite(PIN_S3, HIGH);// Read the Pulse Widthint PW = pulseIn(PIN_sensorOut, LOW);// Return the valuereturn PW;}// Function to read Blue Pulse Widthsint getBluePW() {// Set sensor to read Blue onlydigitalWrite(PIN_S2, LOW);digitalWrite(PIN_S3, HIGH);// Read the Pulse Widthint PW = pulseIn(PIN_sensorOut, LOW);// Return the valuereturn PW;}
빠른 단계
코드 시작 부분 근처에서 보정 변수 선언을 찾습니다:
int redMin = 0; // Red minimum pulse widthint redMax = 0; // Red maximum pulse widthint greenMin = 0; // Green minimum pulse widthint greenMax = 0; // Green maximum pulse widthint blueMin = 0; // Blue minimum pulse widthint blueMax = 0; // Blue maximum pulse width
이전 연습의 보정 데이터를 사용하여 여섯 개의 0 값을 모두 업데이트합니다. 변환 예시(보정 결과 redMin = 42, redMax = 210, greenMin = 55, greenMax = 185, blueMin = 60, blueMax = 172 사용):