PIR sensor to start MP3 shield

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.gif

Have 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;
    }
  }
}

Your “logic” in your code is bassackwards. If you got it to work without the headphones, I fail to see how it worked at all.

skimask:
Your “logic” in your code is bassackwards. If you got it to work without the headphones, I fail to see how it worked at all.

Hello SparkFun Forum

"Bassackwards’ does not seem to be too specific.

If it is meant that input Pin should be looking for a LOW signal instead of HIGH

perhaps its thought the PIR ibeing used is the SparkFun PIR which sends a LOW

signal. This is the HC-SR501 PIR which sends a HIGH signal:

http://www.mpja.com/download/31227sc.pdf

Allen Pitts

What’s your power source?

Power source:

SparkFun Product number TOL-00298

Wall Adapter Power Supply - 9VDC 650mA

https://www.sparkfun.com/products/298

Hello skimask and Forum,

Before the MP3 would play Track01 (the only track on the SD card) over and over.

Redid the breadboard double checking that it is exactly as shown in the Fritz shown below.

This time no sound at all

and

  1. The LED shown in the Fritz just above the PIR that is connected between

the PIR signal and ground was cycling the way it does in test: 2 seconds on

and four seconds to reset.

But the LED between pin 10 and ground did not come on.

So I removed the PIR signal LED and

  1. The pin 10 LED came on and it began to cycle the way the PIR does in test: 2 seconds

on and four seconds to reset.

And the sound came on. Yey!

So it is operating as intended and I probably don’t need the PIR sensor LED because

I am getting an indicator of the PIR sensor signal from the pin 10 LED.

But I still don’t understand why the sensor LED kept the PIR signal from

operating the input pin. Perhaps the LED/resistor on the signal drew enough

power to diminish the voltage to the Arduino input pin.

What do you think?

Thanks to skimask and others who helped me troubleshoot.

I tried to publish a video of the circuit operating but the sound from the

1.5 watt amplifiers is pretty weak and is not picked up by the iPhone.

The video didn’t make much sense with out the sound.

Next step is to replace the two small mono amplifiers with a single

30 watt stereo amp.

http://www.vellemanusa.com/products/view/?id=350530

When complete will post video.

Allen Pitts, Dallas Texas

The PIR sensor output likely can only push X amount of current (don’t know, didn’t read the datasheet, not going to either). Put the LED on the same line as the signal input to the Arduino, LED probably tries to pull any and/or all the current needed to trip the input.

I/O/W, use a mosfet or a transistor the fire the PIR sensor LED vs. using the signal line to fire the PIR sensor LED, or maybe a logic gate of some sort. Any number of different ways of doing it.