This project turns a cheap Digispark ATtiny85 USB dongle and a KY-040 rotary encoder into a dedicated hardware volume knob. Rotate clockwise for volume up, counter-clockwise for volume down, press to mute. It enumerates as a standard USB HID Consumer Control device — no custom driver, no desktop app. Linux, Windows, and many Android devices recognise it out of the box.
Last updated: February 18, 2026
Why Build This?
Keyboard shortcuts work, but a physical knob is better when you are:
- Switching between headphones and speakers
- On a call and need instant mute
- Using a media PC or mini server with no easy keyboard access
- Tired of digging into software mixer panels
For around 5–10 USD in parts you get a dedicated hardware control that is always there.
Parts
- Digispark ATtiny85 USB board — ~2 USD
- KY-040 rotary encoder module — ~1 USD
- Jumper wires (female-to-female) — ~1 USD
- Optional: 3D-printed case or aftermarket knob for a cleaner finish
Wiring
| Rotary Encoder | Digispark ATtiny85 |
| CLK | P5 (PB5) |
| DT | P2 (PB2) |
| SW | P0 (PB0) |
| + | 5V |
| GND | GND |
ATtiny85 pin mapping used by this project:
+-\/-+
ENC_A (CLK) PB5 1| |8 Vcc
USB D- PB3 2| |7 PB2 ENC_B (DT)
USB D+ PB4 3| |6 PB1
GND 4| |5 PB0 ENC_SW (SW)
+----+
Note: PB5 is used as GPIO for encoder input in this design (RSTDISBL fuse context applies when programming bare chips). Digispark boards typically ship in a suitable configuration already.
Firmware
The firmware sends standard HID Consumer Control usages:
| HID Usage | Function |
0xE9 |
Volume Increment |
0xEA |
Volume Decrement |
0xE2 |
Mute |
Because these are standard HID usages, the host OS handles them natively — no custom driver needed.
Build and Flash
Clone the repository and build the firmware and uploader:
git clone https://github.com/hackboxguy/attiny85-hid-rotary-knob.git cd attiny85-hid-rotary-knob make all
This builds main.hex (firmware) and tools/micronucleus/micronucleus (uploader).
Flash via Micronucleus bootloader:
make upload
Tip: After running make upload, you will see "Waiting for device...". Plug in the Digispark within 60 seconds — the upload starts automatically once the bootloader is detected.
If your setup does not require sudo:
make upload SUDO=''
Note: Digispark boards come with the Micronucleus bootloader pre-installed — just plug in and upload. This blog assumes a board with a working bootloader. If you have a blank ATtiny85 chip without Micronucleus, flashing the bootloader requires an ISP programmer and is outside the scope of this guide.
Build prerequisites: Install gcc-avr, avr-libc, binutils-avr, libusb-1.0-0-dev, and pkg-config before running make.
Platform Compatibility
Linux
Works out of the box as a USB HID media control device. Desktop environments map it immediately to system volume and mute. Good fit for Ubuntu/Debian desktops, Arch with Wayland or X11, and Raspberry Pi media boxes.
Windows
Also works without drivers as a standard media-control device. If you briefly see "USB device not recognized" right after plugging in, that is the short Micronucleus bootloader window before the firmware enumerates. After handoff, the knob works normally.
Android
Works on Android devices that support USB OTG and HID media keys. You need a USB-C OTG adapter (or Micro-USB OTG on older phones) and OTG host support enabled on the device.
Android caveats: Behaviour can vary by OEM/ROM. Some devices only react when the screen is unlocked, and mute handling may differ across apps.
Troubleshooting
- Build fails with missing AVR tools — Install the prerequisites listed in the Build and Flash section above.
- Linux
error -71during USB enumeration — Reflash or repair the bootloader. See the repository troubleshooting section. - No response to rotation — Check CLK/DT wiring first (most common issue), then confirm the encoder module GND and 5V connections.
Going Further
The firmware is intentionally simple and stable, but the hardware supports extensions:
- Multi-mode knob (volume / media transport / brightness)
- Long-press and double-click actions
- Mode indicator LED
- Additional HID report descriptors
Start with a practical tool, then evolve it into a custom desktop controller.
SOURCE CODE




No comments:
Post a Comment