PWM is a way of regulating the power/brightness/revolution speed by changing the duration of voltage pulses. The relationship between the duration of a pulse, to the duration of a pause is called duty or power percentage. PWM pulses can be generated by an electric circuit or by a micro-controller. Arduino, for instance, has a command analogWrite() for generating PWM signal.

Fade In Fade Out LED

[insert circuit]
The simple code snipped portrayed below regulates the brightness of an LED by using PWM. Link to code on Github.
#define GREEN_PIN 9
void setup() {
pinMode(BLUE_PIN, OUTPUT);
}
void loop() {
for(int val = 0; val < 255; val ++){
analogWrite(GREEN_PIN, val);
delay(30);
}
delay(2000);
for(int val = 255; val >= 0; val -= 1){
analogWrite(GREEN_PIN, val);
delay(30);
}
delay(2000);
}
Voltage Shape Viewing Using an Oscilloscope
