Thanks, just want the simple sounds and led strips with the motion activation. Iv tested one of the codes last night and it works fine like I mentioned before the other code I need to sort out with then hopefully merge them together.
I’ve seen no reply. What is the number of the post?
That probably explains this PM I received....
I think it would be best to keep the conversation public on this thread for now. If you can post the two sketch files then we can certainly have a look.
Its not impossible for hardware to be faulty of course, but the organization of files on the SD card also needs to follow a specific format which is described here:
https://www.acamar.com.au/MCUProjects/images/gd3200b.pdf
In short, files needs to be in one of the two mentioned folder arrangements and filenames have to start with a three digit track number. @callumdt, is that how you have arranged the files on your SD card?
Thanks for the link, iv got them as 0001.mp3 ect not in a folder just on the SD card. If I make a folder does it need a specific name and should I rename them to 001.mp3 instead?
The document states two options:
Option 1:
A single folder named MP3. It doesn't say, but looks like it must be uppercase. As I understand it, track names can be anything and the track numbers follow the order in which the files were added to the directory. A maximum of 3000 files is recommended.
Option 2:
Up to 99 directories can be created named between 01 and 99. These can contain up to 255 files each. File names must start with 001, 002, 003 etc. So yes, it looks like they must start with 3 digits. If you start with 0001 etc, then the first 10 files will have track number 000, the next 10 will be track 001 etc which will probably confuse the player, so yes, I suggest renaming them as indicated so, you can have 001.mp3, or even 001songname.mp3. So long as it starts 001 (i.e. the track number is 3 digits) then I don't think it will matter what the rest of the filename is.
That is my understanding.
i have made a folder called 01 and added the mp3 files into it, i have also renamed them 001,002,003,004. I will attach the first code which will be for making the Pir play the audio files.
/*This Arduino sketch plays a track sequentially, in numerical order, from a
DFRobot PlayerMini mp3 player module when motion is detected by a PIR sensor.
For the wiring diagram, step-by-step video, code explanation and more
motion-activated sound effects projects with Arduino, visit:
*/
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h> // download this library from Arduino IDE "Manage Libraries"
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
int track = 1; // variable to store current track number
SoftwareSerial fxSerial (rxPin, txPin); // Software Serial object
DFRobotDFPlayerMini fxPlayer;
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)
fxSerial.begin(9600); // initialize Serial communication for mp3 player
fxPlayer.begin(fxSerial); // tells mp3 player to use fxSerial for communication
fxPlayer.volume(30); // mp3 player volume (pick a value 10-30)
delay(30000); // allow 30-60 secs for PIR sensor to calibrate before proceeding with sketch
}
void loop() {
motionStatus = digitalRead(pirPin); // read the PIR pin's current output (is it HIGH or LOW?)
// if PIR pin output is HIGH:
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
fxPlayer.play(track); // play current track from micro SD card
delay(5000); // length in microseconds of the longest track
track++; // add 1 to the current track for the next loop
// if track number tries to exceed 5 (I have 5 total in my case)
if (track > 5) { // change this value to match your total # of tracks
track = 1; // reset track number to 1
}
}
}
// or else if PIR pin output is LOW:
else {
if (pirState == HIGH) {
Serial.println ("Motion Ended"); //print result to the serial monitor
pirState = LOW; // update the previous PIR state to LOW
}
}
}
this next code is for making the Led turn on with pir sensor but I would like it to turn the led off instead so no motion=led on when motion is picked up led turns off. I will be changing the port number for the led so it uses an external Led strip. Here is the code
int pirPin = 12; // Arduino pin the PIR sensor is connected to
int ledPin = 13; //Arduino built-in LED
int motionStatus = 0; // variable to store the PIR sensor's motion status (high or low)
int pirState = 0; // variable to track the state change
void setup() {
Serial.begin(9600); // initialize the serial monitor
pinMode(pirPin, INPUT); // set the Arduino pin that PIR sensor is connected to as an INPUT
}
void loop() {
motionStatus = digitalRead(pirPin); // read the PIR pin's current output (is it HIGH or LOW?)
// if the motion status is HIGH
if (motionStatus == HIGH) {
if (pirState == LOW ) {
Serial.println("Motion Detected"); // print result to the serial monitor
digitalWrite(ledPin, HIGH); // turn on built-in LED
pirState = HIGH; // update the previous state to HIGH
}
}
//or else if motion status is low
else {
if (pirState == HIGH) {
Serial.println ("Motion Ended"); // print result to the serial monitor
digitalWrite(ledPin, LOW); // turn off built-in LED
pirState = LOW; // update the previous state to LOW
}
delay(100); // optional delay to slow down the PIR sensor reading intervals
}
}
To be clear, using neither the reply link at the bottom of every forum post or the more prominent reply link at the end of a topic results in a PM being sent. Both add a post to the topic but the first type adds a link to the post being replied to
Sending a PM has to be done explicitly
DFR documentation about file organisation and many subsequent articles and posts based on it have frequently caused confusion. Individual files on the card do not need to be in a parent folder called ‘\MP3’ or any other name. Nor does the module need them to be named with number prefixes of any kind. They are addressed purely depending on the time they were copied to the card. The user, of course, will usually want to add such prefixes.
So they don't need to be in a folder or have a specific name?
Correct. But for more versatile projects than yours, both numbering and folders will usually be needed.
I’ve now finally seen your code and will take a look at it later today.
Thanks for the help.
The comment is misleading. It might better be called a warming up period. I have found that it is often a bit of a wait for the PIR to settle in and start making accurate reports.
a7
I’ve corrected various errors and merged both sketches into one. See my embedded comments.
/*
Fri 29 Aug 2025 1441; corrected errors & merged LED and PIR sketches
Read my comments in code to see changes, most are marked "my edit".
THIS version switches OFF the LED after motion detected
and stays on for the 2s that the PIR remains high. Amend this if you
want different logic, such as staying on until next trigger, etc.
When triggered by motion it plays each successive track, in full or until
next triggered.
This version uses my own preferred Uno/Nano pins. In particular
I don't use the pair 2/3 for Rx/Tx, which can cause interrupt conflicts
in less simple projects..
Each trigger plays successive tracks, repeating after track 5.
*/
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h> // download this library from Arduino IDE "Manage Libraries"
int pirPin = 3; // my edit
// int pirPin = 12; // Arduino pin the PIR sensor is connected to
int rxPin = 10; // my edit
// int rxPin = 3; // Arduino pin the TX pin of mp3 player is connected to
int txPin = 11; // my edit
// int txPin = 2; // Arduino pin the RX pin of mp3 player is connected to
int ledPin = 13; //Arduino built-in LED, and a more visible one
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
int track = 1; // variable to store current track number
SoftwareSerial fxSerial(rxPin, txPin); // Software Serial object
DFRobotDFPlayerMini fxPlayer;
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
pinMode(ledPin, OUTPUT); // my edit
Serial.begin(115200); // my preference
// Serial.begin(9600); // initialize Serial Monitor (for looking at PIR readings)
fxSerial.begin(9600); // initialize Serial communication for mp3 player
fxPlayer.begin(fxSerial); // tells mp3 player to use fxSerial for communication
delay(1000); // my edit
fxPlayer.volume(15); // my edit // mp3 player volume (pick a value 10-30)
delay(8000); // my edit, allow say 8 secs for PIR sensor to settle
}
void loop()
{
motionStatus = digitalRead(pirPin); // read the PIR pin's current output (is it HIGH or LOW?)
// if PIR pin output is HIGH:
if (motionStatus == HIGH)
{
if (pirState == LOW)
{
Serial.println("Motion Detected"); // print result to the serial monitor
digitalWrite(ledPin, LOW); // turn OFF built-in LED
pirState = HIGH; // update the previous PIR state to HIGH
fxPlayer.play(track); // play up to 3 s of current track
// delay(1000); // // my edit length in MILLIseconds of the current track
// delay(5000); // length in microseconds of the longest track
track++; // add 1 to the current track for the next loop
// if track number tries to exceed 5 (I have 5 total in my case)
if (track > 5)
{ // change this value to match your total # of tracks
track = 1; // reset track number to 1
}
}
}
// or else if PIR pin output is LOW:
else
{
// if (pirState == LOW)
if (pirState == HIGH)
{
Serial.println("Motion Ended"); //print result to the serial monitor
digitalWrite(ledPin, HIGH); // turn ON built-in LED
pirState = LOW; // update the previous PIR state to LOW
}
}
}
+1
Typically mine seem to need 8 or 10 s after power up.
Thanks for the code bit help although I have run into a problem when trying out it onto the Arduino. I get compilation error: 'softwareserial' does not name a type
Please post the whole of the error message
Note that softwareserial does not occur anywhere in @Terrypin's sketch
FQBN: arduino:renesas_uno:minima
Using board 'minima' from platform in folder: C:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1
Using core 'arduino' from platform in folder: C:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1
Detecting libraries used...
C:\Users\callu\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4/bin/arm-none-eabi-g++ -c -w -Os -g3 -fno-use-cxa-atexit -fno-rtti -fno-exceptions -nostdlib -DF_CPU=48000000 -DARDUINO_UNOR4_MINIMA -std=gnu++17 -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -fno-builtin -w -x c++ -E -CC -DARDUINO=10607 -DPROJECT_NAME="C:\Users\callum\AppData\Local\arduino\sketches\8F464C72E6D35ECDBA16E0B9E62A4491/sketch_aug29a.ino" -DARDUINO_MINIMA -DARDUINO_ARCH_RENESAS_UNO -DARDUINO_ARCH_RENESAS -DARDUINO_FSP -D_XOPEN_SOURCE=700 -mthumb @C:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\variants\MINIMA/defines.txt -DCFG_TUSB_MCU=OPT_MCU_RAXXX -IC:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\cores\arduino/tinyusb -IC:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\cores\arduino/api/deprecated -IC:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\cores\arduino/api/deprecated-avr-comp -IC:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\cores\arduino -IC:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\variants\MINIMA -iprefixC:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1 @C:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\variants\MINIMA/includes.txt C:\Users\callum\AppData\Local\arduino\sketches\8F464C72E6D35ECDBA16E0B9E62A4491\sketch\sketch_aug29a.ino.cpp -o nul
Generating function prototypes...
C:\Users\callu\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4/bin/arm-none-eabi-g++ -c -w -Os -g3 -fno-use-cxa-atexit -fno-rtti -fno-exceptions -nostdlib -DF_CPU=48000000 -DARDUINO_UNOR4_MINIMA -std=gnu++17 -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -fno-builtin -w -x c++ -E -CC -DARDUINO=10607 -DPROJECT_NAME="C:\Users\callum\AppData\Local\arduino\sketches\8F464C72E6D35ECDBA16E0B9E62A4491/sketch_aug29a.ino" -DARDUINO_MINIMA -DARDUINO_ARCH_RENESAS_UNO -DARDUINO_ARCH_RENESAS -DARDUINO_FSP -D_XOPEN_SOURCE=700 -mthumb @C:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\variants\MINIMA/defines.txt -DCFG_TUSB_MCU=OPT_MCU_RAXXX -IC:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\cores\arduino/tinyusb -IC:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\cores\arduino/api/deprecated -IC:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\cores\arduino/api/deprecated-avr-comp -IC:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\cores\arduino -IC:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\variants\MINIMA -iprefixC:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1 @C:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\variants\MINIMA/includes.txt C:\Users\callum\AppData\Local\arduino\sketches\8F464C72E6D35ECDBA16E0B9E62A4491\sketch\sketch_aug29a.ino.cpp -o C:\Users\callum\AppData\Local\Temp\1304781558\sketch_merged.cpp
C:\Users\callu\AppData\Local\Arduino15\packages\builtin\tools\ctags\5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives C:\Users\callum\AppData\Local\Temp\1304781558\sketch_merged.cpp
Compiling sketch...
"C:\Users\callu\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4/bin/arm-none-eabi-g++" -c -w -Os -g3 -fno-use-cxa-atexit -fno-rtti -fno-exceptions -MMD -nostdlib -DF_CPU=48000000 -DARDUINO_UNOR4_MINIMA -MMD -std=gnu++17 -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -fno-builtin -DARDUINO=10607 "-DPROJECT_NAME="C:\Users\callum\AppData\Local\arduino\sketches\8F464C72E6D35ECDBA16E0B9E62A4491/sketch_aug29a.ino"" -DARDUINO_MINIMA -DARDUINO_ARCH_RENESAS_UNO -DARDUINO_ARCH_RENESAS -DARDUINO_FSP -D_XOPEN_SOURCE=700 -mthumb "@C:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\variants\MINIMA/defines.txt" -DCFG_TUSB_MCU=OPT_MCU_RAXXX "-IC:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\cores\arduino/tinyusb" "-IC:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\cores\arduino/api/deprecated" "-IC:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\cores\arduino/api/deprecated-avr-comp" "-IC:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\cores\arduino" "-IC:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\variants\MINIMA" "-iprefixC:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1" "@C:\Users\callu\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.4.1\variants\MINIMA/includes.txt" "C:\Users\callum\AppData\Local\arduino\sketches\8F464C72E6D35ECDBA16E0B9E62A4491\sketch\sketch_aug29a.ino.cpp" -o "C:\Users\callum\AppData\Local\arduino\sketches\8F464C72E6D35ECDBA16E0B9E62A4491\sketch\sketch_aug29a.ino.cpp.o"
C:\Users\callum\AppData\Local\Temp.arduinoIDE-unsaved2025729-14588-1ggpfob.0ils\sketch_aug29a\sketch_aug29a.ino:12:1: error: 'SoftwareSerial' does not name a type
SoftwareSerial fxSerial(rxPin, txPin); // Software Serial object
^~~~~~~~~~~~~~
C:\Users\callum\AppData\Local\Temp.arduinoIDE-unsaved2025729-14588-1ggpfob.0ils\sketch_aug29a\sketch_aug29a.ino:13:1: error: 'DFRobotDFPlayerMini' does not name a type
DFRobotDFPlayerMini fxPlayer;
^~~~~~~~~~~~~~~~~~~
C:\Users\callum\AppData\Local\Temp.arduinoIDE-unsaved2025729-14588-1ggpfob.0ils\sketch_aug29a\sketch_aug29a.ino: In function 'void setup()':
C:\Users\callum\AppData\Local\Temp.arduinoIDE-unsaved2025729-14588-1ggpfob.0ils\sketch_aug29a\sketch_aug29a.ino:24:3: error: 'fxSerial' was not declared in this scope
fxSerial.begin(9600); // initialize Serial communication for mp3 player
^~~~~~~~
C:\Users\callum\AppData\Local\Temp.arduinoIDE-unsaved2025729-14588-1ggpfob.0ils\sketch_aug29a\sketch_aug29a.ino:24:3: note: suggested alternative: 'Serial'
fxSerial.begin(9600); // initialize Serial communication for mp3 player
^~~~~~~~
Serial
C:\Users\callum\AppData\Local\Temp.arduinoIDE-unsaved2025729-14588-1ggpfob.0ils\sketch_aug29a\sketch_aug29a.ino:25:3: error: 'fxPlayer' was not declared in this scope
fxPlayer.begin(fxSerial); // tells mp3 player to use fxSerial for communication
^~~~~~~~
C:\Users\callum\AppData\Local\Temp.arduinoIDE-unsaved2025729-14588-1ggpfob.0ils\sketch_aug29a\sketch_aug29a.ino: In function 'void loop()':
C:\Users\callum\AppData\Local\Temp.arduinoIDE-unsaved2025729-14588-1ggpfob.0ils\sketch_aug29a\sketch_aug29a.ino:43:7: error: 'fxPlayer' was not declared in this scope
fxPlayer.play(track); // play up to 3 s of current track
^~~~~~~~
exit status 1
Compilation error: 'SoftwareSerial' does not name a type
So the error was not actually
'softwareserial' does not name a type
after all
Why are you trying to use SoftwareSerial when the Uno Minima has two hardware serial ports ?
Serial is a direct link between the processor and the PC using USB
Serial1 is a serial interface on pins 0 and 1. Connect the player to pins 0 and 1 and use Serial1 to control it
If only you had told us which board you were using earlier in the topic
i have it plugged in through usb-c. my appologes my nano stopped working and i hade a spear uno r4 minima so i changed over to that i didnt think it would be a problem.
