PIR sensor coding issue

I'm trying to create a motion activated talking skull for Halloween. Im new to this and im getting tripped up on the coding aspect. I watched a video tutorial on how to wire the speakers, micro SD, and PIR sensor however I think the accompanying code is wrong. The issue is once I power on the arduino plays the .wav file but won't play it again until I power it off and back on again. Any help would be appreciated!

[color=#444444][color=#434f54]#include[/color] [color=#95a5a6]"SD.h"[/color]
[color=#434f54]#define SD_ChipSelectPin 4[/color]
[color=#434f54]#include[/color] [color=#95a5a6]"TMRpcm.h"[/color]
[color=#434f54]#include[/color] [color=#95a5a6]"SPI.h"[/color]

[color=#434f54]TMRpcm[/color] [color=#434f54]tmrpcm[/color];

[color=#728e00]void[/color] [color=#434f54]setup[/color]()
{
 

[color=#d35400]pinMode[/color]([color=#434f54]7[/color],[color=#728e00]INPUT[/color]);
[color=#d35400]delay[/color]([color=#434f54]500[/color]);
}

[color=#728e00]void[/color] [color=#434f54]loop[/color]()
{

[color=#728e00]if[/color]([color=#d35400]digitalRead[/color]([color=#434f54]7[/color])[color=#434f54]==[/color][color=#728e00]HIGH[/color])
{
 
 [color=#434f54]AudioPlay[/color]();
 [color=#d35400]delay[/color]([color=#434f54]3000[/color]);
 }
 }

[color=#728e00]void[/color] [color=#d35400]AudioPlay[/color]()
{ 
[color=#434f54]tmrpcm[/color].[color=#434f54]speakerPin[/color] [color=#434f54]=[/color] [color=#434f54]9[/color];
[color=#d35400]Serial[/color].[color=#d35400]begin[/color]([color=#434f54]9600[/color]);
[color=#728e00]if[/color] ([color=#434f54]![/color][color=#d35400]SD[/color].[color=#d35400]begin[/color]([color=#434f54]SD_ChipSelectPin[/color])) {
[color=#d35400]Serial[/color].[color=#d35400]println[/color]([color=#7f8c8d]"SD fail"[/color]);
[color=#728e00]return[/color];
}

[color=#434f54]tmrpcm[/color].[color=#434f54]setVolume[/color]([color=#434f54]5[/color]);
[color=#434f54]tmrpcm[/color].[color=#434f54]play[/color]([color=#7f8c8d]"welcome.wav"[/color]);
}[/color]

The picture is very nice, but tells nothing about how you have the project wired. Please make a block diagram showing all the connections, including the power supply.

Paul

I hope this helps. This is the wiring diagram that I followed. The arduino is powered by a USB cable type A/B. Like the page did, they made use of a breadboard as I have tried to do. I also attached the link to the page that I followed. https://create.arduino.cc/projecthub/munir03125344286/welcome-audio-by-using-pir-sensor-c65ae6#comments

Your link wants me to log in or join. I wont do either.

What does your motion sensor documentation say about how it operates? Will it sense more than one motion without power off?

Paul

Its Arduino's website and it asks you to sign in or sign up in order to leave a comment, scroll up on the page (for some reason the url takes you to the comment section not the too of the page for some reason) and you'll see the diagram and the YouTube video associated with the post. I got a "neat" arduino starter kit that came with a PIR sensor and about 15 other bits and pieces, with zero documentation.

Just a quick thing:

#include "SD.h"
#define SD_ChipSelectPin 4
#include "TMRpcm.h"
#include "SPI.h"

There are two kinds of includes, library includes and local includes. Use <> for library includes
then the compiler searches for those files first in the library directories. Thus:

#include <SD.h>
#define SD_ChipSelectPin 4
#include <TMRpcm.h>
#include <SPI.h>

When you are writing libraries yourself, that's the time to use the "" form of include, for the library's
include file(s) as they are local to that library.