USB Volume Control

19,250

256

33

Introduction: USB Volume Control

In this project, we'll build a USB volume control using an Arduino compatible Trinket from Adafruit, and a rotary encoder. Finally, we'll 3D print a housing, fill the base with lead shot to add weight and stability, and laser cut an acrylic bottom cover.

The Arduino code and underlying design were originally found on the Adafruit website. More information can be found Here. The Arduino code will require the Adafruit Trinket libraries, which can be downloaded Here (You'll specifically want the "TrinketHidCombo" library). The actual Arduino code can be downloaded Here.

Step 1: Gather Your Parts

(Hover over the items in the photo for details and links to order):

  • Adafruit Trinket, 5V, 16MHz (be sure to get the 5V version, NOT the 3.3V one).
  • Rotary Encoder (the one shown here is a D-shaft, but there are also encoders with splined shafts, depending on the knob you use)
  • About 2.5" of 5 conductor ribbon cable. Strip and tin the ends as shown in the photo.
  • Five 1/2" long pieces of 1/8" heat shrink tubing.

Step 2: Wiring the Trinket to the Rotary Encoder

The rotary encoder has five pins - three on one side, and two on the other. The two pins on the one side are for the button. They make contact when the encoder's shaft is pressed. This will become the mute function. These pins are not polarity sensitive, and there is no difference in how the button wires connect to them. The three pins on the other side are the signal pins. If you hold the encoder facing the side with the three pins, with the shaft pointing up, the left pin is Signal "A", the center is Common and the right pin is Signal "B". This is also shown on the photo of the data sheet.

Wire the Trinket to the encoder as follows:

  • Trinket Pin #0 to encoder's "A" signal pin.
  • Trinket Pin #1 to one of the encoder's button pins.
  • Trinket pin #2 to encoder's "B" signal pin.
  • Trinket pin 5V to the other encoder button pin.
  • Trinket pin GND to encoder's common pin.

Be sure to slip a piece of heat shrink tubing over each wire before soldering, and slide it as far over the pin as possible before shrinking it. The base will later be filled with lead shot, and these pins need to be as insulated as possible because they will be in contact with the shot when finished. A good tip is to further insulate the encoder pins between the shrink tubing and the encoder with a dab of hot glue.

Step 3: Prepare for Programming the Trinket

Open the Arduino IDE. Download and install the Adafruit Trinket libraries, and the volume control code (links in the beginning of the project). Set the Board Type as "Adafruit Trinket 16MHz", and the Programmer as "USBtinyISP".

The Trinket must be in Bootloader mode in order to upload code to it. When first plugged into the computer's USB port, the green LED will come on steady and the red LED will blink for 10 seconds and then go out. During this 10 second window, the Trinket is in Bootloader mode. You can enter the Bootloader mode at any time by pressing the button at the end of the Trinket opposite the USB port.

I've found that the Arduino IDE takes a bit longer than 10 seconds to compile and verify the code before being sent to the board, so when you send the code to the board, watch the green progress bar in the lower right corner of the IDE window. When it's at the halfway point, press the reset button on the Trinket. The video above shows the green progress bar. When it's about half way, I press the reset button on the Trinket. As long as the green progress bar gets all the way to the right before the 10 second window closes, the Trinket will accept the code. You can see the code transferring by the red LED going solid before turning off. If the transfer doesn't start before the Bootloader time ends, you will see an orange error message on the Arduino IDE. If this happens, just repeat the sequence and try again.

Step 4: Testing the Encoder

Once the programming completes successfully, and the Trinket reboots, you will be able to control your volume with the rotary encoder. Rotating the encoder clockwise should increase your computer's volume, and counter-clockwise should decrease it. Pressing the shaft should mute your computer. If you find that the direction of rotation has the opposite effect (volume increases when it should be decreasing), then you have the encoder "A" and "B" leads reversed. You can either swap the wires at the encoder, or just swap the pin definitions (0 and 2) on lines 3 & 4 of the Arduino code, and then send it to the Trinket again. In the video clip above, you'll see the rotary encoder controlling the volume and mute on the PC.

Step 5: 3D Printing the Base

The 3D Printing file can be downloaded from Thingiverse by clicking Here. I printed it using PLA, 0.15mm layer height and an 0.4mm nozzle. The rectangular block just outside the base in the print file is only used to minimize support material on the outside, since that support would be too thin and tall to remain stable while printing. Use concentric supports everywhere. The only difficult to remove support material is under the bridge that supports the Trinket. I use a combination of small screwdriver, angled tweezers and needle nosed pliers to remove it. It's important to get it out (or at least as much as you can), because that space will later be filled with lead shot.

Step 6: Add the Electronics

Install the Trinket in the base. All of the mounting holes in the 3D printed base are sized for 2-56 screws to self tap. Use two 2-56 x 1/4" screws to fasten the back end of the board. If you want a pack of 100 screws, they can be purchased from McMaster Carr by clicking Here.

Alternatively, if you'd like to buy just what's needed to build your project, a set of screws (for both the Trinket and the bottom cover), as well as the laser cut acrylic cover, rubber feet and optionally the lead shot can be purchased together from my eBay page -- Edit: I no longer have the eBay listings up, because eBay made me remove any of my listings containing lead shot as they consider it ammunition (even if used as weight or ballast). If you're interested in purchasing any of the hardware parts (i.e. screws, Acrylic bottom, rubber feet, lead shot, etc. -- anything but the electronics and knob), message me here (Click my image next to my name at the top of the project, then click the Message button).

Insert the rotary encoder through the hole in the top of the base, add the flat washer and nut and tighten securely.

Step 7: Add Weight to the Base

The base is filled with #7.5 (0.095") lead shot to add weight and stability (about 6 ounces, or 175 gm). This prevents it from slipping around on your desk when you rotate the knob.

Be sure to avoid getting any shot in the cavity where the Trinket is housed. Use angled tweezers to "push" the shot under the bridge, and fill it up to the tops of the bottom plate mounting posts and the walls surrounding the Trinket cavity. Level it out. You want the base to be full enough that it doesn't sound like a maraca when you shake it, but not so much that the bottom cover won't sit flush when installed.

Step 8: Make and Install the Bottom Cover

The DXF file for the bottom cover is included in the Thingiverse page for the base, or click Here for a direct link to the file for the bottom cover. I laser cut it out of 3mm (1/8") acrylic. You can use the same 2-56 x 1/4" screws as you used for mounting the Trinket to attach the bottom cover. Optionally, you can countersink the holes and use flat head screws so the bottom is flush. If you choose to use flat head screws, you can also order a 100 pack from McMaster Carr by clicking Here.

Finish off the bottom by adding four clear rubber feet to prevent slipping.

Step 9: Finish Up

Add a 38mm diameter knob of your choice. The knob I used can be purchased Here. Note that this knob has a set screw, so it is intended to be used with a D-shaft encoder. If you chose to use an encoder with a splined shaft, be sure to select a knob that is for a splined shaft. The knob's shaft hole will have matching splines, and not be smooth. You can choose any knob you like, as long as the outer diameter is 38mm, and it's compatible with the 6mm shaft of your encoder.

Finally, plug your USB cable in, give the computer about 15 seconds to detect the device (the Trinket has to get through its 10 second Bootloader sequence before the PC will detect it), and you're all set.

Epilog Challenge 9

Participated in the
Epilog Challenge 9

First Time Author Contest 2018

Participated in the
First Time Author Contest 2018

1 Person Made This Project!

Recommendations

  • Pi Day Speed Challenge

    Pi Day Speed Challenge
  • Trash to Treasure Contest

    Trash to Treasure Contest
  • Microcontroller Contest

    Microcontroller Contest

33 Comments

0
dhan27
dhan27

Question 8 months ago

mine's not working using an EC11 encoder. i followed the pin layout where pin 1 = pin c. what am i missing? plus im having this issue.

Update: volume control seems to be working on a laptop but not in my desktop, tho the push button is not working on both.

EC11 error.PNG
0
dhan27
dhan27

Question 9 months ago on Step 9

nice instructable! i wanna do this but supplies are very limited in my country. will EC11 module work as rotary encoder?

1
spepin
spepin

Answer 9 months ago

It looks like the EC11 should work fine. You will have to adapt the EC11 pins to their proper counterparts in the project though.

0
saadland
saadland

Question 1 year ago

Hello.
I am want to make such volume knob, but I would like it to be less, if possible.
Did somebody did manage to make it; or though about it.
I am looking for a bluetooth module that can handle HID, to transmit keyboard data, and a battery for it to be wireless.
Can somebody recommand some advices module please:
Thx

0
EdyW
EdyW

1 year ago

Hi... Can this be done with adafruit Trinket M0? I cant find trinket mini 5v in my country.... thanks

0
NikS29
NikS29

Question 1 year ago on Step 9

Hello Hi, I have question about the mute option from the encoder. When I try to press the encoder the sound start to flicker and is going to mute but on second even third try is not stable maybe you know what is the issue.

0
amscastro
amscastro

2 years ago

Hi. I´m not able to send to the trinket. Gives me this error:

avrdude: Error: Could not find USBtiny device (0x1781/0xc9f)

Any idea? I am using Board Type as "Adafruit Trinket 16MHz", and the Programmer as "USBtinyISP", as instructed.

Many thanks.

0
DavidF14
DavidF14

Question 2 years ago on Step 3

I'm stuck on step 3. I've followed all the instructions, including loading in the adafruit boards, and trinket hidcombo libraries. When trying to send code, while the trinket is in bootloader mode, I have been getting an error.

avrdude: Error: Could not find USBtiny device (0x1781/0xc9f)

I double checked the USB port and the cable.

0
DavidF14
DavidF14

Answer 2 years ago

Apologies, not sure how to delete this question now. I got it to work, I used the code the adafruit tutorial. I also was having an issue timing the upload button and bootloader button.

0
spepin
spepin

Reply 2 years ago

Good catch -- you're right. This project was designed for the standard (non-Pro) version of the Trinket. I'm not sure how that slipped in there, but I've edited the project to remove the Pro reference.

0
JaseRuss
JaseRuss

Reply 2 years ago

It’s cool I was cursing you as if bought the pro :) but it’s cool I found the info for that board so it’s all good

0
DavidF14
DavidF14

Reply 2 years ago

Crap. I already have a Pro trinket. Looks like it's larger than a non-pro. So it won't fit in the enclosure. The rotary encoder is the same, I believe.

Could you post the CAD file so it can be edited? (not just the STL)

0
spepin
spepin

Reply 2 years ago

I created this in TinkerCAD, so I can only share a temporary link that will expire in 14 days. Here's a link to the file, but it can only be edited in TinkerCAD. Considering the effort involved in making the change (which may be complicated by the fact that a longer board and the overhang reguired to support it will interfere with the location of the encoder and may make it impossible to install the encoder), you might just be better off just spending the $6.95 on the smaller Trinket.

https://bit.ly/2JI02Zt

0
DavidF14
DavidF14

Reply 2 years ago

Yeah, I was thinking about that too. Seems like way more work. I guess I'll just hang on to it for another project. Thanks!

0
DavidF14
DavidF14

2 years ago

What AWG are the conductors in the ribbon cable?

0
ljcorky
ljcorky

2 years ago

will this work with one of these?https://rover.ebay.com/rover/0/0/0?mpre=https%3A%2F%2Fwww.ebay.co.uk%2Fulk%2Fitm%2F222731225594

0
spepin
spepin

Reply 2 years ago

The code would most likely work with that as well. You’ll have to revise the pin call outs in the code though to match your situation. Of course, you’d also have to modify the enclosure design as well.