Pages: [1]   Go Down
Author Topic: Pwm pitch + volume control?  (Read 1344 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone. I'm looking for a way to control volume of a pwm output while a melody is being played. I'd like to use a photoresistor hooked up to an analog input to control the volume. The example toneMelody is similar to what my code looks like except it's in void loop. I know a photoresistor between the speaker and ground would be one way of doing it, but I want full control from no volume to full volume. Another output to a transistor that controls the pwm might work too, but I'd like to do it without many components. Any help would be greatly appreciated.
« Last Edit: June 03, 2011, 02:57:25 pm by gorbulus » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 533
Posts: 26951
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

Photo resistors usually have a wide range of resistance, if it got up in resistance much at all you wouldn't get much volume being in series with a 4-8-16 ohm speaker.
What would better is to have the photoresistor in series with an output feeding a self-amplified computer moniter speaker - got one of those around? The lower its resistance the higher the volume.
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.

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

CrossRoads, thanks, but thats not really what im looking for. Space is limited so I would like to do it mostly in code. I'm leaning towards the using a transistor in series with the pwm output to the speaker, and then mapping a separate photoresistor input that outputs to the base of the transistor... though im not really sure how to work that out since I'm new to electronics and cant bias a transistor yet. I also saw this http://arduino.cc/forum/index.php/topic,36857.0.html, but it confuses me a bit and i'm not sure how i would use it. What I really want is to use all code: no transistor, no amplifier. Using light sensitivity to control the volume is also vital and it probably needs to be calibrated so i can get full control. Is that possible?
« Last Edit: June 04, 2011, 02:57:27 pm by gorbulus » Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 107
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.adrianfreed.com/content/arduino-sketch-high-frequency-precision-sine-wave-tone-sound-synthesis

he has volume on there, and accurate pitch. you can also put in a lot of different waveforms besides his sine, by making more tables besides the sintable
I based a long running project on it. just keep in mind when you reduce the volume in code you reduce the amount of bits resolution of the output.

also there is a change possible in the setup code for the pwm on pins 9 and 10 you change it to a 16 bit timer (but it only outputs 10 bit PWM) which is much better if you are changing the volume.

(i haven't adapted that to his code because i use a DAC, but i will look in to it soon)
Logged

Pages: [1]   Go Up
Jump to: