Hello everyone, this is my first post on this forum. This is also my first project using any sort of Arduino controller. I am currently following a guide for building a lightsaber based on an Arduino Nano. This is the instructable if you want to take a look https://www.instructables.com/Arduino-Based-Lightsaber-With-Light-and-Sound-Effe/. Everything seems to be working fine except for the speaker, which is playing .wav sounds, but is sounding very bad.
The program plays a "hum" sound on a loop from a connected micro sd card, and when you swing the lightsaber it should temporarily stop the "hum" sound and play the "swoosh" sound until completion; where the "hum" will then cut back in and continue its loop. The problem is that instead of a "hum" noise, it is a loud buzzing sound. When I swing the lightsaber and the "swoosh" noise cuts in and sounds fine for the duration that it plays.
I have tried using other .wav files in place of the "hum" noise that I am trying to play, but the buzzing sound still sounds the exact same. Turning down the volume made the "swoosh" sounds quieter, but the buzzing noise was still just as loud. The program is using tmrpcm to control all of the .wav files, if that helps.
I am using a 4ohm 3W speaker, an Arduino Nano, XM1584 DCDC step down (drops the 11.1v battery down to 4.5v for the amp), and PAM8403 amp. The sounds are all 8 bit, 16kHz, mono .wav files.
I have attached the .ino file for the code below because it is a very large program. The wiring diagram is also attached
This is the instructable if you want to take a look
I would rather take a bath in cold sick. It is a very bad site and virtually all electronics projects are written by rank beginners with an inflated idea of their own ability.
That circuit you posted looks like a typical instructables mess.
Where are all the capacitors?
Why is one input of the amplifier open circuit?
What is A6 doing being fed with a fixed voltage?
So a 1000uF capacitor on the power input pins of the strip. Another one on the power and ground of the amplifier. Then connect the right input of the amplifier to ground.
See if that improves things?
You also seem to have connected an SD card to a 5V system. Does it have level shift circuits on this board?
I connected the two 1000uf capacitors and wired the right amp input to ground. It's still buzzing in the same way. The micro sd card reader does have a built in level converter chip.
Ok, so next put a capacitor in series with the Arduino output and the amplifier input about 4u7 with the positive side to the Arduino. Also add a 4k7 resistor from the amplifier input to ground.
The idea is the amplifier’s input impedance is so high it is picking up noise and the capacitor gives yo an AC signal from the pulsed DC from the Arduino.
Yes it might help tiding things up. Try and have the ground all connected to one point and radiating out to all the other things you need it connected to. This is known as star wiring.
Also move that large capacitor out so that it sits as close to the LED strip as possible.
However this might just be a function of that class D amplifier, maybe you could try an analogue amplifier.
A schematic would be much better. Start by temporarily replacing the step down converter with a battery, If the buzz stays it is probably wire dress. If it stays remove one peripheral at a time to determine where it is coming from. As far as capacitors big is not always better, sometimes it can exacerbate the problem. Your amplifier board can operate at 5V try adjusting the voltage a bit to see what happens. Many times twisting wires helps a lot.
Hey so creating the "star" wiring setup helped organise my wires, but didn't help the tone. I adjusted the voltage step down a few times with no luck either.
It says on the toneAC library project homepage on this forum that pins 9 and 10 should both be wired to the amp, because they are meant to be used out of phase with each other somehow. Here is the link to this forum: toneAC v1.2 - Twice the volume, higher quality, higher frequency, etc. - Audio - Arduino Forum Could the problem be that I need to connect both of these pins to the amp to get the correct tone? I am asking because I want to make sure I understand what this program does before I mess something up.
I couldn’t get that link to work so I am not sure what it says. But an out of phase is known as a differential output, and while it provides twice the output swing it is only of use with something that has a differential input, like a speaker. Your amplifier doesn’t have a differential input, it has two separate inputs, a left and right, so it is of no use to you using a tone library that produces one.
If you had a class B push pull output driving transistors that could be used with a differential output driving it.
Ok that makes sense. I was looking at that page because in my Arduino sketch toneAC is used a few times.
I measured pins 9 and 10 with the voltmeter and they are both putting out 2.5v each, like it says toneAC should in that link. Could this be what is causing the distortions than? If this is the case, should I switch the pin the amp uses for data to one that isn't 9 or 10?
Could this be what is causing the distortions than?
I doubt it.
I thought your problem was the hum noise being too loud?
When you play another .wav file for the hum, have you tried using Audacity to reduce the amplitude of that file?
I just downloaded Audacity and messed around with it and managed to get rid of around half of the noise. I also reduced the frequency constrain of the program and managed to get rid of most of the remaining noise. I'm not sure why that worked, but everything seems to be good now. Thanks for the help