my goal have sound effect play when person first walks field of view of pir. far can work, sound "stutters" 4 seconds before play through way.
the parts using are:
https://www.parallax.com/product/555-28027
http://www.mdfly.com/products/microsd-tf-card-mp3-wav-player-module-ttl.html (datasheet: http://mdfly.oss-cn-hangzhou.aliyuncs.com/board%2faudio%2fau5017.pdf )
and arduino uno
besides vcc , ground, arduino's pins connect pin7 mp3 board's number 1 pin (which active low) , arduino's pin3 out/signal pir sensor.
i have tried couple different example sketches , modified them thought work, both have similar problems "stuttering". below sketches after modification. (note: haven't finished changing of commenting yet.)
i thankful , help. can admit, i'm not @ kind of thing. project halloween in 2016. i'm bad (and realize it) i'm starting year in advance.
first sketch:
second sketch:
the parts using are:
https://www.parallax.com/product/555-28027
http://www.mdfly.com/products/microsd-tf-card-mp3-wav-player-module-ttl.html (datasheet: http://mdfly.oss-cn-hangzhou.aliyuncs.com/board%2faudio%2fau5017.pdf )
and arduino uno
besides vcc , ground, arduino's pins connect pin7 mp3 board's number 1 pin (which active low) , arduino's pin3 out/signal pir sensor.
i have tried couple different example sketches , modified them thought work, both have similar problems "stuttering". below sketches after modification. (note: haven't finished changing of commenting yet.)
i thankful , help. can admit, i'm not @ kind of thing. project halloween in 2016. i'm bad (and realize it) i'm starting year in advance.
first sketch:
code: [select]
// uses pir sensor detect movement, buzzes buzzer
// more info here: http://blog.makezine.com/projects/pir-sensor-arduino-alarm/
// email me, john park, @ jp@jpixl.net
// based upon:
// pir sensor tester limor fried of adafruit
// tone code michael@thegrebs.com
int mp3song1pin = 7; // choose pin mp3 board
int inputpin = 3; // choose input pin (for pir sensor)
int pirstate = low; // start, assuming no motion detected
int val = 0; // variable reading pin status
void setup() {
pinmode(mp3song1pin, output); // declare mp3 board output
pinmode(inputpin, input); // declare sensor input
serial.begin(9600);
}
void loop(){
val = digitalread(inputpin); // read input value
if (val == high) { // check if input high
digitalwrite(mp3song1pin, low); // turn mp3 board on
delay(10);
digitalwrite(mp3song1pin, high); // turn mp3 board
if (pirstate == low) {
// have turned on
serial.println("motion detected!");
// want print on output change, not state
pirstate = high;
}
} else {
digitalwrite(mp3song1pin, high); // turn mp3 board off
if (pirstate == high){
// have turned off
serial.println("motion ended!");
// want print on output change, not state
pirstate = low;
}
}
}
second sketch:
code: [select]
/*
* //////////////////////////////////////////////////
* //making sense of parallax pir sensor's output
* //////////////////////////////////////////////////
*
* switches led according state of sensors output pin.
* determines beginning , end of continuous motion sequences.
*
* @author: kristian gohlke / krigoo (_) gmail (_) com / http://krx.at
* @date: 3. september 2006
*
* kr1 (cleft) 2006
* released under creative commons "attribution-noncommercial-sharealike 2.0" license
* http://creativecommons.org/licenses/by-nc-sa/2.0/de/
*
*
* parallax pir sensor easy use digital infrared motion sensor module.
* (http://www.parallax.com/detail.asp?product_id=555-28027)
*
* sensor's output pin goes high if motion present.
* however, if motion present goes low time time,
* might give impression no motion present.
* program deals issue ignoring low-phases shorter given time,
* assuming continuous motion present during these phases.
*
*/
/////////////////////////////
//vars
//the time give sensor calibrate (10-60 secs according datasheet)
int calibrationtime = 30;
//the time when sensor outputs low impulse
long unsigned int lowin;
//the amount of milliseconds sensor has low
//before assume motion has stopped
long unsigned int pause = 5000;
boolean locklow = true;
boolean takelowtime;
int pirpin = 3; //the digital pin connected pir sensor's output
int ledpin = 7;
/////////////////////////////
//setup
void setup(){
serial.begin(9600);
pinmode(pirpin, input);
pinmode(ledpin, output);
digitalwrite(pirpin, low);
//give sensor time calibrate
serial.print("calibrating sensor ");
for(int = 0; < calibrationtime; i++){
serial.print(".");
delay(1000);
}
serial.println(" done");
serial.println("sensor active");
delay(50);
}
////////////////////////////
//loop
void loop(){
if(digitalread(pirpin) == high){
digitalwrite(ledpin, low); //the led visualizes sensors output pin state
delay(50);
digitalwrite(ledpin, high);
if(locklow){
//makes sure wait transition low before further output made:
locklow = false;
serial.println("---");
serial.print("motion detected @ ");
serial.print(millis()/1000);
serial.println(" sec");
delay(50);
}
takelowtime = true;
}
if(digitalread(pirpin) == low){
digitalwrite(ledpin, high); //the led visualizes sensors output pin state
if(takelowtime){
lowin = millis(); //save time of transition high low
takelowtime = false; //make sure done @ start of low phase
}
//if sensor low more given pause,
//we assume no more motion going happen
if(!locklow && millis() - lowin > pause){
//makes sure block of code executed again after
//a new motion sequence has been detected
locklow = true;
serial.print("motion ended @ "); //output
serial.print((millis() - pause)/1000);
serial.println(" sec");
delay(50);
}
}
}
so, i've been scratching head few days , have come solution. code below identical second sketch above slight modification. relevant area shown in bold(cant bold in code. instead, these:@#@#@#@#@#@) . sound effect starts right want to. helps out similar project.
code: [select]
/*
* //////////////////////////////////////////////////
* //making sense of parallax pir sensor's output
* //////////////////////////////////////////////////
*
* switches led according state of sensors output pin.
* determines beginning , end of continuous motion sequences.
*
* @author: kristian gohlke / krigoo (_) gmail (_) com / http://krx.at
* @date: 3. september 2006
*
* kr1 (cleft) 2006
* released under creative commons "attribution-noncommercial-sharealike 2.0" license
* http://creativecommons.org/licenses/by-nc-sa/2.0/de/
*
*
* parallax pir sensor easy use digital infrared motion sensor module.
* (http://www.parallax.com/detail.asp?product_id=555-28027)
*
* sensor's output pin goes high if motion present.
* however, if motion present goes low time time,
* might give impression no motion present.
* program deals issue ignoring low-phases shorter given time,
* assuming continuous motion present during these phases.
*
*/
/////////////////////////////
//vars
//the time give sensor calibrate (10-60 secs according datasheet)
int calibrationtime = 30;
//the time when sensor outputs low impulse
long unsigned int lowin;
//the amount of milliseconds sensor has low
//before assume motion has stopped
long unsigned int pause = 1000;
boolean locklow = true;
boolean takelowtime;
int pirpin = 3; //the digital pin connected pir sensor's output
int ledpin = 7; //the digital pin connected mp3 board's number 1 pin
/////////////////////////////
//setup
void setup(){
serial.begin(9600);
pinmode(pirpin, input);
pinmode(ledpin, output);
digitalwrite(pirpin, low);
//give sensor time calibrate
serial.print("calibrating sensor ");
for(int = 0; < calibrationtime; i++){
serial.print(".");
delay(1000);
}
serial.println(" done");
serial.println("sensor active");
delay(50);
}
////////////////////////////
//loop
void loop(){
if(digitalread(pirpin) == high){
if(locklow){
//makes sure wait transition low before further output made:
locklow = false;
serial.println("---");
serial.print("motion detected @ ");
serial.print(millis()/1000);
serial.println(" sec");
@#@#@#@#@#@ digitalwrite(ledpin, low); //the led visualizes sensors output pin state
delay(50);
digitalwrite(ledpin, high);
delay(50);@#@#@#@#@#@
}
takelowtime = true;
}
if(digitalread(pirpin) == low){
digitalwrite(ledpin, high); //the led visualizes sensors output pin state
if(takelowtime){
lowin = millis(); //save time of transition high low
takelowtime = false; //make sure done @ start of low phase
}
//if sensor low more given pause,
//we assume no more motion going happen
if(!locklow && millis() - lowin > pause){
//makes sure block of code executed again after
//a new motion sequence has been detected
locklow = true;
serial.print("trigger ready! "); //output
delay(50);
}
}
}
Arduino Forum > Using Arduino > Project Guidance > Using a PIR to trigger an MP3 board, but the audio stutters
arduino
Comments
Post a Comment