Go Down

Topic: Testing Color sensor (Read 778 times) previous topic - next topic

arduattack

Hi there,
  I wanted to know whether color sensor TCS3210 is working. I multiplexed 2 sensors(2:1) and select the data values. When I plugged with arduino uno and run the code initially I got approximately correct RGB values . But now I am getting constant R=50 G=50 B=50.  I think there is something wrong color sensors. So I tested using the color sensor by running code arduino uno and I am getting R=0;G=0;Y=0. Moreover the voltage and current values of the sensors are constant irrespective of the color.The code I used for testing the sensor.
Code: [Select]

#include <FreqCount.h>
void readFreq(int num);
uint8_t pinS2=10,pinS3=11,pinOUT=7;
float r=0,g=0,b=0, refWell;
int i=1;

void setup() {
  Serial.begin(9600);
 
  pinMode(pinS2, OUTPUT);
  pinMode(pinS3, OUTPUT);
  pinMode(pinOUT, INPUT);
  digitalWrite(pinS2, LOW);
  digitalWrite(pinS3, HIGH);
 
  delay(500);
  FreqCount.begin(1000);
}

void loop()
{
    readFreq(i);
  FreqCount.begin(1000);
}

uint32_t giveRed()
{
  unsigned long count=8;
  digitalWrite(pinS2, LOW);
  digitalWrite(pinS3, LOW);
  while (!FreqCount.available()) {    }
  delay(100);
  if(FreqCount.available())
  {count = FreqCount.read();}
  return count;
}

uint32_t giveGreen()
{
  unsigned long count=8;
  digitalWrite(pinS2, HIGH);
  digitalWrite(pinS3, HIGH);
  while (!FreqCount.available()) {    }
  if(FreqCount.available())
  {count = FreqCount.read();}
return count;

}

uint32_t giveBlue()
{
  unsigned long count=8;
  digitalWrite(pinS2, LOW);
  digitalWrite(pinS3, HIGH);
  while (!FreqCount.available()) {    }
  delay(100);
  if(FreqCount.available())
  {count = FreqCount.read();}
  return count;
}

uint32_t giveClear()
{
  unsigned long count=8;
  digitalWrite(pinS2, HIGH);
  digitalWrite(pinS3, LOW);
  while (!FreqCount.available()) {    }
  if(FreqCount.available())
  {count = FreqCount.read();}
  return count;
}

void readFreq(int num)
{
  float rl=0,bl=0,gl=0,cl;
  float ratio;
   
  if(num == 1)
  {
    rl=giveBlue();
    gl=giveBlue();
    bl=(giveBlue()+giveBlue()+giveBlue()+giveBlue())/4;
    cl=giveBlue();
    refWell = bl;
  }
 
  else {
    rl=giveBlue();
    gl=giveBlue();
    bl=(giveBlue()+giveBlue()+giveBlue()+giveBlue())/4;
    cl=giveBlue();
  }
  ratio = (float) bl/refWell;
  if(num == 7)
  ratio = (float) bl/refWell/0.89;
 

Serial.print(rl);
Serial.print(gl);
Serial.print(bl);
Serial.print(ratio);
Serial.println(cl);
delay(1000);
if(ratio < 1.15)
{
Serial.println("Resistent");
}
if(ratio > 1.15 && ratio < 1.25)
{
Serial.println("Mildly Sensitive");
}
if(ratio > 1.25)
{
Serial.println("Sensitive");
}
}


The code I used for final Mux logic.
Code: [Select]
#include <FreqCount.h>
void readFreq(int num);
uint8_t pinS2=10,pinS3=11,pinOUT=7;
float r=0,g=0,b=0, refWell;

//uint8_t pinLEDV=42, pinIRT=43, irpin=39, pinP1=40, pinP2=41;
int serial_num=0;
int inputs[4] = {5,4,3,2}; // A,B,C,D inputs for decoder and mux
byte BCD[3][4] ={
{0,0,0,0},
{0,0,0,1}
//{0,0,1,0}
};//all combinations of input
//int G1 = 36;//SET enable pins for decoder and mux
//int G2 = 34;

void setup() {
  Serial.begin(9600);
  pinMode(pinS2, OUTPUT);
  pinMode(pinS3, OUTPUT);
  pinMode(pinOUT, INPUT);
digitalWrite(pinS2, LOW);
digitalWrite(pinS3, HIGH);
  //delay(500);
  FreqCount.begin(1000);
}

void loop()

  int n=0;
//digitalWrite(G1,LOW);
//digitalWrite(G2,LOW);
for(int n=0; n<2; n++)
{
  Serial.print("Sensor No. = ");
  Serial.print(n);
  Serial.print("   ");
for(int c = 0; c < 4; c++)
{
digitalWrite(inputs[c], BCD[n][c]);
delayMicroseconds(1000);
}
  readFreq(n);
  delayMicroseconds(1500);
  FreqCount.begin(1000);
}
}

uint32_t giveRed()
{
  unsigned long count=8;
  digitalWrite(pinS2, LOW);
  digitalWrite(pinS3, LOW);
  while (!FreqCount.available()) {    }
  if(FreqCount.available())
  {count = FreqCount.read();}
  return count;
}

uint32_t giveGreen()
{
  unsigned long count=8;
  digitalWrite(pinS2, HIGH);
  digitalWrite(pinS3, HIGH);
  while (!FreqCount.available()) {    }
  delay(1000);
  if(FreqCount.available())
  {count = FreqCount.read();}
return count;

}

uint32_t giveBlue()
{
  unsigned long count=8;
  digitalWrite(pinS2, LOW);
  digitalWrite(pinS3, HIGH);
  while (!FreqCount.available()) {    }
  //delay(1000);
  if(FreqCount.available())
  {count = FreqCount.read();}
  return count;
}

uint32_t giveClear()
{
  unsigned long count=8;
  digitalWrite(pinS2, HIGH);
  digitalWrite(pinS3, LOW);
  while (!FreqCount.available()) {    }
  if(FreqCount.available())
  {count = FreqCount.read();}
  return count;
}

void readFreq(int num)
{
  float rl=0,bl=0,gl=0,cl;
  float ratio;
  if(num == 0)
  {
    rl=giveBlue();
    gl=giveBlue();
    bl=(giveBlue()+giveBlue()+giveBlue()+giveBlue())/4;
    cl=giveBlue();
    refWell = bl;
  }
 
  else {
    rl=giveBlue();
    gl=giveBlue();
    bl=(giveBlue()+giveBlue()+giveBlue()+giveBlue())/4;
    cl=giveBlue();
  }
  ratio = (float) bl/refWell;
  if(num == 7)
  ratio = (float) bl/refWell/0.89;
 
Serial.print("R=");
Serial.print(rl);
Serial.print(" ");
Serial.print("G=");
Serial.print(gl);
Serial.print(" ");
Serial.print("B=");
Serial.print(bl);
Serial.print(" ");
Serial.print("ratio= ");
Serial.print(ratio);
Serial.print(" ");
Serial.print("C=");
Serial.println(cl);
delay(1000);
if(ratio < 1.15)
{
Serial.println("Resistent");
}
if(ratio > 1.15 && ratio < 1.25)
{
Serial.println("Mildly Sensitive");
}
if(ratio > 1.25)
{
Serial.println("Sensitive");
}
}


Please help me out !! Its kinda urgent.
Thanks in Advance!!

pylon

#1
Jun 13, 2013, 04:46 pm Last Edit: Jun 14, 2013, 09:56 am by pylon Reason: 1
No link to the hardware you used, no link to the libraries you used, no description of how you have connected the components. Did you really read the sticky not at the top of the forum?

marco_c

I have a library that works well for these types of sensors in my code repository (link below in my signature).
Arduino libraries http://arduinocode.codeplex.com<br />Parola for Arduino http://parola.codeplex.com

arduattack

Actually I connected Output pin of color sensor(Light to frequency coverter) to Pin 7 of arduino uno which isn't connected to timer. That's why I was getting wrong values. I rectified it.But when I illuminated the sensor with red Led I should get R value higher than G and B. But I'm getting almost equal values. Is there anything I can do.

Go Up