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