Trying to find a code for the IR rangefinder that I can tinker with, all I'm looking for is a code that will make a LED light up when something is 20cm away from the sensor. Been looking around the internet all morning, and everything is too confusing... So far this is what I found

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.