Skip to content

Instantly share code, notes, and snippets.

@Ajak58a
Created January 11, 2024 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ajak58a/28d8dc91f401c9415219bb1541b4f417 to your computer and use it in GitHub Desktop.
Save Ajak58a/28d8dc91f401c9415219bb1541b4f417 to your computer and use it in GitHub Desktop.
TCS230/TCS3200 color-recognition sensor with Arduino
// TCS230 or TCS3200 pins wiring to Arduino
#define S0 13
#define S1 12
#define S2 11
#define S3 10
#define sensorOut 9
// Stores frequency read by the photodiodes
int R = 0;
int G = 0;
int B = 0;
void setup() {
// Setting the outputs
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
// Setting the sensorOut as an input
pinMode(sensorOut, INPUT);
// Setting frequency scaling to 20%
digitalWrite(S0,HIGH);
digitalWrite(S1,LOW);
// Begins serial communication
Serial.begin(9600);
}
void loop() {
// Setting RED (R) filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
delay(100);
// Reading the output frequency
R = pulseIn(sensorOut, LOW);
R = map(R, 27, 66, 255, 0);
// Printing the RED (R) value
Serial.print("R = ");
Serial.print(R);
delay(100);
// Setting GREEN (G) filtered photodiodes to be read
digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);
delay(100);
// Reading the output frequency
G = pulseIn(sensorOut, LOW);
G = map(G, 43,66,255,0);;
// Printing the GREEN (G) value
Serial.print(" G = ");
Serial.print(G);
delay(100);
// Setting BLUE (B) filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,HIGH);
delay(100);
// Reading the output frequency
B = pulseIn(sensorOut, LOW);
B = map(B, 31,56,255,0);;
// Printing the BLUE (B) value
Serial.print(" B = ");
Serial.println(B);
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment