#include DFRobotDFPlayerMini.h
#include SoftwareSerial.h
// Define the pin connected to the limit switch
const int limitSwitchPin = 14;
int switchState = 0; // Variable to store the switch state
int lastSwitchState = 1; // Assume Initially the door is closed
// Initialize the software serial connection to the DFPlayer
SoftwareSerial mySoftwareSerial(26, 27); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void setup() {
// Initialize the limit switch pin as an input with internal pull-up resistor
pinMode(limitSwitchPin, INPUT_PULLUP);
// Start serial communication for debugging
Serial.begin(115200);
// Start software serial communication with the DFPlayer
mySoftwareSerial.begin(9600);
// Check if the DFPlayer mini module is connected properly
if (!myDFPlayer.begin(mySoftwareSerial)) {
Serial.println("DFPlayer Mini not detected.");
while (true); // Halt execution if DFPlayer Mini not detected
}
// Set volume
myDFPlayer.volume(30); // Volume level between 0 to 30