There is something very satisfying about physical knobs and buttons. Unlike various software sliders that you drag with your cursor, you can feel when a real button clicks and get a perfect sense of scale when you rotate a physical knob even without looking at it. In this article, we’re going to 3D print a smart oversized USB volume knob! An infinitely rotatable and clickable dial that can play/pause your current song or skip to the next one on double click without you ever leaving the currently opened application!

The basic idea

We’re not going to route the audio signal through the knob physically. If you, for example, route the signal through a potentiometer to adjust the volume, you’re unavoidably going to degrade the signal. Instead, our volume knob will behave very much like a keyboard with media control keys. We’re going to send keystrokes to the operating system, which will then handle the rest. This works really well because your OS knows whether you have Spotify or similar application running, so it will simply forward the command to it. And it works on all Windows, Mac and most Linux distros.

3D printing the knob

Let’s start with what you probably understand the best, 3D printing. We’ve prepared a few different versions of the knob you can choose from with ready to print G-codes and 3MF project files at PrusaPrinters.org.

The knobs are interchangeable, so you can pick any one of these and use it with any of the knob bodies. If you create your own, don’t forget to share it with others. 🙂

The hardware

We need just 2 components!

The rotary encoder is actually the same component that’s under your 3D printer’s control knob. It spins. Indefinitely – which is awesome! No need to handle what happens, when you reach the end. It also clicks! When you press it, the rotary encoder behaves just like a button. This opens up a surprising amount of control because you can map different actions to a single click, double click or long-press.

And the Arduino?

Arduino basics

We’re going to assume you have no experience with Arduino boards what so ever. If that’s not the case, feel free to skip a bit further down this article.

Arduino is an open-source project (yay), responsible for a variety of single-board microcontrollers. Think of them as small computers. These boards are equipped with analog and digital input/output (I/O) pins, so they can interact with the world. Read data from a temperature sensor, send a signal to turn on the fan, check if the temperature dropped… all kinds of stuff. And there are many different types of Arduino boards. Some are big with tons of I/O pins and a wide range of input voltage like Arduino UNO, which is great for prototyping. Some have fewer I/O pins, but they are incredibly small (Arduino Pro Micro).

Using Original Arduino boards?

Just like Original Prusa 3D printers, Arduino project is open-source. If you search online, you’ll be able to find clones of original Arduino boards for as little as $2. So why spend more on the originals? In short – build quality, documentation, development. Without investment into development, there won’t be any innovations. You can clone a board over and over, but eventually, you’d want things like new more-power efficient Bluetooth or Wi-Fi support, better development software with a nicer UI or a faster processor. So at least consider buying an original Arduino board. 🙂

With that said, some of the clone boards with fewer I/O pins, unsoldered header pins and smaller size can actually come in handy – for example in our case of building a compact volume knob.

In our case of building an oversized volume knob, the microcontroller’s job is to read the input from the rotary encoder and translate it into a keystroke. All Arduinos have a basic keyboard emulation functionality built-in. However, unlike the Arduino Uno or Nano, which use USB to Serial adapter, the Arduino Pro Micro supports USB directly thanks to the ATmega32u4 microchip. This is important! The media control keys won’t work on Arduino Uno/Nano (unless you reprogram the microcontroller). Besides, as the name suggests, the Pro Micro is really small and has a micro USB connector, so we want to use it anyway.

Wiring

Since we have only two components to connect to each other, it’s really simple. Connect the pins labeled GND (ground) to GND and plus to VCC (5V). Then there are two pins that handle the rotation, usually labeled CLK and DT, connect them to analog inputs labeled A0 and A1. Finally, there’s the button pin labeled SW – connect it to the analog input A2.

If the labels on your rotary encoder are different, don’t worry. You can simply try to switch the 3 cables connected to analog inputs once we upload the code.

You can use female-to-female jumper wires, which are ideal for testing things out. Once everything’s working, consider soldering cables directly to the board. That way, they’ll stay firmly in place, and you can save some space by getting rid of the Pro Micro’s pins. Or even better: grab a new Arduino without pins soldered to it. Then you can put cables through the tiny holes, where the pins would normally be, which makes the soldering job way easier and the resulting size smaller. And you can keep the Pro Micro with the pins attached for prototyping of your next project.

Programming the Arduino

We have the code ready for you! Unlike, for example, 3D printer firmware, it’s not common to share pre-compiled code for an Arduino. Instead, we share the source code, so that anyone can make changes to the code or choose a different target board. That means you will have to compile the code before uploading it, but that’s fairly simple.

  1. First, download, install and open the Arduino IDE
  2. Then download the code for the oversized volume knob
  3. Open the downloaded code In Arduino IDE (File – Open)

The code uses a custom library “HID-project” that has definitions of the media control keys and makes the code really easy to understand.

  1. In the top toolbar select Tools – Manage Libraries
  2. In the new window, type “HID-project” into the search bar
  3. Click on the HID-project by Nicohood and select Install
  4. You can now close the Library Manager

We’re also going to use another library (actually two of them) for reading the data from the rotary encoder. The first one is called “TimerOne” and you can install it exactly the same way, as described above, except that you search for “TimerOne” instead of “HID-project”.

The other library called “ClickEncoder” has to be installed manually.

  1. Download the ClickEncoder library here
    1. Use the green button Clone or download – Download ZIP
  2. Select Sketch – Include library – Add .ZIP library and choose the file downloaded in step 1

Now we just have to tell Arduino IDE which board we’re using and to which USB/Serial it should upload the code.

  1. Select Tools – Board and select the Arduino/Genuino Micro
    1. If you’re using a different board, make sure you change it here
  2. Connect your Arduino Pro Micro to your computer
  3. Select Tools – Port
  4. You should see COM1 and COM? (Arduino/Genuino Micro), where ? is some number other than 1 (e.g. COM6)
  5. Select the COM? (Arduino/Genuino Micro)
  6. Hit the Upload button

That’s it! Once the upload finishes you can test your volume knob. If rotating it changes the volume in the wrong direction, simply switch the two cables that handle the rotation (CLK and DT). Or change VOLUME_UP to VOLUME_DOWN and vice versa in the code. The default behavior is single-click for play/pause, double-click for skipping to the next song.

Analyzing and changing the code

We took the time commenting the code to make each part as clear as possible. The main structure of every Arduino code looks like this:

  1. Definitions of pins and variables
  2. setup() function that runs once after the Arduino board boots up
  3. loop() function that repeats over and over until the power is cut

Feel free to change anything in the code and see what difference it made.

Summary

We now have a functional 3D printed media control knob! Once you get used to it, you won’t be able to live without it 😉 Just during the writing of this article, I reached for it so many times only to realize it’s in the studio for the video recording 🙂 Feel free to remix the design and improve it – or change the code completely. And if you do so, don’t forget to share it with others! It would be really cool to get the Spacenav project running on the knob, a compatible alternative to the proprietary 3Dconnexion driver.

Let us know in the comments if you enjoyed this article and share your ideas for the next tutorial! And as always, happy printing!

Community prints & remixes