Hi everyone!
im trying to make a pir sensor based audio player using arduino uno and an mp3-tf-16-p, and it doesnt seem to be working!
Heres the code i am using :
#include <DFPlayerMini_Fast.h>
#include <SoftwareSerial.h>
// Use pins 10 and 11 to communicate with DFPlayer Mini
static const uint8_t PIN_MP3_TX = 10; // Connects to module's RX
static const uint8_t PIN_MP3_RX = 11; // Connects to module's TX
SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);
// Create the Player object
DFPlayerMini_Fast player;
int PIRsensor = 4; // the pin that the sensor is attached to
int state = LOW; // by default, no motion detected
int val = 0;
void setup() {
delay(random(500,2000)); // delay for random time
pinMode(PIRsensor, INPUT); // initialise passive infrared sensor as an input
//Init USB serial port for debugging
Serial.begin(9600);
// Init serial port for DFPlayer Mini
softwareSerial.begin(9600);
}
void loop() {
val=digitalRead(PIRsensor); // reads PIR sensor value and assigns to val
if (val==HIGH)
{
Serial.println("pir works");
if (player.begin(softwareSerial))
{
Serial.println("OK");
// Set volume to maximum (0 to 30).
player.volume(30);
// Play the first MP3 file on the SD card
player.play(1);}
else
{
Serial.println("Connecting to DFPlayer Mini failed!");
}
}
}
the serial monitor is printing
"pir works
OK" in a loop so i suppose the logic of the program is sound.
initially i tried using the DFRobotDFPlayerMini library but for some reason it kept showing an error message
this is my hardware connection
i used a 1k resistor b/w the rx of mp3 module and pin 11
i bought a brand new sd card as well for this and named the file 0001.mp3.
the led on the mp3 module flashes for a brief moment sometimes when i connect the whole thing to the computer.
even though the serial monitor is showing that the if statement should execute, im not getting any sound from my speakers whatsoever, even in that brief moment when the led briefly shines.
any help would be appreciated as i am a complete beginner to the hardware part of arduino.
thanks!!!