QTR-1A Reflectance Sensor very sensitive to distance

Hello! Thanks for reading this. I am pretty new with using Pololu sensors with an Arduino, all help is greatly appreciated.

I am using a single QTR-1A reflectance sensor with an Arduino Uno R3 to determine whether this sensor is pointing at a black surface or a white surface, and I was wondering if the sensor is supposed to be as sensitive/quirky as I have noticed. It is very difficult to get any meaningful data from my sensor readings - waving my hand about 15cm above the sensor back and forth gives a noticeable difference (800±100 when my hand is above it, 400±100 when it is not), but when I try to put a black surface vs. a white surface over the sensor at close distances, I get data that jumps all around. Putting the sensor just a millimeter away from a difference distance will give completely different results that I don’t know how to decipher. I have tried distances from 1mm to 20mm, and the data jumps around ±200ish between different points, and those reference points change depending on what distance the sensor is from the surface.

I have a circuit hooked up to an Arduino Uno R3 board, with Vin attached to the 5V pin on the Arduino, GND attached to ground on the Arduino, and OUT attached to an analog pin A4. I am using the Serial port to display the raw data (0 to 1023) from the sensor. Let me know if you think I have hooked up the circuit incorrectly, or have any ideas! My basic code is below, it just sets up a Serial port, then prints readings from an analog pin.

I also have two of these sensors and have gotten the same results with both.

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



void loop(){
  
  int reading = analogRead(4);
  Serial.println(reading);
  delay(100);
  
}

Hello.

Yes, these sensors are very sensitive to distance. Specifically, they are measuring the intensity of reflected IR, and that intensity is very dependent on how far away the reflective surface is. At a constant distance, variance in sensor output corresponds to variance in the IR reflectivity of the surface. If the distance is changing, it is probably not possible to determine if output changes are being caused by changes to distance or changes to surface reflectivity. The QTR sensors are intended to be mounted within a few millimeters of the surface (the product page specifies an optimal sensing distance as 3 mm), and we recommend you calibrate the sensors for your particular setup. Our Arduino library for these sensors even has a calibrate() routine.

Do you have your sensor mounted face-up? I would not expect you to get any meaningful readings at a distance of 15 cm (and something passing in front of the sensor should generally reflect more IR onto the sensor, make the voltage go down, not up). I think that the sensor is detecting ambient IR from the room in this case, and your hand casts an IR shadow over the sensor as it passes over, altering the output to show lower IR detection. This should be easy to test by repeating the same procedure in a darkened room/shady place.

You might find the our QTR sensor app note helpful. It specifically shows how the sensor output varies by distance for a sample application.

What kind of behavior were you hoping to get from this sensor? What is your target application?

- Ben

The sensors are being used for a small RC car to follow a black line about a course, and they were planned to be placed around 0.5cm above the ground. However we expect variations in that distance of around ±2mm depending on a slightly uneven surface, and the variations in the readings we are getting at slight height distances seem to be too high to get consistent black/white results. We still have some more testing to do with them though, and I’ll try testing them with some shields to block ambient light and with the calibrate() function.

Thanks for your help, let me know if you have any more additional information that might be useful.

UPDATE: I just did some more testing (without calibrating the sensors), you were correct that ambient light was getting in the way. The sensors will work for our application as long as we keep them securely fastened (not just me holding them above a line!) and at a closer distance than I had originally planned. Thanks for your speedy response!

I’m glad to hear that the sensors will work for you. Your application sounds completely reasonable for them (I was worried that you wanted to use them for long-range obstacle detection). Thank you for the update.

- Ben