Skip to main content

Rotary Encoder Module

Introduction

A rotary encoder module is a simple way to add a physical knob to a Raspberry Pi Pico project.

Unlike a potentiometer, a rotary encoder does not output one analog voltage level. Instead, it sends pulses as you turn the knob:

  • clockwise
  • counterclockwise
  • push button press on many modules

That makes it useful for:

  • menu navigation
  • volume controls
  • scrolling through settings
  • changing values on a display
  • user input for clocks, counters, and dashboards

Components Needed

ComponentQuantity
Raspberry Pi Pico or Pico W1
Micro USB cable1
Breadboard1
Jumper wiresSeveral
Rotary encoder module1

Fritzing Diagram

Add your wiring image here when it is ready.

Recommended image folder:

/img/raspberry-pi-pico/tutorials/rotary-encoder-module

Example usage:

<figure className="docImageCenter">
<img
src="/img/raspberry-pi-pico/tutorials/rotary-encoder-module/rotary-encoder-wiring.png"
alt="Rotary encoder module wiring for Raspberry Pi Pico"
/>
<figcaption>Rotary encoder module connected to Raspberry Pi Pico.</figcaption>
</figure>

Wiring Notes

Typical rotary encoder module pins are:

  • CLK
  • DT
  • SW
  • VCC
  • GND

Example Pico wiring:

  • CLK -> GP14
  • DT -> GP15
  • SW -> GP16
  • VCC -> 3.3V
  • GND -> GND

Your exact pins can change depending on the code you want to use.

Basic Code

Replace this section with your demo code.

# Paste your demo code here

Code Explanation

Import the modules

Explain what modules are being used and why.

Set up the encoder pins

Explain which pins are connected to:

  • CLK
  • DT
  • SW

Detect clockwise and counterclockwise movement

Explain how the code compares the encoder signals to work out direction.

Detect the button press

If your module uses the built-in switch, explain how that part works too.

Example 2 - Show a Counter

Good follow-up example idea:

  • turn clockwise to increase a value
  • turn counterclockwise to decrease it
  • print the current value to the serial monitor
# Add counter example here

Example 3 - Menu Navigation

Another useful example:

  • rotate to move through menu items
  • press the knob to select
# Add menu example here

Common Problems

The value jumps too quickly

Rotary encoders often need a little debounce handling or state tracking to avoid counting extra steps.

The direction is backwards

Swap the CLK and DT pins in the code or wiring.

The button does not work

  • check the SW pin connection
  • confirm whether the button is active-low
  • make sure ground is shared

Nothing changes when the knob turns

  • recheck the GPIO pin numbers
  • confirm the encoder has power
  • verify the module is connected correctly

Good Project Ideas

Once the rotary encoder is working, you can use it for:

  • LCD or OLED menu control
  • alarm clock setting
  • LED brightness adjustment
  • selecting modes in a project
  • digital volume-style interfaces

Summary

A rotary encoder module is one of the best ways to add simple physical control to a Raspberry Pi Pico project.

With just a few GPIO pins, you can detect:

  • clockwise rotation
  • counterclockwise rotation
  • button presses

Once you send over your demo code, we can turn this template into a finished tutorial quickly.