Color Recognition Sensor Module TCS3200

Color Recognition Sensor Module TCS3200

分类: Sensor Modules 当前有货
可在官方网站购买
欲了解更多详情,请游览我们的官方网站 jselectronics.com.my

详情

The TCS230 is a color light-to-frequency converter on single CMOS integrated circuit. The output is a square wave(50% duty cycle) with frequency directly proportional to light intensity (irradiance). The full-scale output frequency can be scaled by one of three preset values via two control input pins. Output enable (OE) places the output in the high-impedance state for multiple-unit sharing of a microcontroller input.


Library example code includes:

Features:


Item size: 31*23*10mm
Net weight: 5g





How TCS230 Color Sensor Works


The TCS230 senses color light with the help of an 8 x 8 array of photodiodes. Then using a Current-to-Frequency Converter the readings from the photodiodes are converted into a square wave with a frequency directly proportional to the light intensity. Finally, using the Arduino Board we can read the square wave output and get the results for the color.

 

TCS230 TCS3200 Color Sensor Working Principle

If we take a closer look at the sensor we can see how it detects various colors. The photodiodes have three different color filters. Sixteen of them have red filters, another 16 have green filters, another 16 have blue filters and the other 16 photodiodes are clear with no filters.

TCS230 TCS3200 Color Sensor Photodiodes Filters How It Works

Each 16 photodiodes are connected in parallel, so using the two control pins S2 and S3 we can select which of them will be read. So for example, if we want to detect red color, we can just use the 16 red filtered photodiodes by setting the two pins to low logic level according to the table.

TCS230 Color Sensor Frequency Scaling Photodiode Type Table

The sensor has two more control pins, S0 and S1 which are used for scaling the output frequency. The frequency can be scaled to three different preset values of 100 %, 20 % or 2%. This frequency-scaling function allows the output of the sensor to be optimized for various frequency counters or microcontrollers.

Now we are ready to move on and connect the TCS230 sensor to the Arduino board. Here’s the circuit schematics.

Arduino Color Sensing Tutorial TSC230 TSC3200 Color Sensor Circuit Schematics

You can get the components needed for this Arduino tutorial from the links below:

*Please note: These are affiliate links. I may make a commission if you buy the components through these links.
I would appreciate your support in this way!

TCS230 Color Sensor Source Code


Description: First we need to define the pins to which the sensor is connected and define a variable for reading the frequency. In the setup section we need to define the four control pins as outputs and the sensor output as an Arduino input. Here we also need to set the frequency-scaling, for this example I will set it to 20%, and start the serial communication for displaying the results in the Serial Monitor.

In the loop section, we will start with reading the red filtered photodiodes. For that purpose we will set the two control pins S2 and S3 to low logic level. Then using the “pulseIn()” function we will read the output frequency and put it into the variable “frequency”. Using the Serial.print() function we will print the result on the serial monitor. The same procedure goes for the two other colors, we just need to adjust the control pins for the appropriate color.

  1. /* Arduino Color Sensing Tutorial
  2. *
  3. * by Dejan Nedelkovski, www.HowToMechatronics.com
  4. *
  5. */
  6.  
  7. #define S0 4
  8. #define S1 5
  9. #define S2 6
  10. #define S3 7
  11. #define sensorOut 8
  12.  
  13. int frequency = 0;
  14.  
  15. void setup() {
  16. pinMode(S0, OUTPUT);
  17. pinMode(S1, OUTPUT);
  18. pinMode(S2, OUTPUT);
  19. pinMode(S3, OUTPUT);
  20. pinMode(sensorOut, INPUT);
  21.  
  22. // Setting frequency-scaling to 20%
  23. digitalWrite(S0,HIGH);
  24. digitalWrite(S1,LOW);
  25.  
  26. Serial.begin(9600);
  27. }
  28.  
  29. void loop() {
  30. // Setting red filtered photodiodes to be read
  31. digitalWrite(S2,LOW);
  32. digitalWrite(S3,LOW);
  33. // Reading the output frequency
  34. frequency = pulseIn(sensorOut, LOW);
  35. // Printing the value on the serial monitor
  36. Serial.print(''R= '');//printing name
  37. Serial.print(frequency);//printing RED color frequency
  38. Serial.print('' '');
  39. delay(100);
  40.  
  41. // Setting Green filtered photodiodes to be read
  42. digitalWrite(S2,HIGH);
  43. digitalWrite(S3,HIGH);
  44. // Reading the output frequency
  45. frequency = pulseIn(sensorOut, LOW);
  46. // Printing the value on the serial monitor
  47. Serial.print(''G= '');//printing name
  48. Serial.print(frequency);//printing RED color frequency
  49. Serial.print('' '');
  50. delay(100);
  51.  
  52. // Setting Blue filtered photodiodes to be read
  53. digitalWrite(S2,LOW);
  54. digitalWrite(S3,HIGH);
  55. // Reading the output frequency
  56. frequency = pulseIn(sensorOut, LOW);
  57. // Printing the value on the serial monitor
  58. Serial.print(''B= '');//printing name
  59. Serial.print(frequency);//printing RED color frequency
  60. Serial.println('' '');
  61. delay(100);
  62. }

 

Now if we run the Serial Monitor we will start getting some values. These values depend on the selected frequency-scaling, as well as from the surrounding lighting.

TSC230 Color Sensor Photodiode Spectral Responisity Diagram

Note here that three values differ due to the different sensitivity of each photodiode type, as seen from the photodiode spectral responsivity diagram from the datasheet of the sensor.

Nevertheless, now let’s see how the values react when we will bring different colors in front of the sensor. So for example, if we bring red color, the initial value will drop down, in my case from around 70 to around 25.

Sensing color with Arduino Tutorial Example

So now if we want to represent the detected colors with the RGB Model which has values from 0 to 255, we will use the map() function to map or convert the readings to the values from 0 to 255.

  1. //Remaping the value of the frequency to the RGB Model of 0 to 255
  2. frequency = map(frequency, 25,70,255,0);

The value of 70 will be mapped to 0, and the value of 25 to 255. The same procedure goes for the two other colors.

Here’s the final source code for this example:
  1. /* Arduino Color Sensing Tutorial
  2. *
  3. * by Dejan Nedelkovski, www.HowToMechatronics.com
  4. *
  5. */
  6.  
  7. #define S0 4
  8. #define S1 5
  9. #define S2 6
  10. #define S3 7
  11. #define sensorOut 8
  12.  
  13. int frequency = 0;
  14.  
  15. void setup() {
  16. pinMode(S0, OUTPUT);
  17. pinMode(S1, OUTPUT);
  18. pinMode(S2, OUTPUT);
  19. pinMode(S3, OUTPUT);
  20. pinMode(sensorOut, INPUT);
  21.  
  22. // Setting frequency-scaling to 20%
  23. digitalWrite(S0,HIGH);
  24. digitalWrite(S1,LOW);
  25.  
  26. Serial.begin(9600);
  27. }
  28.  
  29. void loop() {
  30. // Setting red filtered photodiodes to be read
  31. digitalWrite(S2,LOW);
  32. digitalWrite(S3,LOW);
  33. // Reading the output frequency
  34. frequency = pulseIn(sensorOut, LOW);
  35. //Remaping the value of the frequency to the RGB Model of 0 to 255
  36. frequency = map(frequency, 25,72,255,0);
  37. // Printing the value on the serial monitor
  38. Serial.print(''R= '');//printing name
  39. Serial.print(frequency);//printing RED color frequency
  40. Serial.print('' '');
  41. delay(100);
  42.  
  43. // Setting Green filtered photodiodes to be read
  44. digitalWrite(S2,HIGH);
  45. digitalWrite(S3,HIGH);
  46. // Reading the output frequency
  47. frequency = pulseIn(sensorOut, LOW);
  48. //Remaping the value of the frequency to the RGB Model of 0 to 255
  49. frequency = map(frequency, 30,90,255,0);
  50. // Printing the value on the serial monitor
  51. Serial.print(''G= '');//printing name
  52. Serial.print(frequency);//printing RED color frequency
  53. Serial.print('' '');
  54. delay(100);
  55.  
  56. // Setting Blue filtered photodiodes to be read
  57. digitalWrite(S2,LOW);
  58. digitalWrite(S3,HIGH);
  59. // Reading the output frequency
  60. frequency = pulseIn(sensorOut, LOW);
  61. //Remaping the value of the frequency to the RGB Model of 0 to 255
  62. frequency = map(frequency, 25,70,255,0);
  63. // Printing the value on the serial monitor
  64. Serial.print(''B= '');//printing name
  65. Serial.print(frequency);//printing RED color frequency
  66. Serial.println('' '');
  67. delay(100);
  68. }

Note that the colors aren’t that much accurate but they are still good enough for simple projects. As another example of the TCS230 color sensor in my next video we will learn how to make an Arduino Automatic Color Sorting Machine.

 

 


更多 Jit Sen Electronics Sdn Bhd 相关资料
Jit Sen Electronics Sdn Bhd
Jit Sen Electronics Sdn Bhd Electronic Components Supplier Melaka, Electrical Parts Supply Malaysia, Semiconductors Supplies ~ Jit Sen Electronics Sdn Bhd