Automatically turns my desk speakers on/off when I change the audio output in Windows.
Well, that's what I'm using this project for anyway. Although, it's essentially just a smart power bar - you can use it to switch any household appliance on/off.
Warning
This project deals with dangerous mains voltages. Do not attempt to replicate this project unless you are experienced with the hazards involved and are using the appropriate safety equipment.
Components and materials I used:
- Duinotech Leonardo Tiny
- Arduino Compatible 5V Relay
- This random power bar
- 10⨯ M2.5⨯9 self-tapping screws
- ~20m/~60g of 1.75mm filament
This is a rough diagram of the circuit I'm using to control the speakers:
In reality, all of the discreet components are part of this board, and connected to the Arduino like so:
Code for the Arduino is located in the sketch
directory.
This program simply listens for characters being sent by the USB host and toggles the relay's state accordingly. If the program receives a '1'
the relay is turned on, '0'
the relay is turned off. The program also needs to receive a heartbeat message ('2'
) at least once every 5 seconds for the relay to stay on.
The script to be run on the connected PC is in the controller
directory.
This script runs in the background, polling the registry for updates to the default audio output device. When the default device changes to one of the specified "active" devices, it instructs the Arduino to turn the relay on. When the default device changes to one of the specified "inactive" devices, it instructs the Arduino to turn the relay off.
Tip
You can customise the list of "active" and "inactive" audio devices in the config file.
Note
You'll need to run cd controller && npm i
before running this script for the first time.
The models
directory contains some housing models that fit with my particular power bar.
You can also find the model source on OnShape.
I printed these with eSun White PLA+, and the following settings:
- 0.4mm nozzle
- 0.2mm layer height
- 3 wall layers
- 15% infill density
The Arduino and relay are slid into the right side of the housing:
With the cover on, the USB port is accessible from this side of the device:
On the opposite side, the two ends of the live wire are inserted into the screw terminals on the relay board:
The terminals can be tightened down through a small hole in the top of the housing:
You can find full-size versions of these images in the images
directory.