The sketch won't "press a switch", it will (should) execute a line of code that will result an MP3 Play every 20 seconds or whatever you like.
This sketch plays an MP3 every 5 seconds (the MP3s I made are very short) --
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
// Use pins 2 and 3 to communicate with DFPlayer Mini
static const uint8_t PIN_MP3_TX = 2; // Connects to module's RX
static const uint8_t PIN_MP3_RX = 3; // Connects to module's TX
SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);
DFRobotDFPlayerMini player; // Create the Player object
void setup()
{
Serial.begin(19200);
softwareSerial.begin(9600);
if (player.begin(softwareSerial))
{
Serial.println("OK");
// Set volume to maximum (0 to 30).
player.volume(22); //30 is very loud
}
else
{
Serial.println("Connecting to DFPlayer Mini failed!");
}
pinMode(13,OUTPUT);
digitalWrite(13,LOW);
}
void loop()
{
Serial.print("Playing #1 \t");
player.play(1);
delay(5000);
Serial.print("Playing #2 \t");
player.play(2);
delay(5000);
Serial.print("Playing #3 \r\n\r\n");
player.play(3);
delay(5000);
}