I've got an SD card and speaker hooked up to my nano and I can play mono audio files easily. My question is, is it possible to control the speed of a motor using the pwm output to the speaker? I tried just hooking the motor in where the speaker was, but that produced no noticeable variations in speed.

Alternatively, is it possible to analyse the wav file on the nano and control the motor that way? (i.e. motor speed is dependant on volume at a given time)


  • Have you tried peak detection yet? – Ignacio Vazquez-Abrams Jul 22 '14 at 1:13
  • That sounds like the sort of thing I'm after, could you go into a bit more detail/provide a link? – Owen Tourlamain Jul 22 '14 at 1:31

Regular sound files will have an even amount of time spend energizing the coil positive and negative, so the motor will not spin around in the normal sense. With a strong enough amplifier it will produce the sounds in the file like a speaker, but it will not noticeably turn.

Actual PWM varies the percentage of the time the signal is HIGH in a fixed frequency square wave, thus all the different values are the same "pitch". Audio varies amplitude and frequency, but the cumulative effect of audio waves is neutral, it spends half of the time below neutral and half above neutral voltage. The simplest analogy I can think of is audio being itself, even vibrations in air, and motor PWM being wind.

I am not sure if it possible to generate a sound file that would turn the motor, it probably depends on the file type. In any case, you would be better off with a far simpler amplifier like a transistor, MOSFET, or H-Bridge on one of your nano's actual PWM pins.

As to whether or not you could analyse the file on arduino, it also depends on file type. The code for the arduino WAV sheild I've seen does not have the arduino actually processing data, but It should be possible with a simple enough file type for arduino to decompress. WAV is not normally compressed, just raw data, so your limits are the RAM and if you can code something to glean volume from the raw data. I don't have much experience in that kind of file processing on AVR so I'm not going to call it either way.

  • Thanks for the info. I have a transistor as an amplifier for the motor already. Would it be possible to build a circuit that would filter the audio into a usable signal for the motor? Like how a bridge rectifier changes the positive and negative of AC into just positive DC? – Owen Tourlamain Jul 21 '14 at 20:31
  • you could put a rectifier in, it would at least make it possible, but still sub optimal. is there a reason you need to power a motor off an audio amp? – BrettAM Jul 21 '14 at 21:00
  • Its not from an audio amp, but from an audio file, I may or may not have a speaker attached as well – Owen Tourlamain Jul 21 '14 at 21:23
  • I see. Have you thought about making a simple file of motor PWM settings to be read at a certain speed on the arduino? – BrettAM Jul 21 '14 at 21:27
  • I can do that, but this way allows me to be lazy as there are countless songs I can "play" already out there. – Owen Tourlamain Jul 21 '14 at 21:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.