Upload this code:
int led1 = 9; // led 1 pin 9
int brightness1 = 0; // led brightness
int fadeAmount1 = 5; // fade amount
void setup () {
Serial.begin(9600);
while (!Serial) {}
Serial.println("Starting sketch");
pinMode(led1, OUTPUT);
}
void loop() {
analogWrite(led1, brightness1);
Serial.print("brightness1 = ");
Serial.println(brightness1);
// fade in the led
brightness1 = brightness1 + fadeAmount1;
// turn off the led for 3 sec when led brighness reaches certain level
if (brightness1 == 150) {
digitalWrite(led1, LOW);
Serial.println("Fade is finished");
delay(2000);
}
delay(50);
}
Then do this:
- Tools > Serial Monitor
- Select 9600 from the menu in the bottom right corner of the Serial Monitor
Adding debug serial output is a really useful tool for understanding what's happening in your Arduino.