How to Move a Servo With Music

I have 2 Arduino Uno's.

The first one is a music player made like this one:

It plays wav files stored on a micro SD card. The music files are :
Bit Res. = 8 bit, Sample Rate = 16000 Hz, Mono, Unsigned PCM 8 bit.

The second Arduino has a KY-037 4 pin Sound detection Module and a servo.

I posted my problem and UKHelliBob was kind enough to help me write the following code:

#include <Servo.h>

Servo MyServo;

int ServoPin = 9;
int sensorValue;
int Rcvd[] = {88, 89, 90, 91, 92, 93, 94};
int Pos[] = {0, 30, 60, 90, 120, 150, 180};
int n;

void setup() {

void loop() {

  sensorValue = analogRead(0);
  sensorValue = map(sensorValue, 0, 1023, 0, 180);

  for (n = 0; n < 7; n++) {

    if (sensorValue == Rcvd[n]) {




But the results are not satisfactory. i.e. it picks up noise and servo movement does
not matches the music in any way.
Back to the books, I read all I could find and have found nothing other that making
a UV meter or using FFT procedure. Uv meter is easy with led's but servos are not
fast enough.
I tried FFT (a bit over my head) but could not implement it.

I just need to get the servo move to the " tempo " (bpm) of the music.

Appreciate your help and suggestions.

What is the "fastest" servo you have been able to find?



Her's the data sheet for the SG90 servo I'm using, it says Speed (sec.)= 0.1


Her's the data sheet for the SG90 servo I'm using, it says Speed (sec.)= 0.1

That number is meaningless. You are looking for something that is NOT geared. Geared will reduce the reaction time for the arm by the gear ratio. You need a direct drive servo to do what you are asking it to do. No, I don't know of one.


An SG90 is a small, cheap, not very fast servo. It's theoretical operating speed at 5V is 0.12 second per 60 degrees.

So how far do you expect it to move for each beat and how fast in BPM is the music you want it to follow? Oh and what exact movements do you expect it make?

The code you have seems to only move the servo if the sensor value just happens to map to a specific value close to 90. Do you have any idea why that is?


Yes my servos are indeed the cheap ones, I'm using 25 of them for my project.


I mapped the numbers I was reading from the sound sensor, in a second attempt
I tried refining it by 20 instead of 30

int Rcvd[] = {85, 86, 87, 88, 89, 90, 91, 92, 93, 94};
int Pos[] = {0, 20, 40, 60, 80, 100, 120, 140, 160, 180};

I got a little better results. It doesn't do just 90 degrees.
What movements ? any movement will do.
What bpm ? I can choose slow music, maybe a Waltzer, a tango.

Can I read the values directly from the output pin that feeds the speaker and not use a sound sensor microphone? Stupid question ??

"Yes my servos are indeed the cheap ones, I'm using 25 of them for my project."

You might need to explain your project more fully. If the servos are too slow, what is your movement expatiation for them? The speed on some servos can be increased by removing a gear, but with a loss of torque.

No torque problem since they just move an icicle stick attached to them.
I could modify them, but would like to know if I'm on the right track using a sound sensor
or if there's a better way.