Our color sensor TCS230 (without library)

Today's blog post we want to use to TCS Color Sensor Module Introduce. The function is quickly explained, in the middle of the board there is a photo sensor with 64 diodes or pixels, 16 of them without filters and 16 each with red, blue or green color filters. The 4 5mm leds are used to illuminate the object to be scanned as evenly and neutrally as possible. Practical tip: for measurement, you should avoid ambient light or stray light as this can distort the results. Depending on the application, it is sometimes helpful to shield the photo sensor with a small tube to obtain constant values.

The output of the IC is a rectangle signal proportional to the respective wavelength. S0 and S1 scale the frequency of the output signal, S2 and S3 are used to query the R/ B/ G and W values.OE switches the module on or off (enable active low)

The wiring:

The code: 

Const Int s0 = 8; Pins
Const Int s1 = 9;
Const Int s2 = 12;
Const Int s3 = 11;
Const Int Out = 10;

Int Red = 0; Var
Int Green = 0;
Int Blue = 0;

Void Setup()



pinMode(s0, Output); 

pinMode(s1, Output);

pinMode(s2, Output);

pinMode(s3, Output);

pinMode(Out, Input);

digitalWrite(s0, High); set mode

digitalWrite(s1, High);


Void Loop()



Serial.Print("red = ");

Serial.Print(Red, DEC);

Serial.Print(" green = ");

Serial.Print(Green, DEC);

Serial.Print(" blue = ");

Serial.Print(Blue, DEC);

If (Red < Blue && Red < Green && Red < 20) red filter
Serial.println(" - (red color detected)");
else If (Blue < Red && Blue < Green) blue filter
Serial.println(" - (blue color detected)");
else If (Green < Red && Green < Blue) green filter
Serial.println(" - (green color detected)");

Void Color()


digitalWrite(s2, Low);

digitalWrite(s3, Low);

Red = pulseIn(Out, digitalRead(Out) == High ? Low : High);

digitalWrite(s3, High);

Blue = pulseIn(Out, digitalRead(Out) == High ? Low : High);

digitalWrite(s2, High);

Green = pulseIn(Out, digitalRead(Out) == High ? Low : High);


Depending on where the module is installed, it may be necessary to adjust the color filter.

This means that nothing stands in the way of your M&Ms sorting machine :-)
By the way, we also Servos & Stepper motor driver





Hallo, ich arbeite im Druckgewerbe. Dort ist der Einsatz von so genannten Spektralphotometern an der Tagesordnung. Nachteil: Die Finger sind richtig teuer und verschleißen mit der Zeit. Gibt der verwendete Chip eine exakte Messung her? Oder wie konstant misst er?
Ich denke, daraus kann man was machen.



Also so eine M&M Sortiermaschine wäre schon ein Cooles Projekt :)

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN