VMA02 + PIR sensor

Hello Velleman projects forum,

I need to trigger a VMA02 shield which would reproduce a sound, with a PIR sensor movement of Arduino.

With the provides codes,
I managed to activate both separately,
I mean, the PIR sensor activates a led,
and,
the VMA02 shield activates the recorded sounds through the bottoms.

//VMA02 code//
#include <ISD1700.h>
ISD1700 chip(10); // Initialize chipcorder with
// SS at Arduino’s digital pin 10

int apc=0;
int vol=0; //volume 0=MAX, 7=min
int startAddr=0x10;
int endAddr =0x2DF;
int inInt=0;
void setup()
{
apc = apc | vol; //D0, D1, D2

//apc = apc | 0x8; //D3 comment to disable output monitor during record

apc = apc | 0x50; // D4& D6 select MIC REC
//apc = apc | 0x00; // D4& D6 select AnaIn REC
//apc = apc | 0x10; // D4& D6 select MIC + AnaIn REC

apc = apc | 0x80; // D7 AUX ON, comment enable AUD

apc = apc | 0x100; // D8 SPK OFF, comment enable SPK

//apc = apc | 0x200; // D9 Analog OUT OFF, comment enable Analog OUT

//apc = apc | 0x400; // D10 vAlert OFF, comment enable vAlert

apc = apc | 0x800; // D11 EOM ON, comment disable EOM

Serial.begin(9600);
Serial.println(“Sketch is starting up”);
}
void loop()
{
char c;

if(Serial.available())
{
/* Power Up */
chip.pu();
c = Serial.read();
switch©
{
case ‘A’:
Serial.println(chip.rd_apc(), BIN);
break;
case ‘Y’:
chip.play();
break;
case ‘P’:
chip.stop();
delay(500);
break;
case ‘E’:
chip.erase();
delay(500);
break;
case ‘R’:
chip.rec();
break;
case ‘F’:
chip.fwd();
delay(500);
break;
case ‘Z’:
chip.g_erase();
delay(500);
break;
case ‘I’:
Serial.println(chip.devid(), BIN);
break;
case ‘W’:
Serial.println(apc, BIN);
chip.wr_apc2(apc); //
break;
case ‘S’:
Serial.println(chip.rd_status(), BIN);
break;
case ‘>’:
startAddr=SerialIn();
Serial.print("startAddr: ");
Serial.println(startAddr);
break;
case ‘<’:
endAddr=SerialIn();
Serial.print("endAddr: ");
Serial.println(endAddr);
break;
case ‘y’:
chip.set_play(startAddr,endAddr);
break;
case ‘r’:
//chip.set_erase(startAddr,endAddr);
//delay(500);
chip.set_rec(startAddr,endAddr);
break;
case ‘e’:
chip.set_erase(startAddr,endAddr);
delay(500);
break;

}
Serial.print("Status—> ");
Serial.print(chip.CMD_ERR()? "CMD_ERR ": "OK ");
Serial.print(chip.PU()? "PU ": "NO PU ");
Serial.print(chip.RDY()? "RDY ": "Not_RDY ");
Serial.print(chip.rd_status(), BIN);
Serial.println();
delay(1000);
}
}
int SerialIn(){
inInt=0;

while (Serial.available() <= 0)
{
delay(300);
}
while (Serial.available()) {
// get the new byte:
char c = Serial.read();
// add it to the inputString:
inInt = (inInt*10) + (c-48);
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (c == ‘\n’) {
//stringComplete = true;
Serial.print("stringComplete ");
}
}
//c = Serial.read()-48;
//mess©;
return (inInt);

                   }
                   /*
                   void mess(int num){

Serial.print("num: ");
Serial.println(num);
startAddr=(0x50*num)+0x10;
endAddr=(startAddr+0x50)-1;
Serial.print("startAddr: “);
Serial.print(startAddr, HEX);
Serial.print(” - endAddr: ");
Serial.println(endAddr, HEX);

}
*/

//PIR code//

/*

  • //////////////////////////////////////////////////
  • //making sense of the Parallax PIR sensor’s output
  • //////////////////////////////////////////////////
  • Switches a LED according to the state of the sensors output pin.
  • Determines the beginning and end of continuous motion sequences.
  • @author: Kristian Gohlke / krigoo () gmail () com / krx.at
  • @date: 3. September 2006
  • kr1 (cleft) 2006
  • released under a creative commons “Attribution-NonCommercial-ShareAlike 2.0” license
  • creativecommons.org/licenses/by-nc-sa/2.0/de/
  • The Parallax PIR Sensor is an easy to use digital infrared motion sensor module.
  • (parallax.com/detail.asp?product_id=555-28027)
  • The sensor’s output pin goes to HIGH if motion is present.
  • However, even if motion is present it goes to LOW from time to time,
  • which might give the impression no motion is present.
  • This program deals with this issue by ignoring LOW-phases shorter than a given time,
  • assuming continuous motion is present during these phases.

*/

/////////////////////////////
//VARS
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;

//the time when the sensor outputs a low impulse
long unsigned int lowIn;

//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 5000;

boolean lockLow = true;
boolean takeLowTime;

int pirPin = 3; //the digital pin connected to the PIR sensor’s output
int ledPin = 13;

/////////////////////////////
//SETUP
void setup(){
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(pirPin, LOW);

//give the sensor some time to calibrate
Serial.print(“calibrating sensor “);
for(int i = 0; i < calibrationTime; i++){
Serial.print(”.”);
delay(1000);
}
Serial.println(" done");
Serial.println(“SENSOR ACTIVE”);
delay(50);
}

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

 if(digitalRead(pirPin) == HIGH){
   digitalWrite(ledPin, HIGH);   //the led visualizes the sensors output pin state
   if(lockLow){  
     //makes sure we wait for a transition to LOW before any further output is made:
     lockLow = false;            
     Serial.println("---");
     Serial.print("motion detected at ");
     Serial.print(millis()/1000);
     Serial.println(" sec"); 
     delay(50);
     }         
     takeLowTime = true;
   }

 if(digitalRead(pirPin) == LOW){       
   digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state

   if(takeLowTime){
    lowIn = millis();          //save the time of the transition from high to LOW
    takeLowTime = false;       //make sure this is only done at the start of a LOW phase
    }
   //if the sensor is low for more than the given pause, 
   //we assume that no more motion is going to happen
   if(!lockLow && millis() - lowIn > pause){  
       //makes sure this block of code is only executed again after 
       //a new motion sequence has been detected
       lockLow = true;                        
       Serial.print("motion ended at ");      //output
       Serial.print((millis() - pause)/1000);
       Serial.println(" sec");
       delay(50);
       }
   }

}

I need to unify both mechanisms,
Activate a sound triggered by the PIR sensor.

If someone can help me,
I would appreciate it.

If you help me to solve it,
I will post here a link of our website,
in where you will find information such as videos, to explain a technological art exhibition we are developing.

We unveil the exhibition on 20th of January.

Kind regards.