Multi-Room Audio Control with Raspberry Pi (2014)
My parents’ house has a whole-house audio setup where an amplifier can drive built-in speakers in each of 5 rooms. This system is great for background music during dinner and parties, but we’ve rarely used it: it’s a hassle to go to the room with the sound system every time we want to turn it on, change the song, station, or volume, or turn a room on/off.
As a winter break project, I put together a controller using the $35 Raspberry Pi computer and some custom hardware and software. From a mobile Web interface, you can:
- Switch room speakers on and off using a custom-built relay board.
- Control the sound system. You can switch between CD, AM/FM, and Aux inputs, change the volume, change the track/station, and turn the system on/off. The controller emits IR signals that simulate the sound system’s remote control.
- Stream music to the system using Apple AirPlay. You can play Pandora, YouTube, or your own music from any iPhone, iPad or Mac on the network.
Here are some photos and screenshots of the final result.
The Setup
The original sound system was hooked up like this:
Here is how the new system is hooked up:
I modified the speaker selector box by inserting relays in parallel with the original switches. If either the relay or the physical switch is on, that room’s speakers will be on. The Pi’s analog audio output is also fed back to the sound system’s Aux input for AirPlay output. Finally, the Pi can also control the sound system with IR commands.
Hardware
- Raspberry Pi Model B. A 700 MHz ARM-based Linux computer with 512 MB RAM. Ten programmable GPIO pins control the five relays: simply pulse the on or off coil for ~50ms. Another GPIO controls the IR diode.
- IDE cable connector. I cut up an old 40-pin IDE connector to connect to the 26-pin GPIO header.
- DPDT latching signal relays. Each relay controls left and right channels (hence dual poles). I opted for two-coil relays, so I could activate one coil to turn the relay on and the other coil to turn it off. (Digi-Key)
- ULN2003A ICs to drive the relays. The Raspberry Pi’s GPIOs can’t drive the relays directly, so we control them with this transistor array. Each chip has 7 NPN Darlington pairs. It also has built-in flyback diodes that will dissipate the inductive kickback from the relay coils. (Digi-Key)
- Stick-on IR diode. I had this emitter lying around. It came with a long cable that terminates in a mono 3.5mm headphone jack. I cut off a female headphone jack from a patch cable to make a plug for this and wired a 270 ohm current-limiting resistor to this.
Edit: Here’s a schematic for the relay board:
Software
I wrote a Python script to control the relays and a Flask/jQuery Mobile web app for control from our phones/tablets. I’ve posted my code on GitHub. This project also leverages other open-source software:
- Raspbian. The Debian distribution for Raspberry Pi.
- Python, Flask, and jQuery Mobile for the control app.
- RPi.GPIO to control GPIO ports from Python.
- ShairPort, to enable AirPlay streaming to the Pi.
- LIRC to learn and send IR commands to the sound system, using the lirc_rpi module.
- uWSGI and Supervisor to run and deploy the webapp.
More details about the software setup can be found in the README on GitHub.
Result
A resounding success! It’s a joy to be able to control our music from anywhere in the house. My mom has been thinking of upgrading the system for a while, and she says it’s an awesome Christmas gift.
Comments