Monthly Archives: September 2023

Contactless Volume Control

Why can’t a thing be made out of the thing that it controls?

After messing with using Arduino as a HID keyboard for a simple push to talk foot pedal I had the idea to create a USB plug in and play volume control with a novel interface. Using an ultrasonic range-finder I could control the volume by raising and lowering my hand over the ultrasonic beam. The idea of controlling sound with sound tickled me so I set about building a prototype.

I found that the range finders had reliability issues until I put a capacitor across the VCC and ground pins for decoupling and filtering. I had a 470uF capacitor to hand but this was likely overkill for the application but probably doesn’t hurt too much. I also added an RGB indicator LED that would change colour based on the volume set, the higher the volume the warmer the colour of the LED.

With the Arduino HID project library it was simple to send HID keyboard media key presses from the Arduino. I would be using MEDIA_VOLUME_UP and MEDIA_VOLUME_DOWN which each increment audio relatively. Ideally I’d use HID_CONSUMER_VOLUME instead for an absolute scale.

I programmed the control to work between 10 and 40 centimetres above the range-finder which corresponds to 0 to 100% volume. Putting your hand into the beam below 10cm mutes the volume. As there’s no way for the device to know what the volume of the computer currently is it sends 100 MEDIA_VOLUME_DOWN requests so it can be reasonably sure the starting volume should be zero. Pulling your hand horizontally out of the beam, headroom depending, gives a value greater than 80cm which it interprets as no reading, the existing value from when your hand was in the beam is held.

I added a rolling array of distance readings and averaged them for a bit of hysteresis so that changes would be smoother and errant readings ignored. It was important that the volume not suddenly jump up immediately.

For the real thing I wanted to make it fairly compact so opted to go with an Arduino Pro Micro, which has an integrated USB controller in its ATmega32U4 allowing me to use it as a plug-in-and-play USB HID (Human Interface Device) without any special drivers.

For the enclosure itself I opted to use a diecast aluminium project box and do the brushed aluminium finish that I had used before on the SIP doorbell project. I checked that everything could fit nicely, I could maybe have gone for a slightly smaller enclosure but was happy with the size.

Using a pencil I scribed out the layout, worked out an elaborate way to securely clamp the enclosure as well as back the hole with wood to hopefully reduce the chance of chipping on the back side. Using a centre punch then a pilot hole before the step bit kept the holes properly positioned, I also marked the step bit with tape to show the desired diameter. After drilling I used a countersink to deburr the holes.

With the holes drilled I was then able to offer up the rangefinder to make sure it would work in-situ and not be affected by the aluminium around it. With that confirmed working I moved on to the brushed finish.

I ran the enclosure up and down as a sled between two pieces of wood clamped into position over increasingly fine abrasive paper until eventually reaching the desired finish.

Next came final assembly, I soldered the capacitor directly to the Arduino along with header wire for the pins on the range-finder and the wires for the RGB LED which I potted into a mount for tidy installation. I threaded the micro USB cable through a rubber grommet and put a knot in it as a strain relief. I also made use of a lot of hot glue to hold the range-finder and Arduino in place.