Please help, First project Saw Billy puppet. [mod. edit]

Hi Everyone!

I am really confused with the programing side of Arduino this is my first time ever using it and so far sounds interesting but is turning out to be a nightmare!! Please help I am currently making a saw puppet billy doll which laughes when you step infront on a pir sensor.

I have combined http://www.instructables.com/id/Talking-Arduino-Halloween-Skeleton and http://www.ladyada.net/media/wavshield/wavehc_play6singlekeyonce.pde

heres my code as i recieve the errors or any other errors i have would be grateful to be rectified!!

billy_complete.ino: In function 'void loop()':
billy_complete:178: error: a function-definition is not allowed here before '{' token
billy_complete:203: error: expected `}' at end of input

#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"
#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 = 12;               // 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  =  20;   // time (ms) between pulses (50Hz)
int mouthchange = 6;  //checks to see if mouth position needs to be changed
int randNumber;   //random number variable to allow the choosing of which wav will be played


/** 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

void setup() {
  byte i;
  pinMode(inputPin, INPUT);     // declare sensor as input for PIR
  pinMode(13, OUTPUT);
  
  centerServo = maxPulse - ((maxPulse - minPulse)/2);
  pulseWidth = centerServo;   // Give the servo a starting point (or it floats)
  
    // set up serial port
  Serial.begin(9600);
  putstring_nl("WaveHC with ");
  
  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!");
 
}


void loop() {
  
  byte i;
 val = digitalRead(inputPin);

  if (val == HIGH)
  {          
    if (pirState == LOW)
    {
      // we have just turned on
     Serial.println("Motion!");
     // Play a sound: 
     randNumber = 0;
     randNumber = random(3);
if (randNumber >= 1)
{
     randNumber = random(3);
     randNumber = randNumber + 1;
     Serial.println(randNumber);
         if (randNumber == 1)
         {
           playcomplete("PUPPET~4.WAV");
         }
       
        else if (randNumber == 2)
        {
           playcomplete("PU68CO~1.WAV");
        }
       
        else if (randNumber == 3)
        {
            playcomplete("PUPPET~1.WAV");
        }
        else if (randNumber == 4)
        {
            playcomplete("PUPPET~2.WAV");
  }
} 
 
 pirState = HIGH;
 
    }
  }
 
  else
  {
    if (pirState == HIGH)
    {

      // we have just turned off
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;

     }
  }
  
// 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 IN ADVANCE!! :slight_smile:

Moderator edit : CODE TAGS

C'mon dude, turn off the CAPS Lock. That's like shouting your message.

This section of code

 pirState = HIGH;
 
    }
  }
 
  else
  {
    if (pirState == HIGH)
    {

      // we have just turned off
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;

     }
  }

appears to not be in void loop, nor in a function. Do a CTRL-T, see if your curly braces are all paired up, make sure the code is in the proper place.

sorry dont mean to be rude or shout just thought it looked for effective in caps! I appologise

Many thanks CrossRoads I have dont cnt + t and recieved the following "Auto Format Cancelled: Too many left curly braces."

Please advise (Thanks so far)

Start at the end of your code. Click to the right of each } and then scroll back to see where it's mating { is.
At some point you will find a mis-match. That will likely be in the area I described above.

ok thanks Crossroads but as im a total noob what am i looking for any examples please?

There's code here that has mismatched braces.

Thanks AWOl please advise where? Thanks

Did you try Reply #4?

void loop(){
// main code
}

you appear to have some stuff in the middle - has to be in void loop, or in a function

void function(){
//some code
}

void otherFunction(){
// some code
}

Hi Crossroads please tell me what reply#4 is?

Thanks

It's the reply on this thread marked "Reply #4"
Here

Ah Thanks AWOL and Crossroads I clicked on the right and a square was highlited on a few but i couldnt work out where it was so im looking for a different code to use. has anyone made the halloween skeleton since they introduced wave hc? ill post the website with the code on

and the old code is as follows any ideas how it doesnt work?

[code]#include "AF_wave.h"
#include "avr/pgmspace,h"
#include "util.h"
#include "wave.h"

#define DEBOUNCE 100

#define swPin 14
#define eyeleds 18

AF_Wave card;
File f;
Wavefile wave;

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  =  20;   // time (ms) between pulses (50Hz)
int mouthchange = 6;  //checks to see if mouth position needs to be changed
int randNumber;   //random number variable to allow the choosing of which wav will be played


/** 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

void setup() {
  // set up serial port
  Serial.begin(9600);
 
  pinMode(inputPin, INPUT);     // declare sensor as input for PIR
  pinMode(eyeleds, OUTPUT);     // declare sensor as output for eyes


  // 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 waveshield pins
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
 
  // open memory card
  if (!card.init_card()) {
    putstring_nl("Card init failed!"); return;
  }
  if (!card.open_partition()) {
    putstring_nl("No partition!"); return;
  }
  if (!card.open_filesys()) {
    putstring_nl("Couldn't open filesys"); return;
  }
  if (!card.open_rootdir()) {
    putstring_nl("Couldn't open dir"); return;
  }
}

void loop()
{
 
  val = digitalRead(inputPin);

  if (val == HIGH)
  {          
    if (pirState == LOW)
    {
      // we have just turned on
     Serial.println("Motion!");
     //Turn eyes on
     digitalWrite(eyeleds, HIGH);
     // Play a sound: 
     randNumber = 0;
     randNumber = random(3);
if (randNumber >= 1)
{
     randNumber = random(3);
     randNumber = randNumber + 1;
     Serial.println(randNumber);
         if (randNumber == 1)
         {
           playcomplete("11.WAV");
         }
       
        else if (randNumber == 2)
        {
            playcomplete("2.WAV");
        }
       
        else if (randNumber == 3)
        {
            playcomplete("13.WAV");
        }
        else if (randNumber == 4)
        {
            playcomplete("1.WAV");
        }
}
 


      pirState = HIGH;
 
    }
  }
 
  else
  {
    if (pirState == HIGH)
    {
      digitalWrite(eyeleds, LOW);
      // we have just turned off
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;

     }
  }


}



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(5);
      }

   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

  }
 
  card.close_file(f);
  digitalWrite(eyeleds, LOW);
  // we have just turned off 
}


void playfile(char *name)
{
  // stop any file already playing
  if (wave.isplaying)
  {
    wave.stop();
    card.close_file(f);
  }

  f = card.open_file(name);
  if (f && wave.create(f))
  {
    wave.play();
  }
}

[/code]

See that note at the end of the original post where somebody has added "Moderator edit: CODE TAGS"? That's because you didn't use CODE TAGS when posting your code. The sticky at the top of the forum has a lot of useful information including directions to use code tags. If you don't use them the forum software is going to mess up your code. You can fix that now by editing your recent post with code in it, selecting the code and clicking the # button in the edit window to add the code tags.

has anyone made anything simular to this project or even just a code to switch a wave shield from a pir would be a start?

Thanks

Thanks Peter Im new at this lol

Ok, back to your initial code listing, it is missing a } here:

 pirState = HIGH;
 
    }
  }
 
  else
  {
    if (pirState == HIGH)
    {

      // we have just turned off
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;

     }
  }
}  <<<<< add this one - to close the void loop() code.

I don't have the libraries you call out, so the best I can do is confirm that CTRL-T works, meaning the code structure is complete.

please help I have been working on this code and still can figure out the problems???

: In function 'void playcomplete(char*)':
: error: redefinition of 'void playcomplete(char*)'
: 'void playcomplete(char*)' previously defined here

#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"
#define DEBOUNCE 100
#define swPin 14
#define eyeleds 13

////////////////////////////////////////////////////////////////////////////////////
int inputPin = 12;               // 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  =  20;   // time (ms) between pulses (50Hz)
int mouthchange = 6;  //checks to see if mouth position needs to be changed
int randNumber;   //random number variable to allow the choosing of which wav will be played


/** 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
/////////////////////////////////////////////////////////////////////////////////////

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);
  
}

///////////////////////////////SETUP/////////////////////////////////////////////

void setup() {
  // 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!
 
  pinMode(inputPin, INPUT);     // declare sensor as input for PIR
  pinMode(eyeleds, OUTPUT);     // declare sensor as output for eyes


  // 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 waveshield pins
  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);

  if (val == HIGH)
  {          
  if (pirState == LOW)
  {
  // we have just turned on
  Serial.println("Motion!");
  //Turn eyes on
  digitalWrite(eyeleds, HIGH);
  // Play a sound: 
     randNumber = 0;
     randNumber = random(3);
if (randNumber >= 1)
{
     randNumber = random(3);
     randNumber = randNumber + 1;
     Serial.println(randNumber);
         if (randNumber == 1)
         {
           playcomplete("11.WAV");
         }
       
        else if (randNumber == 2)
        {
            playcomplete("2.WAV");
        }
       
        else if (randNumber == 3)
        {
            playcomplete("13.WAV");
        }
        else if (randNumber == 4)
        {
            playcomplete("1.WAV");
        }
}
 


      pirState = HIGH;
 
    }
  }
 
  else
  {
    if (pirState == HIGH)
    {
      digitalWrite(eyeleds, LOW);
      // we have just turned off
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;

}
}}

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

// Plays a full file from beginning to end with no pause.
  void playcomplete(char *name){
// see if the wave object is currently doing something
       char i;
       uint8_t volume;
       int v2;
  
  playfile(name);
  while (wave.isplaying)
  { 
       volume = 0;
       for (i=0; i<8; i++)
   {
  v2 = analogRead(1);
       delay(5);
   }
      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

  }
  }
  
 //END:main_loop

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

 // 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();
}

Thank you much appreciated!!

Please, use the auto format tool before posting

Thanks for the advice AWOL im nearly there i think lol!! ive compilled everything now but nothing happens :frowning:

please help???

here is the new code

#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"
#define DEBOUNCE 100
#define swPin 14
#define eyeleds 13
//////////////////////////////////////////////////////////////////////////////

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 = 12;               // 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  =  20;   // time (ms) between pulses (50Hz)
int mouthchange = 6;  //checks to see if mouth position needs to be changed
int randNumber;   //random number variable to allow the choosing of which wav will be played


/** 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

void setup() {

  pinMode(inputPin, INPUT);     // declare sensor as input for PIR
  pinMode(eyeleds, OUTPUT);     // declare sensor as output for eyes

  // 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!");

}


void loop() {

  val = digitalRead(inputPin);

  if (val == HIGH)
  {          
    if (pirState == LOW)
    {
      // we have just turned on
      Serial.println("Motion!");
      //Turn eyes on
      digitalWrite(eyeleds, HIGH);
      // Play a sound: 
      randNumber = 0;
      randNumber = random(3);
      if (randNumber >= 1)
      {
        randNumber = random(3);
        randNumber = randNumber + 1;
        Serial.println(randNumber);
        if (randNumber == 1)
        {
          playcomplete("PUPPET~4.WAV");
        }

        else if (randNumber == 2)
        {
          playcomplete("PU68CO~1.WAV");
        }

        else if (randNumber == 3)
        {
          playcomplete("PUPPET~1.WAV");
        }
        else if (randNumber == 4)
        {
          playcomplete("PUPPET~2.WAV");
        }
      } 

      pirState = HIGH;

    }
  }

  else
  {
    if (pirState == HIGH)
    {

      // we have just turned off
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;

    }
  }
}

// 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(5);
    } 
    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
  }


  digitalWrite(eyeleds, LOW);
  // we have just turned off 
}   
void playfile(char *name){ 

  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();
}

What does the debug output show?