Hello! Thanks for reading this. I am pretty new with using the Arduino, all help is greatly appreciated. I am using a Pololu QTR-1A reflectance sensor, which is a 5V analog sensor with a single infrared LED and a photoresistor. It is meant for edge following and line following, and outputs a voltage from 0 to 5V depending on the amount of light reflected (translated to an integer from 0-1023 on the arduino). I am also using an Arduino UNO R3.
I am trying to determine whether this sensor is pointing at a black surface or a white surface, and I have noticed that the sensor is incredibly sensitive to movement and distance from the surface. It is very difficult to get any meaningful data from my sensor readings - I would expect the sensor to clearly give a high or low voltage depending on whether it is pointing at a black or white surface, but instead I am getting nearly random values. When the sensor is brought within the manufacturer's recommended range of a surface (5mm), the output difference between black/white surface is only 100-200 (about a volt), whereas the manufacturer says it should be somewhere in the realm of 4-5V difference. Moving the sensor even 1mm closer or further away from the surface will change the analog reading of the white or black line by almost 200.
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. 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. Any ideas or experiences with reflectance sensors are greatly appreciated, and whether this behavior is to be expected (online reviews/videos didn't seem to show this behavior) or not.
Here's the code I am using, it is pretty simple:
int reading = analogRead(4);