So I connected 2 arduinos using RX pin on the board that play a specific file, and TX pin on the board that receive IR signal. It does receive signal, but I think it played the wrong file. I had the memory chip and the IR model KY-022. Here is my code for the IR receiver:
#include <IRremote.h>
// #include "SoftwareSerial.h"
// #include "DFRobotDFPlayerMini.h"
const int IR_RECEIVER_PIN = 2;
IRrecv irrecv(IR_RECEIVER_PIN);
decode_results results;
void setup() {
Serial.begin(9600);// serial
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
switch(results.value) {
case 0xE318261B: // button 1
Serial.write(1);
break;
case 0xFFA25D: // button 2
Serial.write(2);
break;
// Add more cases for additional buttons
}
irrecv.resume(); // Receive the next value
}
}
Then it passed the value to the board that play music:
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(12, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
int fileNumber;
void setup() {
Serial.begin(9600); // start the serial communication at 9600 baud
mySoftwareSerial.begin(9600);
if (!myDFPlayer.begin(mySoftwareSerial, true, false)) {
while(true){delay(0); }
}
myDFPlayer.volume(10);
}
void loop() {
if (Serial.available() > 0) {
fileNumber = Serial.read(); // receive the file number from the other Arduino
}
switch (fileNumber) {
case 1:
myDFPlayer.play(1); delay(1);
break;
case 2:
myDFPlayer.play(2); delay(1);
break;
case 3:
myDFPlayer.play(3); delay(1);
break;
// add more cases for additional files
}
}
Yet it can not play the right file. Can anyone help me? Thanks in advance.
