val = cm; // reads the value of the potentiometer (value between 0 and 1023) val = map(val, 200, 10, 0, 255); // scale it to use it with the LED (value between 0 and 255)

analogWrite(ledpin, val); delay(10);

}

if (cm > 61){ analogWrite(ledpin, HIGH);}

}

// The following functions won't compile if not used in the code so no need to comment any out.// Your code left out the closing curly bracket, not sure how it cmpiled without it but maybe // it was only in the version you emailed me.long microsecondsToInches(long microseconds) {return microseconds / 74 / 2;}

The code works, which is great, but now there's another problem...The LED is not functioning correctly. It lights up when it is supposed to but has this annoying habit of flickering, especially when someone moves in front of the sensor. My professor said i should get an external power supply for it (it's an ultra-bright 1 Watt LED)...

Not particularly, no. It also flickers a lot when the sensor reads past 61 cm (I set the LED to stay at 255 when the sensor reads closer than 61 cm).

By the end of the project, I need around 12 of those LEDs to be lit in order to get the obnoxious amount of brightness required. Thus, my problem with needing a power source will be a lot larger by the end.

To be honest, it's because I'm really new to this and wasn't aware that the LED would need any external power.

Thanks again for your input, Groove and AWOL! I take it from your responses that I SHOULD use external power. This being said, since I need to hook up 12 of these 1 Watt LEDs, I believe I need a 12A power source. Are there other electrical implementations I should use with this--i.e. a transistor, a voltage regulator, etc.? Again, I'm really new to this, so I apologize if my questions are really elementary.