Arnov Sharma
Published © MIT

Pico Drum Machine

Pico 2 powered drum machine that plays notes stored in SD card through the DFMiniPlayer.

BeginnerFull instructions provided1 hour886
Pico Drum Machine

Things used in this project

Hardware components

Raspberry Pi Pico 2
Raspberry Pi Pico 2
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Seeed Studio Fusion PCB/PCBA
Seeed Studio Fusion PCB/PCBA

Story

Read more

Custom parts and enclosures

Audio Files

Schematics

WIRING

Code

code

C/C++
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>

// Declare button pins for 8 buttons
const int buttonPins[8] = {14, 15, 16, 17, 18, 19, 20, 21}; // Adjust pins as per your setup
const int noteFiles[8] = {1, 2, 3, 4, 5, 6, 7, 8};  // Corresponding note numbers

// DFPlayer connections
SoftwareSerial mySerial(9, 8); // RX, TX
DFRobotDFPlayerMini myDFPlayer;

void setup() {
  mySerial.begin(9600);
  Serial.begin(9600);
  Serial.println("Initializing DFPlayer...");

  if (!myDFPlayer.begin(mySerial)) {
    Serial.println("Unable to begin:");
    Serial.println("1. Recheck the connection!");
    Serial.println("2. Insert the SD card!");
    while (true);
  }

  Serial.println("DFPlayer Mini online.");

  for (int i = 0; i < 8; i++) {
    pinMode(buttonPins[i], INPUT_PULLUP);
  }
  
  myDFPlayer.volume(30); // Set volume to maximum
  Serial.println("Setup complete. Ready to play notes.");
}

void loop() {
  for (int i = 0; i < 8; i++) {
    if (digitalRead(buttonPins[i]) == LOW) { // The button is pressed
      Serial.print("Button ");
      Serial.print(i + 1); // Shift to human-readable (1-based indexing)
      Serial.println(" pressed.");
    
      myDFPlayer.play(noteFiles[i]); // Play the note directly
      Serial.print("Playing note ");
      Serial.println(noteFiles[i]);

      delay(150); // Reduced debounce delay for faster response
    }
  }
}

Credits

Arnov Sharma
315 projects • 314 followers
Just your average MAKER

Comments