Spotify Connect on a Raspberry Pi + Auto-on stereo

The inspiration for this project came because I wanted to be able to cast spotify to the speakers in my room similar to the way you can cast it to google home or roku devices. The heart of this system is raspotify, which is a super easy way to get “spotify connect” capabilities on a raspberry pi. 

Final Product:

Wood is the material of choice for all electronics projects
The unit in its final place above the stereo.

The Raspberry Pi:

Programming the pi was very easy. After flashing raspbian onto my OG Model 1 raspberry pi, the raspotify setup was a super easy one line install. Here’s the link to the raspotify project.

Programming the raspberry pi

The Arduino:

The other piece of the puzzle was getting the stereo to turn on. The most elegant way to do this would be to have the Raspberry Pi trigger a relay via a GPIO when raspotify detects that a device is connected. I have no desire to dig into the raspotify code & build from source, and I have a buttload of arduinos, so the easiest solution was to have an arduino detect when the raspberry pi was playing audio and have it trigger a relay. The software/hardware for this project took just about as long as it took to document it here. 

The Code

The back of the (mostly) final version with the relay board. I couldn’t find any single relays in my parts bin, so I had to use the 4 relay board even though I only needed 1.
Graph of the raw input to the analog pin on the arduino when music is playing/when there’s no music. This was to validate that the arduino would be able to detect music at all
Adapter to go from a standard 3.5mm audio jack to the pins on the raspberry pi.
Test setup (to test and validate that the arduino can detect the audio signal properly from the pi)