I'm new to programming, and I am testing an IR reflectance sensor TCRT5000, my code gives me data but the data does not correspond to what I want it to do. I want the value to go high when it's detecting a white background and low when it's a dark background, but the sensor does not give varied data at all. I have tried changing the sensor(I have about 50) but the data is still not varied and is about 1020.
const int LINE = A2; //line sensors pins
void setup(){
pinMode(LINE, OUTPUT); //set the line sensor pin as output and turned on
digitalWrite(LINE, HIGH);
Serial.begin(9600);
}
void loop(){
int line = analogRead(LINE);
Serial.print(line); //print the value read from the sensor
Serial.print(" ");
delay(500); //reading taken every half a second
if(line>250){
Serial.println("dark"); //if reading above 250, print dark
}
else{
Serial.println("light"); //if below 250, print light
}
}