Pages: [1] 2   Go Down
Author Topic: Controlling volume from speakers  (Read 2677 times)
0 Members and 1 Guest are viewing this topic.
Cebu City
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Hi im new to arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi I have a project to be made that would involve a wind sensor and a speaker. Is it possible to control the volume of the speaker through the data it receives from the wind sensor and if it is possible can you guys please tell me how to do it? smiley

For example: Soft Blow = Soft sound output
                   Medium Blow = Medium sound output
                   Hard Blow = maximum sound that the speaker can produce

I would like the volume output of the speaker would depend on the strength of my blow through the wind sensor is this possible?
Thanks. Ryan smiley
« Last Edit: January 09, 2013, 11:08:24 am by xxryan1234 » Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31382
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You could use a digital pot to controle the volume of a sound signal:-
http://arduino.cc/en/Tutorial/SPIDigitalPot
Or do you want to generate the sound as well?
Logged

Cebu City
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Hi im new to arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could use a digital pot to controle the volume of a sound signal:-
http://arduino.cc/en/Tutorial/SPIDigitalPot
Or do you want to generate the sound as well?

Yes, I do want to generate sound as well. I want the sound to depend on the strength of my blow through the wind sensor.
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31382
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Then use the tone out function to generate the noise and use the digital pot to control the output signal before you put it into an audio amplifier.
Logged

Toledo, OH
Offline Offline
Sr. Member
****
Karma: 19
Posts: 455
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You could use a digital pot to controle the volume of a sound signal:-
http://arduino.cc/en/Tutorial/SPIDigitalPot
Or do you want to generate the sound as well?

Yes, I do want to generate sound as well. I want the sound to depend on the strength of my blow through the wind sensor.

My toneAC library is a replacement for the standard tone library and includes a volume setting.  You can specify a volume for each note.  There's also a host of other advantages of using my library over tone.

Tim
Logged

Arduino Uno - Teensy 2.0 - Teensy 3.0 - Raspberry Pi Model B w/512MB RAM
My libraries: NewPing library - LCDBitmap library - toneAC library - NewTone library

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31382
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you need to brush up on your theory:-
Quote
the loudest is at 50% duty cycle (only on half the time). Which at 5 volts, is like sending only 2.5v to the speaker. With toneAC, we're sending out of phase signals on two pins. So in effect, the speaker is getting 5 volts instead of 2.5, making it nearly twice as loud.
This is wrong.

What is happening is that the standard tone library you are sending 5V in a single ended drive. With what you are doing you are sending +/- 5V in a push pull arrangement so in effect boosting the output to 10V. Which is why it is twice as loud.
Logged

Cebu City
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Hi im new to arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried using teckel's toneAC library but it doesn't work(it just says 'toneAC' was not declared in this scope even though I already imported the library to my project), I don't think it's compatible with my Arduino ATmega644. I would have loved to use it to save money using a digital potentiometer because i'm really low on budget right now but I guess I have to follow what mike has said. Been searching tutorials on how to use digital potentiometers and hopefully when my order arrives everything will turn out okay. Sorry for the very late reply guys! been very busy these days. smiley

I have a question Mike, so before I connect my speaker to the arduino it goes through the digital potentiometer first right?

and also...
I ordered a    X9C103P Digital Potentiometer will this be okay to do the job? I ordered this one because it's the only one that is available here in our region. smiley
« Last Edit: January 27, 2013, 10:43:11 am by xxryan1234 » Logged

Cebu City
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Hi im new to arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31382
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
so before I connect my speaker to the arduino it goes through the digital potentiometer first right?
Not quite, the order goes:-
Arduino tone out -> digital Pot -> audio amplifier -> speaker


Quote
X9C103P Digital Potentiometer will this be okay to do the job? I
Yes
Logged

Toledo, OH
Offline Offline
Sr. Member
****
Karma: 19
Posts: 455
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you need to brush up on your theory:-
Quote
the loudest is at 50% duty cycle (only on half the time). Which at 5 volts, is like sending only 2.5v to the speaker. With toneAC, we're sending out of phase signals on two pins. So in effect, the speaker is getting 5 volts instead of 2.5, making it nearly twice as loud.
This is wrong.

What is happening is that the standard tone library you are sending 5V in a single ended drive. With what you are doing you are sending +/- 5V in a push pull arrangement so in effect boosting the output to 10V. Which is why it is twice as loud.

I had first said that it was 10 volts, but others corrected me that technically the standard tone library is only getting 2.5 volts because it's being pulsed half the time like a switched-mode power supply.  Basically, I have 50% of people saying one thing and telling me I need to brush up my theory and I have the other 50% saying the opposite saying I also need to brush up my theory.  I think you two groups need to get together and decide which theory is correct and brush up together.

In either case, twice as much voltage, current or whatever you two groups decide is getting to the speaker with my toneAC library over the standard tone library.  You all can fight over if that's 5v or 10v as it doesn't really matter either way to me ;-)  I'm more of a software than hardware guy.  The end result is a significant volume increase and the ability to control volume.

Tim
« Last Edit: January 27, 2013, 04:22:42 pm by teckel » Logged

Arduino Uno - Teensy 2.0 - Teensy 3.0 - Raspberry Pi Model B w/512MB RAM
My libraries: NewPing library - LCDBitmap library - toneAC library - NewTone library

Toledo, OH
Offline Offline
Sr. Member
****
Karma: 19
Posts: 455
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried using teckel's toneAC library but it doesn't work(it just says 'toneAC' was not declared in this scope even though I already imported the library to my project), I don't think it's compatible with my Arduino ATmega644. I would have loved to use it to save money using a digital potentiometer because i'm really low on budget right now but I guess I have to follow what mike has said. Been searching tutorials on how to use digital potentiometers and hopefully when my order arrives everything will turn out okay. Sorry for the very late reply guys! been very busy these days. smiley

I have a question Mike, so before I connect my speaker to the arduino it goes through the digital potentiometer first right?

and also...
I ordered a    X9C103P Digital Potentiometer will this be okay to do the job? I ordered this one because it's the only one that is available here in our region. smiley

toneAC v1.2 that was just released adds support for the ATmega644 (or at least it should based on the datasheet).  But, I think the problem you had was that you were not loading the library correctly.  Either it can't find the library or you didn't include it at the top of your sketch.  First get v1.2, next make sure you uncompress it and put it in your libraries folder just like the rest of the libraries, then just use the sample toneAC sketch for testing, finally incorporate it into your sketch once you're already confident it works.

If you do have a problem using the library with the ATmega644, let me know.  There's specific defines in the library for that chip so it should work.  But, I don't have one to test so if there's a problem I'd like to know.

Tim
Logged

Arduino Uno - Teensy 2.0 - Teensy 3.0 - Raspberry Pi Model B w/512MB RAM
My libraries: NewPing library - LCDBitmap library - toneAC library - NewTone library

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31382
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but others corrected me that technically the standard tone library is only getting 2.5 volts because it's being pulsed half the time.
The others are wrong.
There is no need to get together. PWM is a 0 to 5V signal. At 50% it is still 0 to 5V, it is never 2.5V.
However the average voltage is 2.5V but the peak to peak voltage is 5V.
So your push pull system produces a +5 to -5V signal as seen by the speaker. That is a 10V signal. It has an average voltage of 5V but the problem is that an average voltage tells you nothing. Suppose you use a 25% duty cycle on your system. The average voltage is 2.5V but it is still a 10V peak to peak signal. A 25% duty cycle will sound as loud as a 50% duty cycle tone. The only change a duty cycle makes is to add or subtract a DC offset to the signal and you can't here DC.

When measuring loudness of an electrical audio signal there are several ways you can express it.
Peak
Peak to peak
RMS
Avrage
and peak music
They all give different answers.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16499
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If you do have a problem using the library with the ATmega644, let me know.  There's specific defines in the library for that chip so it should work.  But, I don't have one to test so if there's a problem I'd like to know.

I just tried it on my 644P based board and just using a O-scope and one of your example sketches I could see the clocking on two pins. Different pins then what your library states, but I'm using a Bobuino pin 1284P/644P mapping scheme rather then the older standard Sanguino pin mapping, or whatever ever pin mapping you may have used as you developed the library. As there is no 'official Arduino' pin mapping defined one needs to be able to backtrack to the port/pin number used by the various timers sometimes.

Anyway thanks for adding the 1284P/644P support.

Lefty
Logged

Cebu City
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Hi im new to arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried the library out but even the loudest sound sounds so weak. smiley-sad

X9C103P is a digital potentiometer available in my country, is this okay to be used for volume control?
Logged

Toledo, OH
Offline Offline
Sr. Member
****
Karma: 19
Posts: 455
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but others corrected me that technically the standard tone library is only getting 2.5 volts because it's being pulsed half the time.
The others are wrong.
There is no need to get together. PWM is a 0 to 5V signal. At 50% it is still 0 to 5V, it is never 2.5V.
However the average voltage is 2.5V but the peak to peak voltage is 5V.
So your push pull system produces a +5 to -5V signal as seen by the speaker. That is a 10V signal. It has an average voltage of 5V but the problem is that an average voltage tells you nothing. Suppose you use a 25% duty cycle on your system. The average voltage is 2.5V but it is still a 10V peak to peak signal. A 25% duty cycle will sound as loud as a 50% duty cycle tone. The only change a duty cycle makes is to add or subtract a DC offset to the signal and you can't here DC.

When measuring loudness of an electrical audio signal there are several ways you can express it.
Peak
Peak to peak
RMS
Avrage
and peak music
They all give different answers.

Awesome!  Debate this topic with the people who challenged me about it being 10v AC on this thread: 

http://arduino.cc/forum/index.php/topic,141844.0.html

PeterH, PaulS & sbright33 specifically.

I don't have a horse in this race, but more power to those of you who do.  Let me know who "wins" and who needed to brush up on their theory, which I see you've modified from your post so it seems you're already questioning yourself.

But, you are wrong in one area.  Adjusting the duty cycle of a push/pull PWM does change the volume.  50% is the loudest, but 25% will be lower volume.  No reason to believe me, just use toneAC and change the volume parameter which changes the duty cycle and therefore the volume.  The volume is controlled by the duty cycle, and quite well I might add.

Tim
Logged

Arduino Uno - Teensy 2.0 - Teensy 3.0 - Raspberry Pi Model B w/512MB RAM
My libraries: NewPing library - LCDBitmap library - toneAC library - NewTone library

Pages: [1] 2   Go Up
Jump to: