Summary of Fading using an Arduino
This project demonstrates how to use Pulse Width Modulation (PWM) on an Arduino to fade an LED connected to digital pin 9. PWM creates an analog-like effect by rapidly switching the digital output on and off, controlling the LED's brightness smoothly.
Parts used in the Fading LED Project:
- Arduino board
- LED
- 220-ohm resistor
- Connecting wires
- Breadboard (optional)
Demonstrates the use of analog output (Pulse Width Modulation (PWM)) to fade an LED. PWM is a technique for getting an analog-like behavior from a digital output by switching it off and on very fast.
Circuit
An LED connected to digital output pin 9 through a 220-ohm resistor.
Schematic
image developed using Fritzing. For more circuit examples, see the Fritzing project page
Code
Fading
This example shows how to fade an LED using the analogWrite() function.
The circuit:
* LED attached from digital pin 9 to ground.
Created 1 Nov 2008
By David A. Mellis
modified 30 Aug 2011
By Tom Igoe
http://arduino.cc/en/Tutorial/Fading
This example code is in the public domain.
*/
int ledPin = 9; // LED connected to digital pin 9
void setup() {
// nothing happens in setup
}
For more detail: Fading using an Arduino