Introduction: Pi Zero Speaker - DIY Audio HAT and Audio Player
A few months ago.....
I got hold of a really old wired speaker from somewhat 2004 (I think so), from my father's friend. They knew my hobby of opening things apart. :)
Coming back to the speakers, the one I got was really in bad shape, the body was all dirt coloured. I tried plugging it in, but the plug was all bent and did not fit perfectly in the switchboard. Moreover, the thing did not even work. So, I took out my tools and started ripping apart the speaker. Got hold of the two speakers (with some torn wires) and the amplifier board with a damaged 9v transformer. The amplifier circuit was working perfectly except for some dirt all over it. Even the speakers were covered in dirt and one speaker had a little tear in its diaphragm. So, I cleaned everything and removed the transformer. Then hooked up a 9v battery to the circuit and plugged in my phone as an audio source through the 3.5mm audio jack. The speaker worked as expected. But now the whole circuit and speakers are completely naked (without any covering). So, my next move was to make a new enclosure for the speaker.
Last month I bought the newly released Pi Zero W. Why not integrate Pi Zero W into this speaker?
But the main challenge I faced was that the Pi Zero W does not have inbuilt audio output and buying a Pi Audio HAT was way over my budget.
Enough Intro let's get started.....
[I am not a native English speaker, so kindly forgive me if my English is poor.]
Step 1: The Idea
I started researching on the web for any posts related to Pi Zero audio output or building your own Audio HAT and came across this post by Adafruit website Pi Zero PWM Audio.
This post explains how you can take the audio output from the Pi's GPIO's with some changes in the Config.txt and using a small filter circuit. That's it, your very own DIY Pi Audio HAT.
I started sketching out my ideas. At last, I was satisfied with this sketch (fig 2). The plan was to connect the audio output from Pi on to the amplifier. Then there arises another problem " Power supply"
The amplifier works at 9v and the Pi works at 5v. If I use a normal 9v battery it will run out quickly. Not so good for using with Pi also. Using some li-po battery could have solved the problem, then that means I need to buy a li-po battery but with my budget, I couldn't afford it. So, I chose to use a 12V AC adapter (Spoiler alert: You could also use a 12v rechargeable battery, there is plenty of space in this build)
The final plan was to use some voltage regulators to step down the 12V to 9V and 5v respectively. Since I'm using a 12v supply why not add some LED strips (I also planned to include weather notification functionality using RGB LED strip, but ran out of time. Maybe in future versions I will try to include that)
Step 2: Things Needed
- Pi Zero W
- 270-ohm resistors - 2
- 150-ohm resistor -2
- 10μf capacitor - 2
- 0.01μf polyester capacitor - 2
- Perf board
- Car cell phone charger - 1
- 7809 voltage regulator - 1
- 100nf capacitor - 2
- Heat shrink or insulation tape
- 12 volts AC adapter/ 12 v rechargeable battery - 1
- Thick Cardboard Sheet
- White paper
- DC barrel jack - 1 (optional)
- 2x20-pin strip right-angle female header (optional)
- LED Strip
- Paint (optional)
Step 3: Tools Needed
Step 4: Powering the Amplifier
As I have told you guys before, I removed the 9v transformer from the amplifier circuit so as to power everything from a single 12v power source.
This amplifier uses LA4192 Audio amplifier IC and as per datasheets the max voltage that can be applied to this IC is 11v. If we connect the circuit directly to a 12v supply, it will damage the IC. So, we need to step down the voltage to 9v. For that, I'm using 7809 voltage regulator IC and two 100nf capacitors. Solder the circuit as per diagram on one side of the Perf board (fig 2).
1. Solder the 7809 IC on the perf board.
2. Solder one 100nf Capacitor on the Input and GND of the IC.
3. Solder the second capacitor on the Output and GND of the IC. (Follow circuit diagram).
Don't forget to trim the leads
Step 5: PWM Audio Through Pi Zero GPIO
Since Pi Zero does not have audio output we need to take the audio through the GPIO with a little hack. For that, we need to make a simple circuit using two 0.01 microfarad capacitors, two 270-ohm resistors, two 150-ohm resistors and two 10 microfarad capacitors.
This circuit filters the audio output from the GPIO's 13 & 18.
1. Begin by adding the two 270-ohm resistors to GPIO 13 &18 (Follow circuit diagram for clarification).
2. Then solder the two 10 microfarad capacitors in series to the resistors (take note of the positive and negative. You need to solder the + side of the capacitor to the resistor).
3. Solder the 0.01microfarad and 150-ohm resistor as per the circuit diagram and the other end of them to the GND (pin 3).
4. The output from each 10 microfarad capacitor is the audio output (left and right channel respectively).
You can also use headers so that you can plug it with the Pi when needed
Now you've made your own Audio HAT
I have used an audio jack so as to test during each step. It is not required at the end, the amplifier inputs are directly soldered on to the DIY hat
Step 6: Software Configuration for PWM Audio
If you are setting up Pi Zero W for the first time follow my other Instructable to know more about how to set up Raspbian, enabling SSH and VNC.I have explained everything in detail in that instructable.
1. Power up your Pi and open terminal using SSH/VNC.
2. Open config.txt using this command.
sudo nano /boot/config.txt
3. Add this section to the last part of the file(follow the image 2 for clarification).
#Enable PWM audio dtoverlay=pwm-2chan,pin=18,func=2,pin2=13,func2=4
4. Save the config.txt by pressing ctrl + x and select save by pressing Y and enter.
5. Reboot Pi.
6. Then again open terminal and type.
7. Select Advanced Option in the upcoming interface.
8. Select Audio in the next interface.
9. Select 3.5mm audio jack in the next one and click ok.
10. By default,
Pi audio is set to low. So type in
terminal and increase volume using the up button and press Esc.
That's it you have enabled PWM audio through GPIO.
Step 7: Testing the Voltage Regulator
Solder wires onto the sides of the voltage regulator. Connect the input to the 12v power adapter and using a multimeter test whether you're getting 9v. If you are getting 9v join the output of voltage regulator to the power of the amplifier.
If everything is okay the amplifier should work without any problem, plug in your audio source and check it out.
Step 8: Adding Voltage Regulator for Pi and Testing
We could build a voltage regulator circuit with 7805 to power Pi Zero. But that will lead to huge loss of energy in the form heat. So as per different forums, that suggested using car cell phone charger circuit I bought one and used that to convert 12v to 5v.
Take the car phone charger (I got mine from a local store for 1$). Take apart the outer body and carefully take out the circuit board. Find the input of the circuit board.
Solder wires from GND and +ve of the circuit to our voltage regulator's input (12v).
Power up the circuit with 12v and test the output using a multimeter you should get around 5v.
Try powering Pi with this voltage.
Step 9: Initial Testing
1. Connect our Audio HAT to Pi using the headers.
2. Join the audio output from Pi to the input of the amplifier.
3. Connect USB cable of Pi to the car cellphone charger circuit.
4. Connect the 9v output from the voltage regulator to the power of the amplifier.
5. Connect the 12v Adapter output to the 12v input of the HAT.
Switch on the adapter and amplifier. Wait for the Pi Zero to boot up and when it boots up, using SSH or VNC type in the commands in the terminal to test the audio output.
You should hear a voice speaking "Front Center". If not, try increasing the volume of the amplifier.
Load in some songs on to your Pi's Home folder and type in this command in terminal to play the audio file.
Replace song-name with the name of your song and replace mp3 with correct extension and press enter. If the name is correct the audio should start playing now.
By now all your hardware and software part is complete. Now all that is needed, is to make a suitable enclosure to house everything.
Step 10: Building the Enclosure
So as to give you an idea on how to make the enclosure, I have designed a 3D model using Fusion 360.Open the file PI ZERO SPEAKER v4.stl given below in some 3D modeling software to visualize the structure and the holes needed to make (If you are using Windows 10 there is a 3D modeling software bundled with that, open thefile given below using that software.)
If you have access to a 3D printer just print the PI ZERO SPEAKER v4.stl. No need to follow this step. You can skip to the next step.You can also use laser cut or wooden cases.
Since I don't have access to a 3D printer I chose to make one using some thick cardboard.
Further things that made me use cardboard are:
- I have lots of them laying around.
- Working with wood or other stuff without proper tools can take more time. For the ease of cutting and building, I chose cardboard.
1. Cut out 5 squares of 12cm from cardboard and using sanding paper, sand the edges. (layout is given below so, you don't have to measure everything).
2. Using hot glue gun stick each piece to form a box with one side open.
3. Using sanding paper sand the edges nicely so that they don't bulge out.
4. Take one speaker and draw the layout of it exactly at the upper center.
5. Draw a smaller version of the layout inside the layout and cut it out.
NB: For cutting easily punch holes along the outline.
6. Using amplifier as marking, same way cut out holes for buttons and knobs.
7. Sand holes perfectly.
8. Apply glue along the cut-outs so that the bits of cardboard are glued together.
9. Make a similar one for the second speaker.
The layout of the square in case you need is given below. Print it on an A4 sheet and stick it onto the cardboard. It helps in cutting out the shape without the need for measuring and drawing.
Step 11: Fixing Everything Inside the Case
1. Take the amplifier de-solder speakers and everything.
2. Hot glue the amplifier on the base of the cardboard. Make sure the buttons and knobs are coming out through the cut-outs.
3. Solder one speaker on to its respective wire and hot glue it. Make sure the diaphragm is exactly aligned with the cut-out hole.
Take care not to spill the hot glue on the diaphragm of the speaker.
4. Take the Audio HAT and solder the audio input of the amplifier to the output of HAT. The red and white wires represent two channels and the copper wire is GND.
Don't forget to use Heat shrink or other insulation in every joint.
5. Make holes in the back for the Pi and its ports.
6. Using a cardboard piece make a compartment above the amplifier to hold the Pi zero, HAT, Voltage regulators, etc.
7. Connect every wire and hot glue everything onto the enclosure.
8. Connect a barrel jack to the 12v input so that we can connect the 12v adapter and stick it out so as to access it from the outside.
Don't forget to add a wire from the 12v section for the LED strip.
9. Cut out a cardboard piece of 12cm * 13 cm so as to cover the top section. ( Pdf is given below)
10. Perfectly sand that piece and make sure all connections are working and all ports are glued.
Once test everything out to make sure it is working perfectly. If everything is okay glue the top piece.
11.Solder a long wire to the other speaker.
Store all the excess wires in the second case. If you want to make this speaker portable just add a 12v battery, there is plenty of space to store that in the second case!
When it is done, following the same procedure cut out the top part for the second speaker and hot glue everything shut.
Step 12: Adding LED's and Final Touch Ups
1. Just add LED strips on the top and wire everything. Connect it to the 12v wire we have previously soldered onto the board.
Don't forget to check the polarity
2. Now cut out a piece like in the second picture (paper hat) on a white paper(pdf file given below). This portion should sit like a hat on top of the speaker. This also helps in the diffusion of LED light.
3. Using paper and measurements cover all the other section with paper or use some paint (don't forget to add the holes wherever necessary).
4. Repeat the same for the other.
5. Let the glue dry for some time....
Because all the ports are available you can use Pi with monitor, keyboard, mouse etc.
Plug in 12v supply....
Let the Pi zero boot up...
Type in the command...
PLAY SOME MUSIC!
Step 13: Conclusion
Yes, we have turned that old speaker into something worth. Thanks to everyone who have helped me in completing this project.
Future updates you can expect
- Weather notification using LED strips and weather API (that was the main reason I added some Led strips on top)
- Battery operated one
- Some paint or a new wooden casing
Timelapse detailing the built process
Audio playing in the background is actually recorded from the Pi Zero Speaker while playing "Tetris for Idiots" python game on the Pi Zero W raspbian os
It's my first try recording a project in video format so I forgot film most of the part :)
Final Video Pi Zero Speaker
Audio playing in the background is recorded from the Pi Zero Speaker
In a hurry, I skipped the painting and used some papers to cover everything. Painting is much better than sticking some paper.
Further updates you can do
The possibility of using this speaker is endless, whether it be an Airplay speaker or music streaming machine. I mean there is a fully functioning raspberry pi inside this thing.
You can google for projects related to the topics given below to further upgrade your speaker.
- Music streaming like this project
- Home Theater using KODI
- Airplay Speaker
Thank You For Your Time.
We have a be nice policy.
Please be positive and constructive.