Controlling volume from a Arduino output. - Page 1
Forum section: electronics / beginners

author: Watth
author_rank: Frequent Contributor
timestamp: November 05, 2023, 09:23:26 pm
content: Hey EEVFolks!I want to try to make a basic theremin-like device. Two ranging captors measures the hand's position of the user.The Arduino (or other Arduino-compatible board), will use these measures to alter the pitch for one, and the volume for the other. A loudspeaker will be used in this circuit.And I don't know how to vary the volume, as I guess I will need an extra component.1.- I guess I could use another PWM signal, smoothed with an RC, as a volume reference.I had a look at TI'sLM386audio power amp.Can I simply vary the audio's volume simply by varying the power supply voltage (Vs)?2.- Or simply add a digital potentiometer between the µC's output and the loudspeaker?Thanks for reading.

author: alligatorblues
author_rank: Regular Contributor
timestamp: November 05, 2023, 09:55:08 pm
content: For a volume control to work the way people intuitively think it should, the adjustment has to be on a logarithmic scale. For a speaker to sound twice as loud requires more than twice the power. And the relationship is logarithmic. So, you need a component to vary the signal on that scale. Amplifiers use a logarithmic pot. So, just google on, "logarithmic control of a signal".

author: Buriedcode
author_rank: Super Contributor
timestamp: November 05, 2023, 11:35:08 pm
content: Quote from: Watth on November 05, 2023, 09:23:26 pmNothing wrong with using another PWM signal - its maximum output is dependant on the uspply voltage, but for volume control this isn't really critical - as long as it doesn't vary dramatically during operation. You're just interested in relative accuracy, which PWM is excellent for. It also gives you an easily controllable DC control voltage, and because volume doesn't change dramatically (as in < 10ms) and because you might not need the full 10-bit resolution (1024 steps in volume) you can use a higher frequency PWM, with a heavier filter with say a 50Hz cut of.IMO a digital pot would be overkill, but they are cheap, and can be handy if you want to vary the gain of an amp - something which cannot always easily just use a control voltage. Sounds like you want a VCA - voltage controller amplifier - that can determine the outputs amplitude (variable gain), which is then sent to the power amp (fixed gain)that drives the speaker. Here a digital pot can simply be used as a voltage divider, like a volume pot before the power amp. Like the image, but with SPI/serial control rather than actual buttons:https://www.electroschematics.com/wp-content/uploads/2017/04/dpot-2.png?resize=320%2C206?w=320For smooth colume changes - rather than sudden discrete jumps - you would need to write very quickly to the digital pot to change its value. Changing PWM level is often much quicker (write to a register, rather than send several bytes over SPI/I2C), so less stress of your Arduino if its busy doing other things.So I say either a VCA, or a power amplifier chip that has DC volume/gain control. Off the top of my head sometihng like the old TDA7052 as an example.

author: edavid
author_rank: Super Contributor
timestamp: November 05, 2023, 11:55:38 pm
content: How are you generating the audio output? If it is directly generated by the MCU, just multiply the output waveform value by the volume value.If you are using an external waveform DAC, you could make it an MDAC, and use the volume value to control the reference voltage.Have you looked at the OpenTheremin design?