Instructables
Hi my name is cenk,

i show you now, how you can make servo`s move to Audio Signals.

See in this video how it looks like :




Parts You Need :
- Any arduino
- a 1K resistor
- a Servo
- 1 LED
- 4 Jumper Wires
- 3,5 audio jack pinout(like that one from your common headphones for exemple)
- optional a soldering iron or a other method to make a good electric connection

step 1:

Cut one of the jumper wire in two parts.
(i used a allready cuttet one, therefore the different colors in the picture)

step 2:

strip the 3,5 audio jack pinout, until you can see the 3 wires inside :
you shud see, one for Left Side, Right Side and Ground.
You only need one of the L & R
now solder one peace of the cuttet wire to the
end of the resitor, then solder at the same point the resistor & wire to the choosen wire L & R
it shud look like this :
(note on the picture i soldered a nother wire, that was a project for stero, in this tutorial you can ignore the second wire without
resistor).




Step 3:

Connect the resitor to Ground on the Ardurino and the Wire end to Analog 0 Pin. By The way the other side can be pluged into any Sound
Source, your Phone, cd player etc.... in my case its my soundcard.
Connect Ardurino with your pc Open the Ardurino software and Open under File > Examples > 01 Basic > The "AnalogReadSerial" Sketch
and Upload that.
Start the Serial Monitor (Tools > Serial Monitor) and be sure that your SoundSorce is outputting Signals.
If you see in Serial Monitor Chaotic Readings or only a not changing Zero, you make a misstake, your readings are wrong,
if you see readings that gets higher with louder soundsignal and gets to lower numbers at not so loud parts you are right.
that looks a little bit like matrix, you only see a numbur but its realy good to see that this is sound even if you dont hear anything.

Step 4:

Allright Time to connect the Servo use the other 3 jumper wires for that,
the servo hase a Red one , Connect that one to +5v at arduino
a black one, this one goes to ground at the arduino
and a white one connect this one to Pin 9 at the arduino(9 is a PWM PIN Thats needed for a Servo)
take now your led and mount it however on that servo, connect the smaler - Pin of the LED also to Ground of Ardurino
and the + Longer LED pin to Pin 12 at your Ardurino.

Step 5:
Some Codeing...
start a new Skatch
add the code below :
Upload & Have FUn, if you like Vote for me & feel free to show me your projects with this method :) 

/*
  Make a Servo Move to Sound.
   This example code is in the public domain.
   2012 by Cenk Özdemir
*/
// for servo stuff we include the servo library
#include <Servo.h>
// creating a servo object
Servo myservo;

// Some Varuables we need
int ServoPin = 9;
int SoundInPin = A0;
int LedPin = 12;
// the setup routine runs once when you press reset:
void setup() {
  // initialize

    myservo.attach(ServoPin);
     pinMode(SoundInPin, INPUT);
     pinMode(LedPin, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(SoundInPin);
// we Maop a nother value of this for LED that can be a integer betwen 0..255 
  int LEDValue = map(sensorValue,0,512,0,255);
  // We Map it here down to the possible range of servo moovment.
  sensorValue = map(sensorValue,0,512,0,180);
  // note normaly the 512 is 1023 becouse of analog reading shud go so far, but i changed that to get better readings.
myservo.write(90);
// setting the servo into standard position
  int MoveDelayValue = map(sensorValue,0,255,0,sensorValue);

  // maping the same reading a little bit more down to calculate the time your servo gets to make the one Move
if (sensorValue > 33) { // to cut off some static readings only if the reading gets higher then 33 it begings to work
   delay(1);  // a static delay to smooth things out...
// now move the servo to our mapped reading
  myservo.write(sensorValue); 
  // turn led on with the calculated value for it
  analogWrite(LedPin, sensorValue); 
         // and do that move in this delay time
  
  delay(MoveDelayValue); 
} // Done. now we close that part.
   // turn off the led again.
      analogWrite(LedPin, 0); 
      // and this repeats all the time.
}

A simple project with so much potential applications. applaud..great subject

pcmodder199711 months ago
One thing that would make that better is if you replaced the led with a laser
I don't totally understand, how many times are you sampling the audio per second?
sfool (author)  amandaghassaei1 year ago
Try it :)
sfool (author)  amandaghassaei1 year ago
:), I do not know exactly

as often as possible, the sketch does nothing else.
if you read any other thing with analogRead that much what ardurino is doing it,

the value it reads, gets mapped two times, first to LEDValue 0..255 for a analogwrite of the led, and then to sensorValue betwen 0 .. 180 becouse the range of an servo goes only to 180. a there is a nother maped value its for the time the servo hase to make that movement, after mapping that 3 variables, i only say ServoWrite, the servo delay and the led, after that loop, its setting the servo back to starting pos, the led off by setting it to 0, and re-.Reads the analog In. :)