Hi All thanks for everyones help so far ive managed to now build the mouth on a board which i operated by a servo for movement.
The only problem is please could someone tell me how to add a sound file which plays at the same time as the servo movement!
Please help!
Heres the code i have so far excluding the wav file
///////// BILLY MOUTH MOVE ///////////////
#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 = 11; ///////////////////// 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(3); // 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(3); // 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);
}
}
}