Hello SparkFun Forum,
Have tested a PIR sensor using this method
https://learn.adafruit.com/pir-passive- … sing-a-pir
with good result.
Also Have hooked up a MP3 shield using the info at
https://learn.sparkfun.com/tutorials/mp … eld-hookup
and
https://www.sparkfun.com/tutorials/392
I have even got the two systems working together and
tested the system successfully using headphones.
But when I connected the two systems using amplifiers and speakers
the MP3 tracks runs over and over in an infinite loop even before
the sensor fires.
http://www.allenpitts.com/electronics/P … 150329.gifHave been over and over the logic but can’t figure out what is wrong.
Probably some silly mistake I making and can’t see because I have been
working on it so long.
Thanks.
Allen In Dallas
/*
2. * PIR sensor tester
3. */
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>
SdFat sd;
SFEMP3Shield MP3player;
int ledPin1 = 10; // choose the pin for the LED
int inputPin = 5; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup() {
//start the shield
sd.begin(SD_SEL, SPI_HALF_SPEED);
MP3player.begin();
pinMode(ledPin1, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
}
void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin1, HIGH); // turn LED ON
MP3player.playTrack(1);
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin1, LOW); // turn LED OFF
// digitalWrite(ledPin2, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}