Summary of RGB Rotary Encoder with PWM and ISRs Using an ATmega328
This article details a project using an RGB rotary encoder with an Arduino or ATmega328 microcontroller. It explains configuring pin change interrupts for rotation, external interrupts for the button, and PWM for the RGB LED. The author also demonstrates functionality using three separate LEDs to visualize forward, backward, and push actions.
Parts used in the RGB Rotary Encoder Interface:
- RGB rotary encoder
- Three LEDs
- Resistors
- Arduino or ATmega328 microcontroller
- External pull-down resistor for the switch
Description

Oleg, in one of his earlier posts, explains how to use a rotary encoder with a look up table. Basically the principle works by polling the current port and comparing to the previous reading. By comparing the previous states of AB to the current we can determine forward or reverse motion. For more detail see Oleg’s post.
Parts
Circuits
This is the suggested R/C filter from the datasheet to help avoid chatter (bounce). There is also a timing diagram in there that describes a time period that would mask chatter. Although the R/C filter should help alleviate chatter the chatter timing mask they mention is only 3ms, so a little chatter should not really effect anything (depending on what your ISR will do).
- How do I determine forward or reverse motion?
By polling the current port and comparing it to the previous reading of pins A and B. - Can I use separate LEDs instead of the RGB encoder?
Yes, you can use three LEDs with resistors if you do not have an RGB rotary encoder. - What is the purpose of the R/C filter mentioned?
The R/C filter helps avoid chatter or bounce on the signal lines. - Which pin is the common anode on the encoder?
Pin 5 is identified as the common anode. - Where should the switch terminal be connected?
Terminal C goes to ground, and the switch itself requires a pull-down resistor. - Does the datasheet specify a time period for masking chatter?
Yes, the timing diagram describes a time period that would mask chatter, noted as 3ms.

