#include #include #include //-----Declare MP3 SoftwareSerial mp3Serial(2,3); // RX, TX DFPlayerMini_Fast mp3; byte mp3vol; //-----Constant bytes const byte potiIN = A7; const byte pirIN = A6; //################################### //################################### void setup() { pinMode(potiIN, INPUT); pinMode(pirIN, INPUT); Serial.begin(9600); Wire.begin(); //Start mp3 and set volume from Poti mp3Serial.begin(9600); mp3.begin(mp3Serial); mp3vol = map(analogRead(potiIN), 0, 1023, 0, 30); mp3.volume(mp3vol); } //================================ void loop() { //Set volume from poti mp3vol = map(analogRead(potiIN), 0, 1023, 0, 30); mp3.volume(mp3vol); // --> Adjust the number of tracks on your SD card here: random(1, YOURVALUE); if(analogRead(pirIN)>5 && !mp3.isPlaying()) mp3.playFromMP3Folder(random(1, 10)); //Alternative: random(1, mp3.numSdTracks()+1)); delay(2000); }