# Sensor that can differentiate color?

#### John A Bonilla

Joined Mar 11, 2017
61
Hello everyone,

I am trying to have my robot differentiate between the normal floor and the tape on the floor. It will not follow the line, but I need it to see when it passes over a line. I know about this line sensor, however I feel as though it might not be completely accurate and have confusion with the floors and the lines. If anyone has a better sensor or ideas, it would be very helpful.

https://www.sparkfun.com/products/9453

-John B

Joined Jan 15, 2015
4,733
This is the data sheet for the actual QRE1113, QRE1113GR Minature Reflective Object Sensor. Why do you feel it would not be accurate enough? Just about all of these type line sensing circuits are based on the same principal. A light source be it infrared or visible spectrum is reflected off a surface and the reflected light is measured. When doing this flat color surfaces work best rather than a shiny or high gloss surface. White reflects the most light and black absorbs the most light.

Considering the linked breakout board from Sparkfun is a \$3.00 USD part I would invest in one and provide a supply voltage to the IR Emitter (a current limiting resistor is on board) and measure the output while holding various reflective surfaces (different colors) above the sensor at a given distance.
I know about this line sensor, however I feel as though it might not be completely accurate and have confusion with the floors and the lines. If anyone has a better sensor or ideas, it would be very helpful.
This will depend entirely on the floor (reflective surface) the unit is used on. As a kid I built a color wheel using a small incandescent lamp or flashlight bulb and a simple photo sensitive resistor (PCI). Different colors reflected different amounts of visible light and the changing resistance was used in a circuit to change an audible oscillator frequency. You can always roll your own sensor from discreet parts. Again, why do you not feel the linked part would not be accurate enough based on the data sheet?

Also a Google of "reflective photo sensors" will bring up a few dozen hits like this one from Robo Shop designed with robots in mind.

Ron

Last edited:

#### AlbertHall

Joined Jun 4, 2014
8,828
You do realise that this sensor has to be very close to the surface - like 1-2mm?

Joined Jan 15, 2015
4,733
Additionally in addition to what Albert mentions these sensors work best when well shielded from ambient light. They like dark.

Ron

#### John A Bonilla

Joined Mar 11, 2017
61
You do realise that this sensor has to be very close to the surface - like 1-2mm?
View attachment 151030
Additionally in addition to what Albert mentions these sensors work best when well shielded from ambient light. They like dark. Ron
Thank you for your replies! I can isolate the sensors so that they are in the dark, and I can get the sensors 1 mm or close to it off the ground. I just wanted to make sure because I don't know if the floors would be glossy like a gym floor, or if they will be on a cement floor. The reason i have the problem is because if the sensor mis-reads the floor, then it causes a massive issue with its trajectory.

Joined Jan 15, 2015
4,733

#### be80be

Joined Jul 5, 2008
1,963
This kind of shows how this works.

#### John A Bonilla

Joined Mar 11, 2017
61
This kind of shows how this works.

View attachment 151162
Thank you for the suggestion, I bought the sensors, however instead of buying the analog version, I bought the digital version and I don't know how to use it, and the documentation on it is poor, as the link they provide has a code that does not work.

https://www.sparkfun.com/products/9454
http://bildr.org/2011/06/qre1113-arduino/

I don't have time to return it, if you have any idea as to how I can use this properly it would be very much appreciated.

#### AlbertHall

Joined Jun 4, 2014
8,828
If you use the digital part of the code here what values are printed to serial monitor?

#### John A Bonilla

Joined Mar 11, 2017
61
If you use the digital part of the code here what values are printed to serial monitor?
The code does not work at all

#### AlbertHall

Joined Jun 4, 2014
8,828
I have just downloaded this code. It compiles and uploads to my Arduino. The program prints '3004' repeatedly to the serial monitor which means no reflection was detected which makes sense as I do not have a QRE1113 board.

Which part of this sequence does the program fail to do for you?

#### John A Bonilla

Joined Mar 11, 2017
61
I have just downloaded this code. It compiles and uploads to my Arduino. The program prints '3004' repeatedly to the serial monitor which means no reflection was detected which makes sense as I do not have a QRE1113 board.

Which part of this sequence does the program fail to do for you?
When I copy and paste the code into the arduino IDE and then try to compile it, it gives me these errors.

#### Attachments

• 22.7 KB Views: 4

#### AlbertHall

Joined Jun 4, 2014
8,828
Code:
//Code for the QRE1113 Digital board
//Outputs via the serial terminal – Lower numbers mean more reflected
//3000 or more means nothing was reflected.

int QRE1113_Pin = 2; //connected to digital 2

void setup(){
Serial.begin(9600);
}

void loop(){

Serial.println(QRE_Value);

}

//Returns value from the QRE1113
//Lower numbers mean more refleacive
//More than 3000 means nothing was reflected.
pinMode( QRE1113_Pin, OUTPUT );
digitalWrite( QRE1113_Pin, HIGH );
delayMicroseconds(10);
pinMode( QRE1113_Pin, INPUT );

long time = micros();

//time how long the input is HIGH, but quit after 3ms as nothing happens after that
while (digitalRead(QRE1113_Pin) == HIGH && micros() - time < 3000);
int diff = micros() - time;
return diff;
}

#### John A Bonilla

Joined Mar 11, 2017
61
Code:
//Code for the QRE1113 Digital board
//Outputs via the serial terminal – Lower numbers mean more reflected
//3000 or more means nothing was reflected.

int QRE1113_Pin = 2; //connected to digital 2

void setup(){
Serial.begin(9600);
}

void loop(){

Serial.println(QRE_Value);

}

//Returns value from the QRE1113
//Lower numbers mean more refleacive
//More than 3000 means nothing was reflected.
pinMode( QRE1113_Pin, OUTPUT );
digitalWrite( QRE1113_Pin, HIGH );
delayMicroseconds(10);
pinMode( QRE1113_Pin, INPUT );

long time = micros();

//time how long the input is HIGH, but quit after 3ms as nothing happens after that
while (digitalRead(QRE1113_Pin) == HIGH && micros() - time < 3000);
int diff = micros() - time;
return diff;
}
Thank you! This worked. There must have been an issue when copying and pasting from the internet to the IDE resulting in some character differences or something lol. I appreciate it!