adsense

Arduino drums using an SD card module:

 Here is arduino sd card drum code and diagram

Data is transferred to and from the memory device using the SD Card Module. It enables mass storage, which we can use for our endeavor, particularly for data logging. And the goal of this tutorial is to play audio files from an SD card with your Arduino in respectable resolution.

arduino drum using sd card module



#include <SD.h>         // Include the SD library

#include <SPI.h>        // Include the SPI library

#include <MIDI.h>       // Include the MIDI library


// Define the SD card chip select pin

const int chipSelectPin = 10;


// Define the MIDI channel to send on

const int midiChannel = 10;


// Define the MIDI note numbers for each drum sound

const int kickNote = 36;

const int snareNote = 38;

const int hiHatNote = 42;

const int crashNote = 49;

const int rideNote = 51;


// Create an instance of the MIDI library

MIDI_CREATE_DEFAULT_INSTANCE();


void setup() {

  // Initialize the serial port

  Serial.begin(9600);


  // Initialize the SD card

  if (!SD.begin(chipSelectPin)) {

    Serial.println("SD card initialization failed!");

    return;

  }


  // Initialize the MIDI library

  MIDI.begin(midiChannel);

}


void loop() {

  // Check if a drum sound file is available

  if (SD.exists("kick.wav")) {

    // Send the MIDI note on message for the kick drum

    MIDI.sendNoteOn(kickNote, 127, midiChannel);


    // Play the kick drum sound from the SD card

    playSound("kick.wav");


    // Send the MIDI note off message for the kick drum

    MIDI.sendNoteOff(kickNote, 0, midiChannel);

  }


  // Check if a snare sound file is available

  if (SD.exists("snare.wav")) {

    // Send the MIDI note on message for the snare drum

    MIDI.sendNoteOn(snareNote, 127, midiChannel);


    // Play the snare drum sound from the SD card

    playSound("snare.wav");


    // Send the MIDI note off message for the snare drum

    MIDI.sendNoteOff(snareNote, 0, midiChannel);

  }


  // Check if a hi-hat sound file is available

  if (SD.exists("hihat.wav")) {

    // Send the MIDI note on message for the hi-hat

    MIDI.sendNoteOn(hiHatNote, 127, midiChannel);


    // Play the hi-hat sound from the SD card

    playSound("hihat.wav");


    // Send the MIDI note off message for the hi-hat

    MIDI.sendNoteOff(hiHatNote, 0, midiChannel);

  }


  // Check if a crash cymbal sound file is available

  if (SD.exists("crash.wav")) {

    // Send the MIDI note on message for the crash cymbal

    MIDI.sendNoteOn(crashNote, 127, midiChannel);


    // Play the crash cymbal sound from the SD card

    playSound("crash.wav");


    // Send the MIDI note off message for the crash cymbal

    MIDI.sendNoteOff(crashNote, 0, midiChannel);

  }


  // Check if a ride cymbal sound file is available

  if (SD.exists("ride.wav")) {

    // Send the MIDI note on message for the ride cymbal

    MIDI.sendNoteOn(rideNote, 127, midiChannel);


    // Play the ride cymbal sound from the SD card

    playSound("ride.wav");


    // Send the MIDI note off message for the ride cymbal

    MIDI.sendNoteOff(rideNote, 0, midiChannel);

  }

}


void playSound(const char* filename) {

  // Open the sound file


Post a Comment

0 Comments