5.1 Pulse width modulation (PWM)

Uncategorized — roguescience @ 3:03 pm

Now what if we want to have a LED fade in or out? The Arduino only has ANALOG INPUTS.  DIGITAL pins can be configured as INPUTs or OUTPUTs but a DIGITAL OUTPUT can only output 0V (LOW) or 5V (HIGH). Luckily, there is a solution to this problem with a bit of electronic trickery called Pulse Width Modulation (PWM).

PWM sends DIGITAL values very rapidly to a DIGITAL OUTPUT to emulate an ANALOG signal - this is done by setting one of the PWM pins on the Arduino (3,5,6,9,10,11) to OUTPUT and using the AnalogWrite() function. AnalogWrite() takes a value between 0-255 (8-bit) and produces output that emulates voltages between 0 and 5V.

More details for those interested in the nitty gritty of PWM:

The duty cycle represents what percent of the time 5V (HIGH) is written. For example if the OUTPUT is 0V (LOW) for 90% of the time and 5V (HIGH) for 10% of the time then the duty cycle is 10% which emulates 0.5V.

0 Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2010 Roguescience Arduino Tutorials | powered by WordPress with Barecity