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

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:
#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:
#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!!
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: June 14, 2013, 02:56:59 am by pylon » Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1257
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a library that works well for these types of sensors in my code repository (link below in my signature).
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

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

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.
Logged

Pages: [1]   Go Up
Jump to: