Introduction: Talking Arduino Halloween Skeleton

Welcome to another of my instructables!

So Halloween is upon us again and I really wanted to use the Arduino I had.  I went to the halloween store and found a skull with a hinged skull and that was the spark that began this project.  I knew that it would probably be easy to have a servo move using the arduino and have it move the skull jaw up and down.




Step 1: Gather Your Materials

you'll need stuff.  Lots of stuff.  Well...not lots of stuff, but stuff from different places.  Here's a sort of breakdown of all the stuff I used and where I got it.

Arduino Duemilanove - $34.99
http://www.makershed.com/ProductDetails.asp?ProductCode=MKSP4

Ladyada Waveshield Kit - $21.95
http://www.makershed.com/ProductDetails.asp?ProductCode=MKAD11

2 Super Bright Red LED's - $1.79 for a 2 pack
http://www.radioshack.com/product/index.jsp?productId=3096133

PIR Sensor Module - $9.99
http://www.radioshack.com/product/index.jsp?productId=2906724

A small servo - around $13.00
Bought it at a RC hobby shop here in town

A skull - around $9

A black cloak halloween costume - around $10

various bones

Speakers

Wire

PVC and fittings - from lowes or home depot

hmmm.....seeing it all written out it seems like more money that I remember spending...haha.  Still though, to get animatronic halloween things premade you'd spend a bunch more that that.  That's what I'll keep telling myself to justify this.




Step 2: Build the Sound Shield

first thing you need to do is build your sound shield.  To save from repeating the wonderful step by step tutorial that lady ada made for her sound shield, I'll just put the link here to it.  One thing to note, I had the older version of this shield and didn't realize I was looking at the newer instructions until she was telling me to install pieces that I didn't have.  haha.  Make sure you are looking at the correct instructions before you start soldering.

V1.0 instructions
http://www.ladyada.net/make/waveshield/solder10.html

V1.1 instructions
http://www.ladyada.net/make/waveshield/solder.html

Step 3: Wire Up LED's

So here's how the LED's were wired up.  They are being fed 5v from the Analog 4 spot on the arduino.  What's great about this is that the arduino feeds out 5v, the LED's each require 2.5v, so the two of them are perfect for each other.

Step 4: Wire Up Motion Sensor and Servo

Here's how the motion sensor and servo are connected up.  these diagrams are done this way because I hooked all the wires in the skull up to a small project circuit board and then used CAT-5 Network Cable to run it down to the arduino.  The network cable allowed me to have more than enough wires to run everything I needed in one convenient package.

Step 5: All Together Now!

Here's the whole set up for the wiring in the skull.  Looks fairly simple in diagram form I think...

Step 6: One Other Thing...

You need to get a voltage reading of what the power of the audio is.  What this allows is whenever the volume on the sound gets loud enough, it opens the mouth of the skull.  Then when the voltage drops, the servo closes the jaw.  Fairly simple.  We'll attach a wire from a resistor and plug that wire into one of the inputs on the arduino so we can read it in the code. 

Step 7: Put Some Wav's on Your Card!

Grab yourself 4 wav files and format them as the lady ada tells you they need to be formatted.  If you want to use my code as is, you'll have to label them as follows on the card.  If you can figure out my code, you can just rename them to whatever you change the code to.  Anyways...use these names if you don't want to modify anything:


1.wav

2.wav

11.wav

13.wav

Step 8: Hook Up the Arduino

Hook up your arduino to the computer, copy and paste this code, and put it on your arduino.

If the code isn't visible below, I included a txt file of it so you can just download it that way.

-----------------------------------------------------------------------------------------------------------------------------------

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










Step 9: Test It!

I'm sure there's some other little things I've left out.  I'll continue to add to this as I remember.  This project took me over a month and grew larger and larger as I bought more things to add to it.  If it doesn't work, and you've followed all my instructions, dig deeper!  This isn't an end all, be all instructable!  Part of the fun in these projects is making it your own.  This project came about from me combining lots of other arduino projects I've seen around the web and that really is the best way to learn new things!  Have fun!  Experiment!

Halloween Contest

Third Prize in the
Halloween Contest

Arduino Contest

Participated in the
Arduino Contest