Loading...
Loading...
// Sound Effects Module
#include <DFRobotDFPlayerMini.h>
#include <SoftwareSerial.h>
SoftwareSerial mp3Serial(10, 11);
DFRobotDFPlayerMini mp3;
const int TRIGGER = 2;
int lastState = HIGH;
void setup() {
mp3Serial.begin(9600);
mp3.begin(mp3Serial);
mp3.volume(20);
pinMode(TRIGGER, INPUT);
}
void loop() {
int state = digitalRead(TRIGGER);
if (state == LOW && lastState == HIGH) {
int sound = random(1, 6); // Random sound 1-5
mp3.play(sound);
}
lastState = state;
delay(100);
}This is starter code - modify and expand for your specific needs.
Before building this project, make sure you have the Arduino IDE installed and are comfortable uploading basic sketches to your board.
Most projects use standard Arduino libraries. Some may require additional libraries like AccelStepper, Servo, or NmraDcc - install these through the Arduino Library Manager.