# I want to actuate a motor based on a wav file, but it has too many samples per second

I am trying to actuate a simple DC motor based on a wav file. At the moment I am using the "cat vs dogs sounds" from Kaggle.

One of the wav files in this DB looks like this:

These audio files are just a few seconds. The sample rate is 16KHz.

My first idea was to just actuate the motor based on the amplitude, but at 16KHz this doesn't make any sense. Also, the signal goes constantly from + to - (this is sort of ok because the motor can move in both directions), but from a human POV, what the motor does doesnt make any sense, because the movements are too rapid. I then tried to "decimate" the signal into a few points per second, but the signals seem to be badly destroyed.

DC motors are actuated using an Adafruit board, using Arduino, and then I have a Python script that interfaces with the Arduino through serial. I have this working fine, and I can make for example a loop from python that increases the speed every few seconds. My idea was to go forward or backwards based on the amplitude of the signal (if it is negative or positive), I am no expert on audio, so this might make no sense. I won't react to other sounds, only to the input wav files.

I don't really know what is the best way of transforming an audio signal of 16KHz into something that can be use to actuate a motor. At the moment I am using a DC motor, but the idea in the near future is to use leds instead, and change their intensity based on the audio signals

• Are you using this for animatronics? Like when a dog barks in the wave file, the animatron should bark timed to the wave file? – morbo Jul 13 at 12:01
• Short of yeah. Not exactly to "bark back" but "do something back". ideally I want to change the level of some LEDs, but at the moment I am happy just actuating motors. – Dr Sokoban Jul 13 at 13:04
• changing LEDs via analogwrite() or if you're using neopixels or something via a library is much easier than controlling a motor...to change the brightness/colour of LED's is trivial at 16khz...but impossible with a motor. a possible solution would be to resample your sound at the hz you're looking for...take the positive or negative half of your signal (either using a quadratic or just cutting off anything < 0 and then finding your peak via some logic and use that as your source. It'd be helpful if we had a link to one of your samples and some code...via pastebin or something. – morbo Jul 13 at 13:31
• @morbo thanks for your answers. My samples are from the kaggle vs dogs kaggle sound DB: kaggle.com/mmoreaux/audio-cats-and-dogs and then I am reading them following this: kaggle.com/connerbrown/audio-cats-and-dogs-visualization and then what I want is to use the list read, which contains just numbers, to actuate the motor. I am not sure how I can resample the audio at a lower HZ – Dr Sokoban Jul 13 at 14:01
• i read your post several times and it appears that you have not said what you are trying to do .... actuate a motor is almost meaningless ... please rewrite your post to something like i have a signal ABC. i would like the motor to do XYZ in response to DEF in the signal – jsotola Jul 13 at 20:01