Ultrasonic Music Control

A small, driverless device that allows you to control your music with the wave of a hand.

Similar projects worth following
After reading a HaD post about a radio that can be controlled with geastures, i needed to built my own one. But as i mostly listen to music with my PC i just needed a Ultrasonic Sensor that plugs into the USB port.
Ofcourse i had a HC-SR04 Ultrasonic module lying around. So i built this project in about a Week, with components that totally cost only about 5$. It conveniently doesnt need any drivers.

At the moment is features only 4 functions, Volume Up, Volume down, Play/Pause and a mechanical button to enable or disable the Sensor. And two Leds that show if the sensor is turned on or off.

I would personally like to see more people to contribiute to this project as it is extreamly simple apart from the USB-HID software part :)


The hardware is fairly simple the Project uses only a very small amount of components that cost only about 5$...

The Attiny2313 is clocked by a 16mhz oscillator that produces a precise frequency necessary for the USB communication. The USB port is connected to PD3 and PD2 with two 68ohm resistors, as in the VUSB example cuirit. Two Leds are connected to PB2 and PB1 and a Button to PB0. The interesting part is the power supply, because a USB port expects a high data line at 2.7 to 3.6volt instead of the 5V supplyed by the connector so there are two diodes in series that reduce the voltage for the microcontroller to about 3.6v.

For the prototype i used a square perfboard with 45mm side length. But i also layouted a PCB that fits with 20mmx45mm directly below the sensor.

When im done with the SMD version i will propably 3D print a nice case for the sensor.


Possible gestures at the moment:

As i use an AVR microcontroller the best way to get USB is VUSB, a open and free USB library for these micros. With the help of this Library i implement a "USB HID Consumer device" as its wildly used in Keyboards with special functions like Volume Buttons. And it also enables it to be driverless on most Operating systems (Windows, Linux...)

The software is a very simple proof of concept at the moment, it just polls the hardware button and if its not muted also the ultrasonic sensor. To do this it sends a trigger signal and counts then the responding pulse length. Depending on this pulse length the right keycode is then selected. And sent in the next step. Tho prevent multiple readings it then sleeps for 300ms and also turns booth LEDs on in this time to give a feedback. If the Hradwarebutton instead is pressd it only toggles the led and the mute variable. What is really important is that the whole time and while every waiting period the watchdog is continuously reseted.

Ofcourse you could send other keycodes instead with this setup every other keycode in the "Consumer Page (0x0C)" section of the USB HID Table is possible...

Other Stuff:

To do:

  • tidy up the code
  • improve LED feedback
  • finish the layout (change switch to side switch)
  • make a 3D model
  • design a case
  • add more functions?


  • For me as a Teenager i can easily hear a clicking noise that is emitted by the Ultrasonic sensor every time the trigger pin is pulsed. If your older it is possible that you cant hear that noise anymore as your ears degrade...
  • The Attiny2313 is almost completly full, as the hex file has about 5,50kb of the 6kb aviable. So there is propably no space for more functions without tidying the code up.
  • I can only increase and decrease the volume, as windows(atleast win7) doesnt allow absolute inputs, so cool swinig your hand through the air is not possible at the moment.

  • 1 × HC-SR04 Ultrasonic Sensor module
  • 1 × Attiny2313 Microprocessors, Microcontrollers, DSPs / ARM, RISC-Based Microcontrollers
  • 1 × USBport You can use any type that you want..
  • 2 × LEDs in your desired colours..
  • 1 × Button That makes Click! :D

View all 9 components

  • Creating the case

    Lloyd300008/23/2014 at 10:56 0 comments

    Right now i try to crreate a case thats stylish and also cheap to print on shapeways for example.

    I will add later more information...

  • Creating a 3D model

    Lloyd300008/23/2014 at 10:54 0 comments

    The next step is to create a 3D printed case for the PCB and the sensor. But to do this i first created a 3D model of the hole assambly to thest everything first. And as it turns out it really was a good idea:

    As you can see i forgot the mounting holes in the PCB...

    For the 3D software i use SolidEdge as i learnd how to use it in shool and is aviable for free for students.

  • Creating a cuirit diagramm

    Lloyd300008/23/2014 at 10:50 0 comments

    Ofcourse i have to publish the cuirit diagramm so others can easily build their own Ultrasonic switch:

  • Laying out the PCB

    Lloyd300008/23/2014 at 10:48 0 comments

    at the moment im working on the layout for the pcb. I decided to use smd components as you can see in this picture: 

    With these smd components i can get the hole thing fit below the HC-SR04 sensor. But still i need a double sided PCB, and ony have exposed pads as programming port...

    But on the otherhand beacause the PCB is that small it will be very cheap to manufacture in china :)

View all 4 project logs

Enjoy this project?



Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates