Go Down

Topic: The Arduino Controlled, Phone Operated, House Wide Audio System (Part 2) (Read 1 time) previous topic - next topic

kameo315

PART 2: CONTINUED

We also need some way to get audio to the PT2258 chip, right? An easy way to do this is to pick up a couple 3.5mm through hole jacks. This allows you to input whatever source into the system you want. We will then need some way to transfer the audio output of the PT2258 chip to our amp. I used more 3.5mm jacks on the PT2258 board and a few RCA to 3.5mm adaptor cables. There also needs to be a way to connect this board to the Arduino so stick a few male headers on the board connected to +5V, GND, SCL, SDA, CODE1, and CODE2 (CODE1 and CODE2 are used to change the I2C address of the chip to allow more than 1 PT2258). I then used these cables to connect the board to the Arduino.

    When your schematic is all finished, it should look something like this. The reason I have two sets of male headers is for daisy chaining boards for larger systems.



Also notice how the connections in the datasheet match those of the schematic.



PART 3: ASSEMBLING THE BOARD

    Since we have just finished the schematics for our circuit, we now need to choose our components. The datasheet for the PT2258 suggests 10µF capacitors and 100 kOhm resistors. FOLLOW THE DATASHEET. Order as many of these as you will need for however large your system is. You'll also need to pick up the PT2258 and some male headers. Since you're ordering stuff, if you choose to use the board I designed, head on over to OSH Park and order a couple.

    Now for the fun part! It's time to solder! Find that soldering iron and some solder. I recommend starting with the PT2258 itself and working your way away from the center of the board. You can follow along step by step in this imgur album.

When you're finished it should look something like this.



    Now that the volume control module is finished, there is one more thing we need to consider. We want to be able to turn the system on and off remotely. I used this relay in line with the power supply for the amp to allow the Arduino to control whether the amp gets power.

Time to wire everything together:
1.   Plug the Ethernet shield into the top of the Arduino



2.   Connect 5V and GND on the relay to 5V and GND on the PT2258 board


3.   Connect the relay signal to any of the digital pins of the Arduino

4.   Connect 5V and GND of the PT2258 board to the Arduino
5.   Connect SCL and SDA of the PT2258 to A5 and A4 on the Arduino, respectively
6.   Connect both CODE1 and CODE2 to GND on the arduino (if you are using two PT2258s, connect CODE2 to +5V on the second)

7.   Find a spare 3 prong AC power cable (it MUST be 3 prong), cut the non-3-pronged end off and expose the three wires inside.


8.   Do some Googling to find out which of your three wires is live, which is neutral, and which is ground.
9.   Connect neutral and ground to their corresponding ports on the power supply and connect the live wire to the normally open port on the relay board.


10.   Connect the load port on the relay to the live port on the power supply.

11.   Using some spare wire, connect + and - of the power supply to + and - on the amp.


The finished system should look like this



PART 4: AUDIO INPUT

    What would be the point of all this if you still had to walk over to your computer to change the song? The days of getting out of your La-Z-boy to play "Never gonna give you up" are over!

    If you haven't yet heard of a Chromecast, prepare to be amazed. A Chromecast is a small HDMI dongle which allows you to play Netflix, Hulu, Pandora, whatever you want on your TV! All for just $35! Oh, and did I mention you control it from your phone through WiFi? Bingo! That's what we want. If you pair a Chromecast with an HDMI audio extractor, you are able to take the audio signal the Chromecast outputs and send it through our PT2258 chip. All you need to do is plug the Chromecast into the HDMI port on the audio converter and plug the RCA outputs on the converter into the input of our freshly soldered PT2258 borad.

Wow, that was pretty easy! Now on to some harder parts….

PART 5: ARDUINO CODE

     This section will be relatively short. Writing this code is not a beginner task. If you are well versed in C++, feel free to have a go at writing your own code. For those of you who are still beginners, I have attached the code I have written for this project. Feel free to use it however you like!

    There are some changes you must make to the code depending on your setup. I have listed those at the very top of the code file and have included instructions on how to fill in the blanks.  

PART 6: THE WEB-APP

    I will be approaching this section in the same way as the Arduino code. I have attached the code I use and, if you are so inclined, you may use it knowing that it will work. All you need to do is take the HTML file containing the webpage, put it on the microSD card in the root directory and name the file "Kamdora". Next put the microSD card back in the Ethernet shield and you're ready to go!

PART 7: USING THE SYSTEM

    In order control the system from your phone you will need to open the browser of your choice and type the IP address of the arduino followed by /?app (i.e. 192.169.1.199/?app). This will take you to the control webpage and you are good to go! Start casting some music through the Chromecast and have full control over where and how loud it plays! By the way, this web-app will work on any device will a web browser, not just your phone.

   This is the screen you should see. Press System On to engage the relay and allow power to travel to the power supply and amp. Press mute all to instantly mute all channels and silence your house. Click on any of the channels individually to mute separate zones. The volume scale is 78 (quietest) to 0 (loudest) and is controlled by the arrows.

    There you have it! You have completed your very own house wide audio system! I hope you enjoyed my tutorial and if you have any questions just ask me in the comments!

kameo315

So you want audio huh? But not just any audio, you want audio EVERYWHERE! In your bedroom, bathroom, kitchen, closet, shed, doghouse, etc. Still not enough? Well, what if I told you all of this audio can be controlled (volume and what is playing) on a room by room basis from ANYWHERE in your house, all for far less than it would cost you to buy a similar retail system. Don't believe me? You're not alone, but if you keep reading hopefully I'll change your mind.

    First of all, let me start with some disclaimers: This system is not perfect. There are limitations. Furthermore, it will take effort and it will be worth it.

    Second: You will need a building in which you can/already have routed speaker wire to every room in which you want audio. This is ridiculously hard to do in older buildings unless you are willing to tear down walls. I recommend waiting until you plan on renovating/building a house or, I guess, if you're that kind of person, you could just run speaker wire through the hallways and trip over it every time you get up to pet the cat. If you cannot/are not willing to do this, step away now. You will not want to keep reading and realize what you are missing in your house. If you do, I am not responsible for any damage to walls that may occur from spontaneous urges to run speaker wire.

    Ok, now that all the boring stuff is over, LET'S GET BUILDING!

PART 1: THE BASICS

    The first thing you will need to do is go buy an arduino. If you're unfamiliar with Arduino, it's basically a very small, low powered computer which will be controlling our system. Arduinos range from very small to much bigger and more powerful. The Arduino we'll be using in this tutorial is the Arduino Uno R3. The Uno is a middle range, great for beginners Arduino which is very versatile. You can get one for around $20 from your favorite online store.

    Now that you have your Arduino, STOP. Drop everything. Take a weekend and get to know your Arduino. Make its LEDs blink. Power it through a 9v battery. Make it talk to you. Take it for a romantic dinner at your favorite restaurant. Whatever floats your boat. The most important thing is to learn what you are working with! There are plenty of Arduino tutorials available online so I won't bother to make one. If you merely just follow my instructions step-by-step and copy my Arduino code exactly you won't learn anything! Sure, you'll have a working audio system but what good is that? What happens if you want to control your blender from your phone? I know how to do it, but that's because I've taken the time to learn about Arduino and all the wonderful things it can do.

    Now that that's over and you have at least a basic idea of what we're working with it's, time to start thinking about what we want our system to do. First thing's first, we want AUDIO! Well that's easy. All we need is an amp, right? Something like one of these, right? WRONG! What we want is something simple, stripped down, and efficient. We don't need any of that airplay or HDMI mumbo jumbo. We'll integrate that ourselves. What we want is a plain and simple amplifier. That's it. An audio signal in, and a speaker output. I'm using (and highly recommend) this one. It has six channels meaning it will be good for up to three rooms (assuming you take the stereo route which I'm guessing most people will).

    Next you will need speakers for each room you want audio. I'm going to let you have some freedom on this task. Really any speakers will do. Go find some that fit your price range and room size. I personally picked up these and have been extremely impressed with their sound quality, especially considering their price.

PART 2: THE ARDUINO

    Time for controls! We need to decide how to control our system. I said earlier we'll be using our phones to control it, right? Well how might we interface a phone with an arduino.... There's bluetooth, WiFi, and NFC. Bluetooth and NFC both have annoying range restrictions (NFC especially, HA) so let's choose WiFi. In order to send commands from your phone to the arduino, the arduino will need to be connected to your home network. Luckily, there is an ethernet shield for the Arduino Uno which plugs right into the top of your new best friend. This allows the Arduino to communicate with other devices on your home network and send and receive files from its included microSD card. You probably have a microSD card lying around somewhere. If not, buy one. It doesn't need to be big. The file we are going to put on it is only a couple of kilobytes.

PART 3: THE CIRCUIT

    So the Ethernet shield allows our Arduino to communicate with your phone, but how can the Arduino control the audio signal  going to the speakers? This problem is solved using the fantastic PT2258 IC. This little guy receives commands over the I2C (pronounced eye-squared-see) bus and has six channels of control to match our six channel amp. Basically what this chip does is take six audio inputs and can control the volume from a range of -78dB to 0dB. The various types of commands it can receive are located in the datasheet and will be discussed more later.

    We now need to figure out how to wire this little guy up. If you are a beginner, STOP. This is another learning opportunity. Go buy a cheap soldering iron. You will not need a good one for this project. You should be able to find one for under $20. Now go find an old printer, computer, toaster, etc. and rip it apart. Find some circuit boards and have at it. Soldering is tricky and takes quite a bit of practice to master. Find a tutorial of your liking (trust me, there are plenty out there) and learn.  

Not too bad, huh? Now you can scratch "Brutally tear apart and defile a toaster" off your bucket list.

    Time for a choice. There are two routes you can take for hooking the PT2258 chip up to your Arduino. You could buy a prototyping board such as this and wire it yourself, or you could do as I did and design your own PCB to make things easier and neater. (I have attached the board file for those of you who don't feel like designing your own) Either way you are going to be following the schematic in the PT2258's datasheet EXACTLY. Do not skimp out on capacitors or resistors. These are necessary elements of the circuit and without them you may be severely disappointed in the sound quality.

    There are three types of components needed: capacitors, resistors, and the PT2258 IC itself. Each has a different, but equally important role in the circuit. The capacitors store a charge and release it if there is a sudden drop in power from the supply side of the input. When wired in the configuration shown in the datasheet, the capacitors function to smooth the audio signals and remove sharp or sudden spikes. Resistors are generally used to lower voltage or hinder current flow. In the configuration shown in the datasheet, with one end connected to the source and the other to ground, the resistors are called "pull down resistors" meaning when there is no input signal, the circuit is pulled down to ground. This has the handy effect of removing annoying static or buzzing when nothing is being played through the system.
If you chose the second method of designing your own PCB, head on over to Sparkfun's excellent Eagle tutorial. Eagle is a piece of software used for designing and manufacturing PCBs.

Click here for part 2 of the tutorial


CrossRoads

Huh, that didn't merge the way I thought it would. Sorry about that.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

djx18

Thank you so much for this post Kameo! I am building my house, and wanted a solution like this! You documented this all for me! :D

One thing i wanted to do a bit different is have 6 zones, with 2 speakers in each zone. So that would be 2x PT2258 boards for 12 channels. I see you can add another board, but what about the Power Supply. Do I need 2 power supplies or 1 power supply that is more powerful will suffice? Also, the relay... if i need 2 amps then I need 2 relays?
If you think 1 power supply will work can you share which one I should buy? Also, how would i power the amplifier boards with this power supply, just split two cables from the output terminal to each amp?

Thanks again for the post!

Go Up