hi please i want to change the sound volume using potentiometer and a speaker with arduino.can you help me to do the connection circuit .thx in advance
kind regards
hi please i want to change the sound volume using potentiometer and a speaker with arduino.can you help me to do the connection circuit .thx in advance
kind regards
What sort of speaker? Dynamic one can overload arduino pin if connected directly - it can have several ohm resistance (so series connected potentiometer can help limiting current, if never set to zero) - better add additional resistor in series so max. current draw from the pin will not exceed MCU limits...
i telled you that the speaker works good so the blue knob is not set to zero yes or no.
please can you send me a circuit picture to describe connections
please i have trouble in : where i connect out pin of potentiometer?
where i connect sig pin of speaker and also vcc pin of speaker
yours trully
ok - so: set working system only with microbit and speaker module and check it.
then: disconnect only connection between microbit output and speaker module input
get potentiometer of proper value (what resistance is yours? it should be printed somewhere on the case)
potentiometer has three pins - find which one is regulated (let's call it "center pin")
connect one pin (not "center pin") to microbits output
connect another pin (not "center pin") to the ground
connect "center pin" to speaker module's input
is it clear or is it something that needs additional explanation?
yes thx i will connect out pin of potentiometer to p2 of microbit and sig pin of speaker to p1 so i make this program shared and i will try
i hope it will work
i´m eager to know
Ok - I have checked your code and now I understand...
You are trying to tune volume in your code using input from potentiometer connected to another pin...
What I am trying to propose is to reduce/regulate signal from microbit at "speaker's" input
So - only one of two: either put potentiometer between microbit and "speaker" or devise code that will scale output on microbit pin using any metric (for example - potentiometer connected to another contact or something else)
I think you are not doing what you thin you are doing:
so - you get voltage sample from P2 (from potentiometer), then write it to the output pin, then play sound disregarding pot value
check if music.playSoundEffect has variable setting volume and use pot variable to change volume
I don't know microbit and don't know language from the photo - could you share it using makecode.microbit.org as previous (it will translate)? The problem is that this webpage translates to my language that will be in turn unusable to you...
can you put block setVolume in loop before playing sound? something like this:
- read pot
- setVolume(pot)
- playSound()
and first verify that it correcly reads pot values when potentiometer position changes?
what is setSound called in your interface?
I don't know microbit and don't know language from the photo - could you share it using makecode.microbit.org as previous (it will translate)? The problem is that this webpage translates to my language that will be in turn unusable to you...
can you put block setVolume in loop before playing sound? something like this:
- read pot
- setVolume(pot)
- playSound()
and first verify that it correcly reads pot values when potentiometer position changes?
what is setSound called in your interface?
ok - this is different code - it changes frequency of tone using potentiometer connected to P2 (so potentiometer reading works)
playTone has definition playTone(frequency, duration)
can you check in main loop
- reading value of P2 to pot variable
- calling setVolume(pot) <- the same setVolume which you have had in previous version at the top with 127 value
- then playSound?
and of course it wouldn't allow for changing volume during playback - it is read only once per play...
I will advise for analog volume control
I think that it is rather strange when volume changes along with frequency - is it big change? Maybe speaker has narrow bandwidth and plays quieter sounds near the edges... It seems that this module has also capacitor connected parallel to potentiometer - it could make tones of higher frequency quieter (lower impedance of capacitor on high frequences - but I haven't checked its capacitance - it can be too small to make difference for audio)
thx a lot best friend .i don't want how to thank you really.all works well
i share you my rectified program with makecode(this is the microbit language that i teach to our pupils in school)