Parts shop on Daraz
⚡
Circuits · Repair · DIY projects by SR Jewel

Arduino Leonardo Mobile Drum Pad Code: Keyboard Trigger Setup

Sr Jewel December 22, 2023 arduino drum code

Before using this sketch

This code uses Arduino's Keyboard.h library to send key presses from a compatible USB board. It generates keyboard events, not MIDI notes, so use it with an app or device that accepts keyboard input. The board must support native USB HID, such as an Arduino Leonardo or Micro; a standard Uno cannot run this keyboard path through its normal USB connection. See the Leonardo documentation and Arduino’s USB Keyboard reference.

The sketch reads several analog pins for pad triggers. Match the pin list to your board, and protect each microcontroller input from piezo voltage spikes with a suitable trigger circuit. A bleed resistor alone does not guarantee input protection. Test the hardware one pad at a time before connecting the full kit.

The original project video and sketch follow.



Arduino Mobile Octapad With Code 


Arduino Code:
#include <Keyboard.h>

void setup(){
  Keyboard.begin();
  pinMode (10, INPUT_PULLUP);
  pinMode (11, INPUT_PULLUP);
  }
 
  void loop() {
   
    int c = analogRead(A0);
    int d = analogRead(A1);
    int e = analogRead(A2);
    int f = analogRead(A3);
    int g = analogRead(A4);
    int h = analogRead(A5);
    int i = analogRead(A6);
    int j = analogRead(A7);

  //8 pad selections------------------------------------------------------------
   
     if(c>100){
      Keyboard.print("q");
      delay(10);
      }
     
      if(d>100){
        Keyboard.print("w");
        delay(10);
        }
       
        if(e>100){
          Keyboard.print("e");
          delay(10);
          }
         
          if(f>100){
            Keyboard.print("r");
            delay(10);
            }
           
            if(g>100){
              Keyboard.print("s");
              delay(10);
              }
             
              if(h>100){
                Keyboard.print("d");
                delay(10);                
                }
               
                if(i>100){
                  Keyboard.print("u");
                  delay(10);
                  }
                 
                  if(j>100){
                    Keyboard.print("x");
                    delay(10);
                    }
                   
  //Tone Selection Keys---------------------------------------------------------------------  
                 
                    if(!digitalRead(10)){
                      Keyboard.press(KEY_UP_ARROW);
                      delay(200);
                      } else if(!digitalRead(11)){
                       Keyboard.press(KEY_DOWN_ARROW);
                        delay(200);
                        }
                       Keyboard.releaseAll();
                        }
                     
Safety first. Electrical and electronic work can be dangerous. Follow proper procedures, use the right tools and protective equipment, and leave high-voltage or hazardous work to qualified or properly supervised people.
SR

SR JEWEL · Electronic Help Care

Electronics technician and content creator from Jessore, Bangladesh. I build and repair circuits, amplifiers, LED displays and musical instrument electronics, and publish the diagrams and fixes that work in practice.

Comments

Akshay dancer said…
Which board use for this code?
Sr Jewel said…
#include

void setup(){
Keyboard.begin();
pinMode (10, INPUT_PULLUP);
pinMode (11, INPUT_PULLUP);
}

void loop() {

int c = analogRead(A0);
int d = analogRead(A1);
int e = analogRead(A2);
int f = analogRead(A3);
int g = analogRead(A6);
int h = analogRead(A7);
int i = analogRead(A8);
int j = analogRead(A9);

//8 pad selections------------------------------------------------------------

if(c>800){
Keyboard.print("3");
delay(10);
}

if(d>800){
Keyboard.print("7");
delay(10);
}

if(e>800){
Keyboard.print("8");
delay(10);
}

if(f>800){
Keyboard.print("4");
delay(10);
}

if(g>800){
Keyboard.print("6");
delay(10);
}

if(h>800){
Keyboard.print("5");
delay(10);
}

if(i>800){
Keyboard.print("1");
delay(10);
}

if(j>800){
Keyboard.print("2");
delay(10);
}

//Tone Selection Keys--------------------------------------------------------------------

if(!digitalRead(10)){
Keyboard.press(KEY_UP_ARROW);
delay(200);
} else if(!digitalRead(11)){
Keyboard.press(KEY_DOWN_ARROW);
delay(200);
}
Keyboard.releaseAll();
}

Electronic Help Care

ElectronicHelpCare.com is a practical electronics and technology resource for students, hobbyists, technicians, and DIY enthusiasts. Discover electronics repair guides, circuit diagrams, PCB design, Arduino, ESP32, IoT projects, LED displays, power supplies, solar systems, troubleshooting tips, component information, and step-by-step tutorials. Our goal is to make electronics learning, repair, and innovation easier through useful, practical, and easy-to-understand technical content.

About

Electronic Help Care shares practical electronics tutorials, circuit diagrams, PCB layouts, Arduino projects and repair guides.
;}}

Search this blog

Recent Posts

Tags

Comments

Octapad & MIDI Projects

Featured Posts

Video Tutorials

Recent DIY Projects

More Electronics Tutorials

DIY Electronics

Audio Amplifier Circuits

Arduino Projects

Repair Guides

Featured

Breaking News