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?

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.

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 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.

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.

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.

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.

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.

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.

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.PeakPeak to peakRMSAvrageand peak musicThey all give different answers.

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.

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.PeakPeak to peakRMSAvrageand peak musicThey 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.