Pages: [1]   Go Down
Author Topic: Color Sensor Errors  (Read 985 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, I'm trying to use a parallax color sensor (specs at http://www.parallax.com/Portals/0/Downloads/docs/prod/acc/TCS3200_doc.pdf ) I'm checking the colors' frequencies using the Serial Monitor on my computer. However, I'm only getting a reading for the green color duration. Even then, I'm not getting any variance with different colors. I'm not exactly sure if it's a programming error or if the sensor is malfunctioning, but I would love some help. I think it may have something to do with the outputs(S2 and S3). Thanks for all your help.

Code:
[
/*optimal distance for calibration is 2.5 in*/
int Out = 13;                 //C Input "the Read"?
int S0= 8;                 //A Output
int S1 = 9;                //B Output
int S2= 10;                  //E Output
int S3 = 12;                 //F Output
int LED = 11;                 //D Output-turns on LEDS

unsigned long REDduration;
unsigned long GREENduration;
unsigned long BLUEduration;
unsigned long CLEARduration;


void setup () {
 pinMode(LED,OUTPUT);
 pinMode(Out,INPUT);
 pinMode(S0,OUTPUT);
 pinMode(S1,OUTPUT);
 pinMode(S2,OUTPUT);
 pinMode(S3,OUTPUT);
 digitalWrite(LED, HIGH);
 Serial.begin(9600);
}

void loop () {
  digitalWrite(S0,HIGH);
  digitalWrite(S1,HIGH);
  color ();
  Serial.print("R");
  Serial.println(REDduration);
  Serial.print("G");
  Serial.println(GREENduration);
  Serial.print("B");
  Serial.println(BLUEduration);
  Serial.print("C");
  Serial.println(CLEARduration);
}

void color () {
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
 REDduration= pulseIn(Out,HIGH);
digitalWrite(S2,LOW);
digitalWrite(S3,HIGH);
 BLUEduration= pulseIn(Out,HIGH);
digitalWrite(S2,HIGH);
digitalWrite(S3,LOW);
 CLEARduration= pulseIn(Out,HIGH);
digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);
GREENduration= pulseIn(Out,HIGH);

}]
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46246
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is already an LED with resistor connected to pin 13. That usually means it's not the best choice for an input pin. Try a different input pin.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you I did not think of that. I changed it to pin 7, but now it's only reading CLEARduration. Any thoughts?
Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 26
Posts: 1148
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What values do you get? Do they vary when you vary what you point to? Do the vary if you have the illumination LED On/Off?

I have never used this sensor, so I am just guessing here. Firstly I would pull the S0 (using the names in the PDF you refer to) LOW so we divide the output frequency by 50. This may possibly give a slow enough frequency for the pulseIn() to return a more usefull value.
The example code in the PDF counts pulses, the Arduino measures pulsewidth. Assuming the same wave shape, then at higher frequencies the pulsewidth should be narrower.
I do not like using interrupts but this may be the right place to do it, to get a count of pulses rather than the pulswidth - at the possible 600Khz that is 2 microseconds which pulsewidth() may/may not catch.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the help. I worked it out now. I just disconnected the S0 and S1 inputs. I know this is probably not correct, but I'm getting consistent readings. If it starts malfunctioning again, I'll be sure and try your suggestions!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nevermind, the numbers I'm getting are just garbage. They don't change no matter what color is in front on the sensor. I also tried LED light to see if it was too dark, but that didnt change the values either. Please Help!
Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 26
Posts: 1148
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying, I'm trying ...  smiley-wink but I need something to work on.

What happened by tying S0 low to get a slower frequency? And please do post the values ... others might see a pattern or get a clue to your problem.

And I also think a circuit diagram might tell us something.
Logged

Pages: [1]   Go Up
Jump to: