Color Sensor TCS230

From the documentation:

MD_TCS230(uint8_t s2, uint8_t s3); MD_TCS230(uint8_t s2, uint8_t s3, uint8_t oe); MD_TCS230(uint8_t s2, uint8_t s3, uint8_t s0, uint8_t s1); MD_TCS230(uint8_t s2, uint8_t s3, uint8_t s0, uint8_t s1, uint8_t oe);

Various forms of the constructor for this class. The parameters are all the Arduino pin numbers used to control the nominated pins on the TCS230. The form used will depend on the configuration of the hardware connections to the Arduino. At a minimum S2 and S3 are required for color filter selection.

You can either use a constructor that includes the S0, S1 pins in the constructor, and the library will use them. If you don't specify them to the library then it is up to you to connected them to either GND or +5V. To see which makes sense in you situation, you need to look at the datasheet for the device and set accordingly.

Thanks for ur help! Finally I got results on screen using the example ColorMatch_TCS230. My results are like:
RGB(255,0,0)
RED
.
.
.
What I am supposed to do now is to send this data to other arduino with LCD screen and to see this results on LCD screen, or at least on screen of other computer which is connected to this arduino. I found this link. It is saying about VirtualWire library. But I dont have any idea how I can make these two codes work together? http://communityofrobots.com/tutorial/kawal/using-rf-link-reciever-and-transmitter-arduino
I am using 433 MHz transmitter-reciever module like this http://mcdn01.gittigidiyor.net/5678/RXA1-TXC-1-RF-ALICI-VERICI-MODUL__56782719_0.jpg
Can you help me about putting these two codes together and make it work?

I think that is a different problem and should be raised in a separate forum discussion panel. There are others who will know far more than I do about that.

I would suggest that you try and experiment with the VirtualWire hardware and library before you use it in your code, as becoming familiar with your tools helps you to use them better.

Good luck!

hello again!

I was getting good results yesterday. I did the same things today, same code, same pin connections, everything is same. Now I am putting different colors in front of sensor and getting results like

(255,45,255) ... (255,169,255)

Red and Blue values are always same! 255 everytime. my definitions are:

// Pin definitions

define S0_OUT 6

define S1_OUT 7

define S2_OUT 12

define S3_OUT 13

define OE_OUT 8 // LOW = ENABLED

MD_TCS230 CS(S2_OUT, S3_OUT, OE_OUT);

I was doing the same yesterday, and getting results changing always according to the color I put in front of sensor.

What could it be related to? My sensor is broken or I dont know? Can you help me please? :~

and now I started to get results like

(56,255,67) ... (78,255,113)

Green always 255... I am afraid that color sensor module is broken.

Hello, Now I am using this code http://www.elecfreaks.com/wiki/index.php?title=Color_Sensor_Module

and getting results like in the pic in this link http://www.elecfreaks.com/store/download/product/User_Guide/Color_Sensor_Module/color_sensor_module_user_guide.pdf

but sometimes I am getting some results bigger than 255...What could be the problem? Anyone can help me please?

Well your result is only going to be limited to 255, if it is a one-byte unsigned number. If it is a 16 bit or 32 bit number, there is nothing specifically limiting it to a maximum value of 255.

I had a look at the code there and could not determine how exactly these numbers are being derived.

If that is a problem for you, you can always scale it back to the 0..255 range if you want to use it for some other purpose.

Well your result is only going to be limited to 255, if it is a one-byte unsigned number.

To the letter this is true. However, the sensor library is supposed to return an RGB value. If the library is not doing that there is a problem with the library, as a correct RGB reading is always 0-255. The RGB value is derived from the frequency returned and there is a linear relationship between the two, so you see scaling factors built into the code OP is using.

I still don't know how to connect pins with Marco_c libraries... :cold_sweat:

I read everything... but probably I need a text like:

Connect GND to GND, 5V to 5V, S1 to 2, S3 to 5... and load the example Calibrate.

I just need to calibrate and read values, with the example, and I read everything but I don't know why it is reading 0,0,0 always! I use Arduino Uno and the TCS230 with the connection between OE and GND cut like the instructions said.

Thanks in advance for your help!!

What you need is actually all in the documentation already.

Refer to this other post http://forum.arduino.cc/index.php?topic=224465

Hello,
In my case I get very small values + white value. The values are < 100 so all the surfaces I scan are close to black.
Any ideas? I tried it on nano. Could it be low power issue.
Thank you.
Antonis

I can't get the example from https://github.com/dalmirdasilva/ArduinoColorRecognitionDriver as it references a missing Timer1.

C:\Users\Steve\Documents\SketchApress\libraries\ColorRecognitionTCS230\ColorRecognitionTCS230.cpp: In static member function 'static void ColorRecognitionTCS230::timerInterruptHandler()': C:\Users\Steve\Documents\SketchApress\libraries\ColorRecognitionTCS230\ColorRecognitionTCS230.cpp:62: error: 'Timer1' was not declared in this scope

por favor alguien q me ayude a usar las frecuencias que se obtienen del sensor de color tcs230 para poder controlar servomotores…ya tengo la programacion del sensor…me falta ubicar a los servos en la programacion : Smiley-confunden:

Arduino_ColorRecognitionSensorTCS230.ino (1.79 KB)

Hi I also used a color sensor based on TCS230 (ZX-Color http://olimex.cl/website_MCI/static/documents/Datasheet_ZX-Color.pdf), but is very different. So, while typical sensor has 7 pins, ZX-Color has only 3 pins (one for 5v, one for ground and one for output signal). The output must be conected to analog input pin in Arduino UNO. I couldn't find any information about how to obtain the separates R, G, B signals. All information, codes and libraries on internet is based on 7 pins sensor. Please, any help will be aprecciated

No libraries for this but the datasheet you provided has all the information you need.

ZX-COLOR would be detect the object color and convert to DC voltage 0-5V fed to the OUTPUT connector

Connect the output signal to an analog input on the Arduino

Internal processing of ZX-COLOR will gives the digital data of target color in 6-bit MSB. Bit 7 and 4 as Red component bits (Rr). The full red color value is both bits as 11(R=1, r=1). None red color component, both bits are 00 (R=0, r=0). Bit 6 and 3 as Green component bits (Gg). The full green color value is both bit as 11 (G=1, g=1). None green color component, both bits are 00 (G=0, g=0). Bit 5 and 2 as Blue component bits (Bb). The full blue color value is both bits as 11 (B=1, b=1). None blue color component, both bits are 00 (B=0, b=0). The important value are upper 6 bits. The internal processor will convert the color bit to analog. The DC voltage output is 0 to 5V. The A/D system must convert the DC voltage to digital data and analyze for defination the sensing color.

So take the analog value read from the sensor and use the bits above for the RGB values.

This sensor seems to take the RGB values from the TCS230 (0-255) and reduce them to 2 bit resolution (0-3) each.

Please help me to correct the below code for color sensor. I want to add a push button program so when it is ask for the “Reading value for Black calibration and white calibration”, I’ll press push button and program move ahead. But data(RGB) it will read continuously. Please help me.

#include <MD_TCS230.h>
#include <FreqCount.h>
#include <LiquidCrystal.h>

#define BLACK_CAL 0
#define WHITE_CAL 1
#define READ_VAL 2

// Pin definitions
#define S2_OUT 9
#define S3_OUT 10
#define OE_OUT 13 // LOW = ENABLED

MD_TCS230 CS(S2_OUT, S3_OUT, OE_OUT);
const int rs = 8, en = 7, d4 = 6, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup()
{

Serial.begin(57600);
lcd.begin(16, 2);
lcd.setCursor(1, 0);
Serial.print(F("\n[Sensor Calibration]"));
lcd.print(F(“Sensor Values”));
CS.begin();
}
char getChar()

{
while (Serial.available() == 0)
;
return(toupper(Serial.read()));
}

void clearInput()

{
while (Serial.read() != -1)
;
}

uint8_t fsmReadValue(uint8_t state, uint8_t valType, uint8_t maxReads)

{
static uint8_t selChannel;
static uint8_t readCount;
static sensorData sd;

switch(state)
{
case 0: // Prompt for the user to start
Serial.print(F("\n\nReading value for “));
switch(valType)
{
case BLACK_CAL: Serial.print(F(“BLACK calibration”)); break;
case WHITE_CAL: Serial.print(F(“WHITE calibration”)); break;
case READ_VAL: Serial.print(F(“DATA”)); break;
default: Serial.print(F(”??")); break;
}

Serial.print(F("\nPress any key to start …"));
state++;
break;

case 1:
getChar();
clearInput();
state++;
break;

case 2:
CS.read();
state++;
break;

case 3:
if (CS.available())
{
sensorData sd;
colorData rgb;

switch(valType)
{
case BLACK_CAL:
CS.getRaw(&sd);
CS.setDarkCal(&sd);
break;

case WHITE_CAL:
CS.getRaw(&sd);
CS.setWhiteCal(&sd);
break;

case READ_VAL:
CS.getRGB(&rgb);
Serial.println(“RGB [”);
lcd.setCursor(0, 1);
lcd.print(“RGB [”);
Serial.print(rgb.value[TCS230_RGB_R]);
lcd.print(rgb.value[TCS230_RGB_R]);
Serial.print(",");
lcd.print(",");
Serial.print(rgb.value[TCS230_RGB_G]);
lcd.print(rgb.value[TCS230_RGB_G]);
Serial.print(",");
lcd.print(",");
Serial.print(rgb.value[TCS230_RGB_B]);
lcd.print(rgb.value[TCS230_RGB_B]);
Serial.println("]");
lcd.print("]");
delay(2000);
lcd.print(" ");
//lcd.clearLine(0);
//lcd.clear();
//lcd.noDisplay();
delay(10);
lcd.setCursor(0, 1);
//lcd.display();
break;
}
state++;
}
break;

default: // reset fsm
state = 0;
break;
}

return(state);
}

void loop()
{
static uint8_t runState = 0;
static uint8_t readState = 0;

switch(runState)
{
case 0: // calibrate black
readState = fsmReadValue(readState, BLACK_CAL, 2);
if (readState == 0) runState++;
break;

case 1: // calibrate white
readState = fsmReadValue(readState, WHITE_CAL, 2);
if (readState == 0) runState++;
break;

case 2: // read color
readState = fsmReadValue(readState, READ_VAL, 1);
break;

default:
runState = 0;
}
}

Hello ALL! I use this post to make a question. I need build a pea sorter low cost. the question is if you belive that one or more color sensors could detect the green peas and the white or black peans.

Thank you.