Hello,
I am trying to get the mention board to play audio through its' on board 3.5mm jack using a Ardunio uno board and a PIR sensor to trigger random sounds on the SD Card. But, for some reason, either my limited knowledge or something else I'm overlooking. I cannot get it to play thought unpowered or powered speakers.
I know that the PIR sensor and board is talking to the DY-SV5W as i can see it detect motion and says playing X track in the serial monitor. But, there is no sound.
The DY-SV5W drip switches is currently in 010, but I have tried using 100 and 001 with no differing results.
Here is the code I am using for the ardunio board. Put it get using my limited knowledge and modding code from a working DFminiPlayer sketch as the basis of my understand. It verified correctly with no problem before uploading it the ardunio.
#include <SoftwareSerial.h>
int pirPin = 12; // Arduino pin the PIR sensor is connected to
int rxPin = 3; // Arduino pin the TX pin of the DY-SV5W is connected to
int txPin = 2; // Arduino pin the RX pin of the DY-SV5W 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
SoftwareSerial mp3Serial(rxPin, txPin); // Software Serial object for DY-SV5W
void setup() {
pinMode(pirPin, INPUT); // Set PIR pin as input
pinMode(rxPin, INPUT); // Set mp3 player TX pin as input
pinMode(txPin, OUTPUT); // Set mp3 player RX pin as output
Serial.begin(9600); // Initialize Serial Monitor
mp3Serial.begin(9600); // Initialize Serial communication for DY-SV5W
delay(30000); // Allow 30-60 seconds for PIR sensor to calibrate
}
void loop() {
motionStatus = digitalRead(pirPin); // Read the PIR pin's current output (HIGH or LOW)
if (motionStatus == HIGH) {
if (pirState == LOW) {
Serial.println("Motion Detected"); // Print result to the Serial Monitor
pirState = HIGH; // Update the PIR state to HIGH
playRandomTrack(); // Play a random track
delay(13000); // Delay for the approximate length of the longest track
}
} else {
if (pirState == HIGH) {
Serial.println("Motion Ended"); // Print result to the Serial Monitor
pirState = LOW; // Update the PIR state to LOW
}
}
}
void playRandomTrack() {
int track = random(1, 65); // Generate a random track number (1 to 64)
Serial.print("Playing track: ");
Serial.println(track);
sendCommand(0x03, track); // Command 0x03 plays a specific track
}
void sendCommand(byte command, int parameter) {
byte highByte = (parameter >> 8) & 0xFF; // Extract high byte of parameter
byte lowByte = parameter & 0xFF; // Extract low byte of parameter
byte checksum = 0xFF - (0xFF + command + highByte + lowByte) + 1; // Calculate checksum
// Send the 6-byte command sequence
mp3Serial.write(0x7E); // Start byte
mp3Serial.write(0xFF); // Version byte
mp3Serial.write(0x06); // Command length
mp3Serial.write(command); // Command byte
mp3Serial.write((byte) 0x00); // Feedback (0x00 = no feedback)
mp3Serial.write(highByte); // High byte of parameter
mp3Serial.write(lowByte); // Low byte of parameter
mp3Serial.write(checksum); // Checksum
mp3Serial.write(0xEF); // End byte
}
Also here is the basic wiring in text format I used to hook up the PIR sensor, Ardunio, and the DY-SV5W.
Any help with this is appreciated as like I said, I am probably missing something obvious, but don't know I am.
