Skip to content

Latest commit

 

History

History
84 lines (54 loc) · 3.93 KB

README.md

File metadata and controls

84 lines (54 loc) · 3.93 KB

Speaker Controller

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.


Bill of Materials

Components and materials I used:


Circuit

This is a rough diagram of the circuit I'm using to control the speakers:
full circuit diagram

In reality, all of the discreet components are part of this board, and connected to the Arduino like so:
simple circuit diagram


Code

Arduino

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.

PC

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.


Housing

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

Images

Fully assembled:
The assembled device

The Arduino and relay are slid into the right side of the housing:
Inside the right side of the device

With the cover on, the USB port is accessible from this side of the device:
Inside the right 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:
Inside the left side of the device

The terminals can be tightened down through a small hole in the top of the housing:
Top of the device

You can find full-size versions of these images in the images directory.