int pirPin = 12; // Arduino pin the PIR sensor is connected to
int rxPin = 3; // Arduino pin the TX pin of mp3 player is connected to
int txPin = 2; // Arduino pin the RX pin of mp3 player is connected to

int motionStatus = 0; // variable to store the PIR's current reading (high or low)
int pirState = 0; // variable to store the PIR's state change

void setup() {
  pinMode(pirPin, INPUT); // set Arduino pin that PIR is connected to as an INPUT
  pinMode(rxPin, INPUT); // set Arduino pin that mp3 player TX is connected to as an INPUT
  pinMode(txPin, OUTPUT); // set Arduino pin that mp3 player RX is connected to as an OUTPUT
  Serial.begin(9600); // initialize Serial Monitor (for looking at PIR readings)
}

void loop() {
  motionStatus = digitalRead(pirPin); // read the PIR pin's current output (is it HIGH or LOW?)
  delay(100); // need to debounce the PIR pin (switch/button)
  if (motionStatus == HIGH) {
    if (pirState == LOW) {
      Serial.println("Motion Detected"); // print result to the serial monitor
      pirState = HIGH; // update the previous PIR state to HIGH
      digitalWrite(txPin, HIGH);
    }
  }  else {
    if (pirState == HIGH) {
      Serial.println ("Motion Ended"); //print result to the serial monitor
      pirState = LOW; // update the previous PIR state to LOW
      digitalWrite(txPin, LOW);
    }
  }
}