Yes, you could simply compare the value returned by analogread to some value that you find by trial and error or by looking at the specs.
Please forgive that I have not done very much yet with the Arduino so I may not completely flesh this out...
That is you could start off by doing something as simple as:
Have your main loop simply repeat looping through doing something like:
int val;
int prev;
void setup() {
prev = 0;
Serial.begin(9600);
}
void loop() {
val = analogRead(0); // assume pin 0...
if (val != prev) {
Serial.println(val, DEC);
prev = val;
}
delay(50);
}
This will simply do the analog conversions and print out the values when it changes. Now you can simply move a target around and see how the value changes. You will probably find that as you move the target closer to you the value will go up. You can then decide at what the value is at the distance you wish to trigger the LED. You then can simply set the LEDS output port to the appropriate value. For example if you find that the trigger point is around 330, you could change the code to something like:
void loop() {
val = analogRead(0); // assume pin 0...
if (val >330)
digitalWrite(1, HIGH);
else
digitalWrite(1,LOW)
delay(50);
}
Again there may be issues here, also I show pins 1 and 0... But hopefully it gives you a few hints. Also how you turn on or off the LED will depend on how you have it wired.
Good Luck
Kurt