This is a standard Arduino example sketch, copied here for reference.

Full Source Code
The full code is all in one fileĀ Fade.ino.
/* Fade This example shows how to fade an LED on pin 9 using the analogWrite() function. This example code is in the public domain. */ int led = 9; // the pin that the LED is attached to int brightness = 0; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by // the setup routine runs once when you press reset: void setup() { // declare pin 9 to be an output: pinMode(led, OUTPUT); }
Read more: Fade Arduino Sketch