please help!!!

Hi everyone im trying to create a pir sensor to switch on a servo and wave shield at the same time.
I have managed to do both seperately but when combining the two results in Error Compilling. please help!!!

#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include <WaveHC.h>
#include <WaveUtil.h>
#include <Servo.h> 

SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the filesystem on the card
FatReader f;      // This holds the information for the file we're play

WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

// this handy function will return the number of bytes currently free in RAM, great for debugging!   
int freeRam(void)
{
  extern int  __bss_end; 
  extern int  *__brkval; 
  int free_memory; 
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end); 
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval); 
  }
  return free_memory; 
} 

void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  putstring("\n\rSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  putstring(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}

///////////////////////////////////////////////////////////

Servo myservo;  // create servo object to control a servo 
// a maximum of eight servo objects can be created

////////////////////////////////////////////////////////////////// 
int pos = 0;    // variable to store the servo position 

int calibrationTime = 0;       

long unsigned int lowIn;        

long unsigned int pause = 5000; 

boolean lockLow = true;
boolean takeLowTime; 
/////////////////////////////////////////////////////////////////////////

int pirPin = 8;    ///////////////////// pir sensor pin

/////////////////////////////////////////setup

void setup() 
{ 
  myservo.attach(16);  // attaches the servo on pin 9 to the servo object
  Serial.begin(9600);
  pinMode(pirPin, INPUT);

  // Set the output pins for the DAC control. This pins are defined in the library
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);

  Serial.println("calibrating sensor ");
  for(int i = 0; i < calibrationTime; i++){
    Serial.print(calibrationTime - i);
    Serial.print("-");
    delay(1000);
  }
  Serial.println();
  Serial.println("done");
  while (digitalRead(pirPin) == HIGH) {
    delay(500);
    Serial.print(".");     
  }
  Serial.print("SENSOR ACTIVE");
  delay(1000);
  
//  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!)  
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
    sdErrorCheck();
    while(1);                            // then 'halt' - do nothing!
  }
  
  // enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);
 
// Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {     // we have up to 5 slots to look in
    if (vol.init(card, part)) 
      break;                             // we found one, lets bail
  }
  if (part == 5) {                       // if we ended up not finding one  :(
    putstring_nl("No valid FAT partition!");
    sdErrorCheck();      // Something went wrong, lets print out why
    while(1);                            // then 'halt' - do nothing!
  }
  
  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(),DEC);     // FAT16 or FAT32?
  
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!"); // Something went wrong,
    while(1);                             // then 'halt' - do nothing!
  }
  
  // Whew! We got past the tough parts.
  putstring_nl("Ready!");
}
  
//////////////////////////////////////////////// loop 

void loop() {

  if(digitalRead(pirPin) == HIGH){

    for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 90 degrees 
    {                                  // in steps of 1 degree 
      myservo.write(pos);              // tell servo to go to position in variable 'pos' 
      delay(4);                       // waits 4ms for the servo to reach the position 
    } 
    for(pos = 90; pos>=1; pos-=1)     // goes from 90 degrees to 0 degrees 
    {                                
      myservo.write(pos);              // tell servo to go to position in variable 'pos' 
      delay(4);                       // waits 4ms for the servo to reach the position 
    } 
    if(lockLow){ 

      lockLow = false;           
      Serial.println("---");
      Serial.print("motion detected at ");
      Serial.print(millis()/1000);
      Serial.println(" sec");
      delay(50);
    }        
    takeLowTime = true;
  }

  if(digitalRead(pirPin) == LOW){      

    if(takeLowTime){
      lowIn = millis();
      takeLowTime = false;
    }

    if(!lockLow && millis() - lowIn > pause){ 

      lockLow = true;                       
      Serial.print("motion ended at ");
      Serial.print((millis() - pause)/1000);
      Serial.println(" sec");
      delay(50);

      playcomplete("PUPPET~1.WAV");

    }
  }
 } 


// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
  // call our helper to find and play this name
  playfile(name);
  while (wave.isplaying) {
  // do nothing while its playing
  }
  // now its done playing
}

void playfile(char *name) {
  // see if the wave object is currently doing something
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
  }
  // look in the root directory and open the file
  if (!f.open(root, name)) {
    putstring("Couldn't open file "); Serial.print(name); return;
  }
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV"); return;
  }
  
  // ok time to play! start playback
  wave.play();
}

Many Thanks

There is a compiler error, but you're not going to tell us what it is?

Hi Arrch i will post the error here see if it helps

Servo\Servo.cpp.o: In function __vector_11': C:\Program Files (x86)\Arduino\libraries\Servo/Servo.cpp:103: multiple definition of __vector_11'
WaveHC\WaveHC.cpp.o:C:\Users\djdc23\Documents\Arduino\libraries\libraries\WaveHC/WaveHC.cpp:41: first defined here

Thanks

You have conflicting timers.

The Wave shield uses timer1 to drive it. Timer1 is also used by default in the Servo library.

You can disable Timer1 in the Servo library by editing Servo.h and commenting out all the lines that say:

#define _useTimer1

There's a number of them for different chips. Best to do them all then you're sure to get the one for your board.

Thanks Majenko this really helped i just changed the servo to an int rather than the servo library so it sort of works the only thing is im trying to figure out how to add in the servo in the void loop part and im there! :slight_smile:

please help as im now stuck on moving the servo to sound. So far I have managed to code wiring a sensor playing a wav file and moving a servo motor to the wav file. The only problem is the servo moves very slight i am trying to move it 0 degrees to 90 degrees and back again.
Do i need to change the pulse width or ???

heres the code

//////////////////////////////////////////////////////////////////// libraries
#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include <WaveHC.h>
#include <WaveUtil.h>
///////////////////////////////////////////////////////// constant pins, values
#define DEBOUNCE 100
#define swPin 14


SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the filesystem on the card
FatReader f;      // This holds the information for the file we're play

WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

// this handy function will return the number of bytes currently free in RAM, great for debugging!   
int freeRam(void)
{
  extern int  __bss_end; 
  extern int  *__brkval; 
  int free_memory; 
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end); 
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval); 
  }
  return free_memory; 
} 

void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  putstring("\n\rSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  putstring(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}

///////////////////////////////////////////////////////////////////////////////////////////

int inputPin = 8;               // choose the input pin (for PIR sensor)
int servoPin = 16;              // choose the input pin (for Servo)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status for motion sensor
int minPulse     =  600;  // minimum servo position
int maxPulse     =  2200; // maximum servo position
int turnRate     =  1800;  // servo turn rate increment (larger value, faster rate)
int refreshTime  =  0;   // time (ms) between pulses (50Hz)
int mouthchange = 6;  //checks to see if mouth position needs to be changed



/** The Arduino will calculate these values for you **/
int centerServo;         // center servo position
int pulseWidth;          // servo pulse width
long lastPulse   = 0;    // recorded time (ms) of the last pulse

/////////////////////////////////////////////////////////////////////////// setup

void setup() {

  pinMode(inputPin, INPUT);     // declare sensor as input for PIR
  
  digitalWrite(inputPin, HIGH);

  // set up servo pin
  pinMode(servoPin, OUTPUT);  // Set servo pin 18 (analog 4) as an output pin
  centerServo = maxPulse - ((maxPulse - minPulse)/2);
  pulseWidth = centerServo;   // Give the servo a starting point (or it floats)

  // set up serial port
  Serial.begin(9600);


  putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
  Serial.println(freeRam());      // if this is under 150 bytes it may spell trouble!

  // Set the output pins for the DAC control. This pins are defined in the library
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);

  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!)  
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
    sdErrorCheck();
    while(1);                            // then 'halt' - do nothing!
  }

  // enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);

  // Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {     // we have up to 5 slots to look in
    if (vol.init(card, part)) 
      break;                             // we found one, lets bail
  }
  if (part == 5) {                       // if we ended up not finding one  :(
    putstring_nl("No valid FAT partition!");
    sdErrorCheck();      // Something went wrong, lets print out why
    while(1);                            // then 'halt' - do nothing!
  }

  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(),DEC);     // FAT16 or FAT32?

  // Try to open the root directory
  if (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!"); // Something went wrong,
    while(1);                             // then 'halt' - do nothing!
  }

  // Whew! We got past the tough parts.
  putstring_nl("Ready!");

}

//////////////////////////////////////////////////////////// loop
void loop() {

  val = digitalRead(inputPin);  // read input value

  if (val == HIGH)          // check if the input is LOW
  {
    if (pirState == LOW)
    {
      Serial.println("Motion Detected!");
      playcomplete("PUPPET~1.WAV");
      delay(5);

     }
  }
}
  

// Plays a full file from beginning to end with no pause.

void playcomplete(char *name) {
  char i;
  uint8_t volume;
  int v2;

  playfile(name);

  while (wave.isplaying)
  {
    volume = 0;
    for (i=0; i<8; i++)
    {
      v2 = analogRead(1);
      delay(1);
    } 
    if (v2 > 440)
    {  
      pulseWidth = 1800;
      mouthchange = 1;
    }
    else
    { 
      pulseWidth = 800;
      mouthchange = 1;
    } 
    digitalWrite(servoPin, HIGH);   // start the pulse
    delayMicroseconds(pulseWidth);  // pulse width
    digitalWrite(servoPin, LOW);    // stop the pulse
  }
}


void playfile(char *name)
{ 
  //////// stop any file already playing//////////////////////////
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
  }
  // look in the root directory and open the file
  if (!f.open(root, name)) {
    putstring("Couldn't open file "); 
    Serial.print(name); 
    return;
  }
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV"); 
    return;
  }

  // ok time to play! start playback
  wave.play();
}

Thanks again this site and people on here have been really helpful :slight_smile:

There's more to controlling a servo than just the pulse width.

The pulse has to happen at the proper frequency. Typical servos require around 50Hz pulses, with the duty cycle lasting between around 800uS and 2ms for 0° to 180° - actual values vary depending on the servo.

Your analogue reading loop with the delay(1) plus the overhead of the rest of that loop gives around a 120Hz pulse (not including whatever extra time the wave shield causes - that depends on your sound file bitrate). You might want to slow that down a little.

Also, you are reading the analogue input 8 times and using the last value. That will be an instantaneous volume, not an average or peak volume. Remember - sound is a waveform. You read 8 points along that waveform and use the last. I would have though sampling rapidly over a short period and calculating a good value to use from that might be better - maybe repeatedly sample for say 10ms (tip: use millis()) and using the maximum value read would be a good start.

Thanks for the reply Majenko! Im still a bit confused. Ive adapted the code and it runs as fast as i need it to be as its a puppet laugh wav file
just would like to know how to increase the servo from 0-90 degrees as it currently at a guestimate runs about 45 to 55 ish

Thanks again heres the new code

//////////////////////////////////////////////////////////////////// libraries
#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include <WaveHC.h>
#include <WaveUtil.h>
///////////////////////////////////////////////////////// constant pins, values
#define DEBOUNCE 100
#define swPin 14


SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the filesystem on the card
FatReader f;      // This holds the information for the file we're play

WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

// this handy function will return the number of bytes currently free in RAM, great for debugging!   
int freeRam(void)
{
  extern int  __bss_end; 
  extern int  *__brkval; 
  int free_memory; 
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end); 
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval); 
  }
  return free_memory; 
} 

void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  putstring("\n\rSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  putstring(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}

///////////////////////////////////////////////////////////////////////////////////////////

int inputPin = 8;               // choose the input pin (for PIR sensor)
int servoPin = 16;              // choose the input pin (for Servo)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status for motion sensor
int minPulse     =  600;  // minimum servo position
int maxPulse     =  2200; // maximum servo position
int turnRate     =  1800;  // servo turn rate increment (larger value, faster rate)
int refreshTime  =  0;   // time (ms) between pulses (50Hz)
int mouthchange = 6;  //checks to see if mouth position needs to be changed



/** The Arduino will calculate these values for you **/
int centerServo;         // center servo position
int pulseWidth;          // servo pulse width
long lastPulse   = 0;    // recorded time (ms) of the last pulse

/////////////////////////////////////////////////////////////////////////// setup

void setup() {

  pinMode(inputPin, INPUT);     // declare sensor as input for PIR
  
  digitalWrite(inputPin, HIGH);

  // set up servo pin
  pinMode(servoPin, OUTPUT);  // Set servo pin 18 (analog 4) as an output pin
  centerServo = maxPulse - ((maxPulse - minPulse)/2);
  pulseWidth = centerServo;   // Give the servo a starting point (or it floats)

  // set up serial port
  Serial.begin(9600);


  putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
  Serial.println(freeRam());      // if this is under 150 bytes it may spell trouble!

  // Set the output pins for the DAC control. This pins are defined in the library
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);

  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!)  
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
    sdErrorCheck();
    while(1);                            // then 'halt' - do nothing!
  }

  // enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);

  // Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {     // we have up to 5 slots to look in
    if (vol.init(card, part)) 
      break;                             // we found one, lets bail
  }
  if (part == 5) {                       // if we ended up not finding one  :(
    putstring_nl("No valid FAT partition!");
    sdErrorCheck();      // Something went wrong, lets print out why
    while(1);                            // then 'halt' - do nothing!
  }

  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(),DEC);     // FAT16 or FAT32?

  // Try to open the root directory
  if (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!"); // Something went wrong,
    while(1);                             // then 'halt' - do nothing!
  }

  // Whew! We got past the tough parts.
  putstring_nl("Ready!");

}

//////////////////////////////////////////////////////////// loop
void loop() {

  val = digitalRead(inputPin);  // read input value

  if (val == HIGH)          // check if the input is LOW
  {
    if (pirState == LOW)
    {
      Serial.println("Motion Detected!");
      playcomplete("PUPPET~1.WAV");
      delay(5);

     }
  }
}
  

// Plays a full file from beginning to end with no pause.

void playcomplete(char *name) {
  char i;
  uint8_t volume;
  int v2;

  playfile(name);

  while (wave.isplaying)
  {
    volume = 0;
    for (i=0; i<50; i++)
    {
      v2 = analogRead(1);
      delay(2);
    } 
    if (v2 > 440)
    {  
      pulseWidth = 1800;
      mouthchange = 1;
    }
    else
    { 
      pulseWidth = 800;
      mouthchange = 1;
    } 
    digitalWrite(servoPin, HIGH);   // start the pulse
    delayMicroseconds(pulseWidth);  // pulse width
    digitalWrite(servoPin, LOW);    // stop the pulse
  }
}


void playfile(char *name)
{ 
  //////// stop any file already playing//////////////////////////
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
  }
  // look in the root directory and open the file
  if (!f.open(root, name)) {
    putstring("Couldn't open file "); 
    Serial.print(name); 
    return;
  }
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV"); 
    return;
  }

  // ok time to play! start playback
  wave.play();
}

You’re still using the final instantaneous analogue reading:

    volume = 0;
    for (i=0; i<50; i++)
    {
      v2 = analogRead(1);
      delay(2);
    }

You have a volume variable that you’re not using - maybe you should:

    volume = 0;
    v2 = 0;
    for (i=0; i<50; i++)
    {
      volume = analogRead(1);
      // Remember this value if it's the biggest so far
      if (volume > v2) {
        v2 = volume;
      }
      delay(2);
    }

Majenko thanks for your help so far im a complete noob not understanding anything i have in the code as it was mainly copied from a project done called "arduino talking skull" so with that in mind could you please tell me how to use a volume variable instead?

Many Thanks for you help so far.

I already did.

Here it is again with more comments.

    v2 = 0;    // Start with a max volume of 0
    for (i=0; i<50; i++)
    {
      volume = analogRead(1);  // Read the instantaneous volume

      if (volume > v2) {   // If the instantaneous volume is greater than the max volume then
        v2 = volume;    // save it as the new max volume
      }

      delay(2);
    }

Thanks Majenko youve been a great help yeah sorry i missed that example in the last post i think its worked thanks again
:slight_smile:

Thanks for your help Majenko! Im sorry but im not sure its enough to move the servo! :frowning: whats the max i need to the signal or volume to increase the angle of servo im trying to accomplish. I have the following sketch which is absolutely perfect for movement in servo, The only problem is as it uses servo library so i dont know how to add my wav file :frowning: aswell.

please advise

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 

int calibrationTime = 0;       

long unsigned int lowIn;        

long unsigned int pause = 5000; 

boolean lockLow = true;
boolean takeLowTime; 
/////////////////////////////////////////////////////////////////////////

int pirPin = 8;    ///////////////////// pir sensor pin

/////////////////////////////////////////setup

void setup() 
{ 
  myservo.attach(16);  // attaches the servo on pin 9 to the servo object
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  
  // Set the output pins for the DAC control. This pins are defined in the library
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  
  Serial.println("calibrating sensor ");
  for(int i = 0; i < calibrationTime; i++){
    Serial.print(calibrationTime - i);
    Serial.print("-");
    delay(1000);
  }
  Serial.println();
  Serial.println("done");
  while (digitalRead(pirPin) == HIGH) {
    delay(500);
    Serial.print(".");     
  }
  Serial.print("SENSOR ACTIVE");
  delay(1000);

  
}  
//////////////////////////////////////////////// loop 
 
 void loop() {

  if(digitalRead(pirPin) == HIGH){
 
  for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 90 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(4);                       // waits 4ms for the servo to reach the position 
  } 
  for(pos = 90; pos>=1; pos-=1)     // goes from 90 degrees to 0 degrees 
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(4);                       // waits 4ms for the servo to reach the position 
   } 
    if(lockLow){ 

      lockLow = false;           
      Serial.println("---");
      Serial.print("motion detected at ");
      Serial.print(millis()/1000);
      Serial.println(" sec");
      delay(50);
    }        
    takeLowTime = true;
  }

  if(digitalRead(pirPin) == LOW){      

    if(takeLowTime){
      lowIn = millis();
      takeLowTime = false;
    }

    if(!lockLow && millis() - lowIn > pause){ 

      lockLow = true;                       
      Serial.print("motion ended at ");
      Serial.print((millis() - pause)/1000);
      Serial.println(" sec");
      delay(50);
    }
  } 
 }

Thanks for the help I would be stuck without you guys

Now that I can't tell you, since I don't know what your schematic is. All I know is you are reading something from an analogue port. How is that analogue port connected up?

if you mean on my previous sketch int v2 is a soldered wire from resistor r7 to analogue 1 in the arduino board as this should be the way that the wav files are being read and sent to the servo to move for mouth action.

Thanks again

as this should be the way that the wav files are being read and sent to the servo to move for mouth action.

How is the data from a wav file any kind of useful input to a servo?

djdc23:
if you mean on my previous sketch int v2 is a soldered wire from resistor r7 to analogue 1 in the arduino board as this should be the way that the wav files are being read and sent to the servo to move for mouth action.

Thanks again

What is resistor R7? R7 on what? The Arduino? The Wave shield? The radio next to you on the desk? Your mother's sewing machine?

ok well thanks for the replies firstly i thought it would be good to have the mouth to my puppet open and close to the scary laughing wav file and secondly the r7 is on the wave shield ill send you the link to have a look at and see how i copied him.

the only thing ive donde different was firstly convert the af wave to wave hc and lastly i dont need led eyes

Thanks again

TBH I can't see how that code has ever worked. Don't you just love it when people without a clue write and publish projects like this?

Personally I would have the volume level triggering an animation sequence opening the mouth to the full width then closing it half way. If the sound had dropped to nothing then continue closing all the way - otherwise repeat the animation from the half-open position. I would use hardware PWM to drive the servo, rather than some dodgy delay system, and run it all with a proper FSM.

yeah tbh it does annoy me as im making a puppet from saw and thought this project sounded perfect until 5 ot 6 days ago once i ordered all the parts thinking that all i would have to do is follow the instructions and copy the code but its been a nightmare finding out that the code has changed they dont use wave af anymore etc etc.

So I would be extremely gratefull if you could asist me properly as you seem to know alot about what you are doing.

All im after is a pir sensor to switch a waveshield mp3 file on whilst moving a servo back and fourth for the mouth to open and close where i can understand and adjust the angle and speed of the servo to my satisfaction.

Please advise what is best for this project?