picture this: you have two separate audio output devices on your computer - speakers and a pair of headphones. modern audio drivers allow you to attach these two devices to different audio ports on your computer (back plate and front i/o) and have them show up as separate, selectable devices in windows.
that in turn makes it possible to switch between these devices via software - by clicking the loudspeaker icon in the windows tray bar and selecting the one you'd like to set as the default output device.
now imagine that you don't have to do these three clicks. that's where this piece of software, along with a bit of hardware, comes into play.
you will need:
- a windows computer with the aforementioned driver settings
- a headphone stand that you hang your headphones on whenever you're not using them
- an arduino uno-compatible microcontroller board (or, if you rewrite that part, any)
- a force sensitive resistor (e.g. FSR-406)
- a few wires, another resistor and a usb cable
the idea is to:
- attach the FSR to the headphone stand, so that whenever your headphones weigh down on it, there is a measurable change in resistance
- measure this resistance with a small circuit on the microcontroller
- relay this information via the usb cable to the computer
- have FSRAudioSwitcher switch the devices whenever the measured resistance goes under or over a certain threshold.
- assemble the hardware
- connect it to the computer
- program the microcontroller
- start up FSRAudioSwitcher
- right-click on the tray icon
- select the devices to switch between, filling the roles of speakers and headphones
- select the COM port that represents the microcontroller
- check the resistance measurements when your headphones are resting on the FSR. pick something slightly higher as the threshold.
- done
this repository consists of two components; the FSRAudioSwitcher which runs on your computer and speaks to the microcontroller via a COM port, and a small program that your arduino is programmed with to periodically take measurements of the resistor to supply the computer with.
this piece of software includes the windows-side logic to control the audio device and read measurements sent from the microcontroller board.
FSRAudioSwitcher will display a tray icon from which you can control its settings as well as view the current resistance measurement.
a left-click will dis- or enable the switching functionality.
the included .ino file contains some simple logic for calculating the current resistance exhibited by the FSR, based on a voltage divider circuit. this data is measured every 200ms and relayed via serial connection to the host computer, where it is read by FSRAudioSwitcher.
Depending on your hardware setup, you will need to change some of the variables.
analogPin
is the pin on the microcontroller that will do the analog-to-digital conversion and let the program read the voltager1
is the resistor opposite the FSR, required to calculate the latter's resistancevin
is the voltage used on the circuit
note that you can also change the delay between measurements, but be advised that it should remain under the read timeout set in FSRAudioSwitcher (2000ms at the time of writing). 200ms are nice and responsive and still leave the microcontroller sleeping most of the time. additionally, the serial port baud rate must be identical to the one set in FSRAudioSwitcher.
here's a quick schematic on how to connect the voltage divider circuit. ports to the left connect to the arduino.
for the FSR, i used an FSR-406 off amazon. my microcontroller is a cheap 6€ arduino uno clone off ebay. it is connected via usb to the computer.