Code:

int led = 9;

int brightness = 0;

int fadeAmount = 5;

void setup() {

pinMode(led, OUTPUT);

}

void loop() {

analogWrite(led, brightness);

brightness = brightness + fadeAmount;

if (brightness <= 0 || brightness >= 255) {

fadeAmount = -fadeAmount;

}

delay(30);

}

The first part of the code, the int, is referred to the variables we will be using

On void setup, we prepare the pinMode that is locatd the variable Led as an OUTPUT form

We create the void loop, which will contain the main part

On the void loop, we stablish an equality with the var LED and BRIGTHNESS using the analogWrite() command.

We say that brigthness equals the same variable name + the variable fadeAmount, this allows to make the fade effect we are looking for

After that, we stablish an if() which it will declare the min and max of the brigtness on this case and change the variable fadeAmount from positive to negative

That is how to make a fade effect using a LED and Arduino.