ANALOG OUTPUT – Again, the simplest output transducer is the LED but for more than the two states available with digital output (0 and 5 volts) we need analog output. We can vary the brightness of an LED directly from a microcontroller. Microcontrollers do not directly supply variable voltage. Instead they pulse the output pin on and off really fast. If you blink an LED fast enough the LED will appear to be on continuously.

 

 

 

PWM (Pulse Width Modulation)

 

 

 

With Pulse Width Modulation (PWM) the output is pulsed between 0 and 5 volts periodically. By varying the duty-cycle or the ratio of time on to time off, the voltage seen by certain components will also vary. A 100% duty-cycle would be 5 volts, a 50% duty-cycle would be 2.5 volts and so on. The brightness of an LED will vary with the effective voltage from a PWM controlled pin.(2.5 volts will light an LED at roughly half its normal intensity).

 

 

Analog Output (PWM) Circuit and code

 

 

 

 

Active HIGH LED circuit (Vss is ground). Use one of the PWM digital outputs (pins 3, 5, 6, 9, 10 and 11).

 

 

Fade LED on pin 9 using PWM. This patch will work with either active LOW or HIGH circuits. AnalogOutPWM.pd