Task 4: Upload, Test, and Experiment
Running the Fade Code
After writing your fade sketch using a for loop and analogWrite(), upload the code to your Arduino and observe the LED.
You should see the LED gradually increase and decrease in brightness. If not, try the steps in the troubleshooting section below.
Try This!
- Change the delay() value in the code. What happens when it's set to 5ms? 50ms?
- Try adjusting the range in the for loop — go from 0 to 128 instead of 255.
- Use Serial.println() to print brightness values as they change.
Troubleshooting
- Is your LED connected to a PWM-capable pin (like 9 or 10)?
- Is the LED connected the right way? (Long leg to pin, short to GND)
- Did you upload the sketch successfully?
- Are all jumper wires secure?