Protostack educates us on Pulse Width Modulation.

Tutorial Type:

Tutorial Difficulty

Parts Required

Tools Required

Protostack, AVR, Pulse Width Modulation, PWM, Arduino, C++

ATmega168A Pulse Width Modulation Tutorial



Protostack is back with another AVR tutorial. In this installment Daniel covers everything you need to know about PWM and gives you 3 examples using an Atmega 168. The first two use the existing PWM pins and are fairly common for the experienced AVR enthusiast, the third example however is quite interesting and shows us how to use timer interrupts to create 3 more PWM lines. Keep reading after the jump....

"Dimming an incandescent bulb is easy. Simply adjust the current down using a potentiometer and you are done. Dimming an LED is another story entirely. When you reduce current through an LED there are unintended consequences like color shifts and dropouts. A better way is to use Pulse Width Modulation (PWM).


With PWM the LED is turned on and off many times per second. By adjusting the percentage of on time vs off time, the brightness of the LED can be controlled. The diagram below shows 4 PWM wave forms with varying duty cycles. The 90% duty cycle example would produce the greatest brightness whilst the 10% duty cycle will produce the least. The selected period should be sufficiently short so that a flicker isn’t noticeable."

Protostack, PWM, AVR, Arduino, C++


To read the full tutorial visit Protostack.com and while you are there check out one of their Atmega 168 Dev kits, USBASP AVR programmer or their stackable prototyping boards.

Other Articles You Might Like

Review: Lulzbot AO-100 3D Printer part 1Lulzbot AO-100 / AO-101 reviewed

Tutorial: DIY Telescope to PC CableDIY Telescope to PC Cable

Project: LED Strip Bench LightingDIY RGB LED Strip Bench lighting

Review: ISO-TIP Portable  Soldering KitISO-Tip Portable Soldering Kit Review

Article: Arduino Due Overview

Project: 3D Printed Balloon Powered CarPrint a Balloon powered Jet Car with your 3D printer