Welcome in the wonderful world called Arduino ,
First use the # button if you want to publish code (you can modify your 1st post, select the code and press the #button)
The reading of the sensor will fail, so I rewrote your code a bit so it should work
#define THRESHOLD 750
int ledPin = 10; // Setup LedPin on Digital Pin 10
void setup()
{
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
if (sensorValue < THRESHOLD )
{
digitalWrite(ledPin, HIGH); //High Reflectance.
}
else
{
digitalWrite(ledPin, LOW); // Low Reflectance.
}
}
To improve the stability of the readings, you can repeat them in a loop like in the function below.
unsigned int sharpRawAvg()
{
unsigned long raw = 0;
for (byte i=0; i<32; i++)
{
raw += analogRead(A0);
//delay(1);
}
return raw/32;
}
You can add this function to your code and call it from your sketch
replace
int sensorValue = analogRead(A0);with
int sensorValue = sharpRawAvg() succes,
Rob