Pages: [1]   Go Down
Author Topic: Need an Arduino Tone Digital Volume Control Method  (Read 3419 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino Rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Say I have a tone generated on pin 4. I set it to go through one 4.7K ohm resistor and then a 10K potentiometer before it gets to the speaker then completes to ground. So I have some analog volume control. However, regardless of my preferred overall volume as limited by my potentiometer and resistor, I want to ramp the volume up from zero at the beginning of a sequence of tones and then ramp it back down at the end of the series of tones within in a specified duration digitally. What component(s) can I use between pin 4 and my resistor/potentiometer setup that I will allow the arduino to ramp volume up and down digitally?
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 517
Posts: 26307
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you getting any volume like that? 5V thru a 4.7K resistor, that only leaves 1mA to go thru a speaker.  If you have an 8 ohm speaker, that's only .008 milliWatts.  Not sure that'd even be audible.
Are you actually driving a speaker?  Or are you going into an amplifier?
If you were driving an 8 ohm speaker directly, you'd need a 120 ohm resistor in series to keep from blowing the output pin. 40mA & 8 ohm speaker is 12.8mW.

What you could do is filter a PWM output, use that to drive a Voltage Controlled Amplifier, run the tone output thru that to a speaker amplifier.
Let me see if I can look one up.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 517
Posts: 26307
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Another option is to use your tone output as the VRef for a DAC and use the digital input as the volume control.
You want full volume, give all 8 bits high (for an 8-bit DAC for examplle), or 255.
1/2 volume, 127.
1/4, 64.
1/8, 32. etc.
Then Tone can toggle happily away from 0-5V, and be digitally controlled. 
Send that on to your speaker amplifier.

Here's a simple amp that I am using.

Swap in any logic level MOSFET. I run from a 12V, 4A supply, the speaker is good for 90dB (loud), but I think I am only running around 3.8W (Power = Voltage^2/Resistance, so 12*12/(34 +4 (the two 68 ohm resistors in parallel + the speaker impedance)) = 3.79W .  The switch is intended to put the two 68 ohm resistors in parallel for a 34 ohm load (hi volume) or 68 ohm load (low volume). I wired up another one to give me 34 (two 68s in parallel) or 136 (two 68s in series), am thinking now my logic is flawed about that as there is not the noticable difference in volume I was expecting. Maybe switching resistors in series between the DC blocking cap and the speaker would make more sense.

Anyway, hope the DAC gives  you an idea and you can use the amplifier idea.


* MOSFET_amplifier.jpg (78.03 KB, 960x720 - viewed 113 times.)
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino Rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you getting any volume like that? 5V thru a 4.7K resistor, that only leaves 1mA to go thru a speaker.  If you have an 8 ohm speaker, that's only .008 milliWatts.  Not sure that'd even be audible.
Are you actually driving a speaker?  Or are you going into an amplifier?
If you were driving an 8 ohm speaker directly, you'd need a 120 ohm resistor in series to keep from blowing the output pin. 40mA & 8 ohm speaker is 12.8mW.

What you could do is filter a PWM output, use that to drive a Voltage Controlled Amplifier, run the tone output thru that to a speaker amplifier.
Let me see if I can look one up.
Hi CrossRoads,

Thank you for your in-depth replies. I greatly appreciate it. If it isn't abundantly clear yet, I'm a noob, so I apologize for not further narrowing the scope of my parameters.

I've adapted Mitch Altman's ATtiny brain machine to Arduino UNO. It's essentially a guided meditation device. I'm using two pins to generate distinct tones, one to each ear using stereo headphones. The separated tones might be 441 Hz in the right ear and 399 Hz in the left ear. The end result is a binaural beat of 2Hz as interpreted by the brain through the efforts of our wonderful corpus callosum.

Without any resistors at all, the sound output is enough to probably damage the earphones with continued use. (I used a very old rugged cheap pair of over-the-head earphones for testing. I suspect a pair of $10 silicone-insert types used for many mp3 players would have been blown on the first try.) The 4.7KOhm resistors step down the volume to the point where the highest amplification is merely annoyingly loud rather than ear-damagingly loud using an audio headset. The 10K dual audio potentiometer does a good job of further reducing sound to a user-preferred level to an audio headset for anyone with a reasonable hearing capacity.

I didn't know what a DAC was, so I looked it up and found a lot of interesting Digital-to-Analog Converters that may be more expensive than the original Arduino UNO itself. I'm probably wrong, but I got the impression that I'd be moving the actual tone generation to a different integrated circuit, out of the realm of the arduino tone library.

Specific tones generated by the arduino are imperative to the project. Given the sound levels on the output pins for the tones, I want to create a 'sound envelope' using (perhaps?) voltage-controlled volume that allows me to ramp the sound up gently to it's normal existing output level at the beginning of a session and ramp the sound back down at the end of a session.

The example you've very kindly posted looks like it's designed to amplify more than dampen what's already there. I'm not exactly sure it's the kind of thing I'm looking for, though it might be adapted.

I have $15 dollars in the form of a gift certificate from Radioshack down the street. If it helps, I already have a popular quad opamp I bought from Radioshack. Taking from what you suggested, I wonder if I could use two pwm pins as voltage controllers that could limit the volume of the tones generated on two non-pwm pins before it goes out through the user-controlled potentiometer.

I found this example and wondered if it might be something I could adapt to use with an opamp and some extra components. Do you think it would work, or is this for something else entirely? If I were to use a circuit like this, I imagine the pwm pin would have to be attached either to 8 or 4 in the below diagram. Again, I'd be grateful for feedback and suggestions.


Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 517
Posts: 26307
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What you describe there is using the PWM signal to limit the range of the VCC pins, which I'm pretty sure would't work that well.

Look at a part like this
http://www.analog.com/en/digital-to-analog-converters/digital-potentiometers/ad5243/products/product.html
Put this in place of VR1, change R2 = 10K for gain of 1 on the output stage.

Gotta run out for a bit, will read the datasheet when I get back to see how noisy the part might be.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 517
Posts: 26307
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This one looks good too
http://www.analog.com/en/digital-to-analog-converters/digital-potentiometers/ad8402/products/product.html
PDIP for ease in prototyping also.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino Rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sweet! There are quite a number to choose from even when narrowing it down to the ad8402.
Is there a particular one of those listed that you would suggest?
Just to be sure - this is still a linear rather than logarithmic solution, right?

You got me thinking about digital potentiometers, so I looked here to find out who sells in lots of one.
http://octopart.com/parts/search?q=digital+potentiometer
I might be able to buy a few other parts at the same time.

If nothing else, it will be interesting and hopefully entertaining to figure out which pin connects where.

Again thanks.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 517
Posts: 26307
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You have to look at each one to see which are linear or logarithmic. This one is linear I think.
I suggested it because of the package type, surface mount parts can be difficult to prototype with.
Alas, Dual Inline Package (DIP) availability is going away for many parts. Unless someone comes up with a line of really inexpensive breakout boards for the myriad of part types, the cost of prototyping will either rise with having to make  custom board for any layout, or just become cumbersome with the one-size to accomodate many parts kind of breakout boards. (one for quad flat packs in different pitch widths; small outline packages; thin small outline packages; leadless packages; etc).
http://www.schmartboard.com/index.asp?page=products are examples of one size to accomodate several package sizes
http://www.logicalsys.com/smt-to-thru-hole-adapters.asp  are examples of specific package size parts.
Both are pricey to stock up on to just have around for experimenting - one really needs to know what is needed for a project.

I am toying with the idea of making a 10" x 10" board of footprints for $95 here, cutting them up hacksaw and adding square posts for breadboard use as I go.
https://www.internationalcircuits.com/layer_grid.php?cat_id=13
These guys are in Natick, couple towns over from me.
Now that I've started playing with eagle I think I could pull that off - question remains, what packages to use? And then try & go for fancier surface mount pads underneath to keep the pin width at 0.3" like a DIP for easier protoboard/ breadboard usage?
I guess if boards are say 0.4" wide by 1.2" long for a 20 pin TSOP part, that's only 0.48in^2, could fit 20 across the board, and have 8-10 rows of different part types. Or maybe 10 each of 2 types across the board, go for 20 differente types on a board.

Anyway, that's a different discussion.
8402, DIP package, with TL072 opamp for output buffering, sounds like a good plan for driving earbuds or other high impedance (as compared to 8 ohm) drivers.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino Rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Alas, Dual Inline Package (DIP) availability is going away for many parts. Unless someone comes up with a line of really inexpensive breakout boards for the myriad of part types, the cost of prototyping will either rise with having to make  custom board for any layout, or just become cumbersome with the one-size to accomodate many parts kind of breakout boards.
I see what you mean about availability. Almost everything is now surface mount, and there all a lot more expensive.

8402, DIP package, with TL072 opamp for output buffering, sounds like a good plan for driving earbuds or other high impedance (as compared to 8 ohm) drivers.
For the price and availability, linear will have to do.

Again thanks.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino Rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am toying with the idea of making a 10" x 10" board of footprints for $95 here, cutting them up hacksaw and adding square posts for breadboard use as I go.
https://www.internationalcircuits.com/layer_grid.php?cat_id=13
Looks like someone already has had a similar idea and is selling it on ebay.
http://cgi.ebay.com/SMD-CONVERTER-ADAPTER-PCB-SOT-MSOP-SIP-DIP-14-/120628243230?pt=LH_DefaultDomain_0&hash=item1c1600eb1e#ht_2710wt_905
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 517
Posts: 26307
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Looks like low pin count parts. Too bad delivery is  a month.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 517
Posts: 26307
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, I went & purchased one, let y'all know in a month if its worthwhile.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: