Brooke's LED Fade

From CHS Sigma
Revision as of 10:25, 16 May 2017 by Bbecker85 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Our first assignment was to make a LED fade in and out. This assignment demonstrates the use of analogWrite(). Analogwrite() uses pulse width modulation (PWM) to make the fading effect. The result of the project was a wave of text growing and shrinking the LED brightness.


First, I wired up my circuit using a 220Ω resistor and made the LED blink. Then went to trying to make the LED fade in and out, rather then blink. I then used analogWrite() to make the fading effect.

Problems and Solutions:

One problem I had was using analogWrite in the code to make the fade. I then solved my problem by researching about analogWrite and how to use correctly in a code. After doing my researching about analogWrite i correctly used it in the code to make the LED fade in and out.

Circuit Diagram:



    int led = 9;
	int brightness = 0;
	int fadeAmount = 5;
	void setup()
	pinMode (9, OUTPUT);
void loop()
	analogWrite(led, brightness);
	brightness = brightness + fadeAmount;
    if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;