loading

This Instructable describes how to build a USB pedal with an Arduino Leonardo board.

When you press the pedal with your foot, a keyboard keystroke will be send to your computer, smartphone or tablet over USB.

The possibilities are endless! Some examples:

  • Start / stop photo slideshow.
  • Next slide Powerpoint presentation.
  • Scroll webpages up or down.
  • Flip a page forward / backward in a PDF reader. (Useful for musicians!)
  • Start / stop audio recording. (Useful for musicians!)
  • Other custom keyboard actions.

This project describes how to send [Page down] and [Page up] keys for two pedals, but you can use one pedal for one keystroke as well.
Adding additional pedals allows you to send more keystrokes.
It can be used on Windows, Linux and Android smartphones or tables.
The Leonardo board is equivalent to a standard HID (Human Interface Device Class) USB keyboard.


Project level:
Easy Difficult


Prerequisites:

  • A computer with Arduino IDE version 1.6 or higher installed.
  • An Arduino board with HID USB keyboard support is required.
  • Some hardware components and tools. (Described in next chapters).

There are plenty of commercial USB foot pedals available for 200 Euro's/Dollars or more. DIY projects are customizable and a lot of fun to build!


Let's start!

Step 1: Components

You need the following components:

  • Arduino Leonardo board.
  • Micro USB cable.
  • Black and yellow wires (Inside: LIY 26 AWG, 18 x 0.1mm, outer diameter: 1.20mm).
  • Female TS mono plug (1/4" 6.35mm).
  • 2x Dupont male DIY connector (inside and outside).
  • One or more foot switches / pedals. (I use a M-Audio SP-2 sustain pedal)

Tip: You can use other Arduino boards with an ATmega32U4 chip such as the Leonardo Pro Micro, as long as the chip supports on-chip USB with HID keyboard.


Warning: The Arduino UNO board does not support USB HID keyboard and cannot be used with this project.

Step 2: Tools

You need the following tools:

  • Soldering station.
  • Tin.
  • Dupont crimper tool.
  • Pliers (a pair of flat tongs) tool.
  • Multimeter (Optional)

Step 3: Hardware

At least one pedal (switch) should be connected to an Arduino Leonardo board.

Connect the switch between GND and digital pin 2.
If you have a second pedal, connect it between GND and digital pin 3.


Note: I use a N.O. (normally open) switches.

Step 4: Create a Custom Cable With Connectors

In this step a custom cable will be created to connect the pedal to the Arduino board.

  1. Cut two wires at around 10cm.
  2. Strip the wire ends (4mm coper).
  3. Cut the connector from the strip and keep the attachment at the end of the connector.
  4. Put the wires into the Dupont male header.
  5. Fold the pull relief with a flat plier to keep the wire in position.
  6. Put the wire with connector into the Dupont crimp tool.
  7. Shrink the Dupont connector with the crimper tool.
  8. Remove the attachment from the connector.
  9. Mount the connector in the housing.

Tip: Please refer to my other Instructable how to create a custom cable with Dupont connectors:
https://www.instructables.com/id/Dupont-Crimp-Tool-Tutorial/

Step 5: Solder the Cable

Solder the wires to the female TS connector.

Step 6: Arduino Sketch

The Arduino sketch below sends a [Page Down] keyboard keystroke by pressing the pedal with your foot on digital pin 2.

An optional second pedal can be connected to GND and digital pin 3 to send a [Page Up] key.


Connect a (micro) USB cable between the Arduino Leonardo board and your computer. Open the Arduino IDE and copy-paste the following code:


#include "Keyboard.h"

#define PEDAL1_PIN   2
#define PEDAL2_PIN   3

// Works on the Leonardo board only to simulate 
// a HID keyboard over USB

static void Pedal1Down(void)
{
    Keyboard.press(KEY_PAGE_DOWN);
}

static void Pedal2Down(void)
{
    Keyboard.press(KEY_PAGE_UP);
}

void setup(void)
{
    Keyboard.begin();

    // Set pin to input
    pinMode(PEDAL1_PIN, INPUT);
    // Enable pullup resistor
    digitalWrite(PEDAL1_PIN, HIGH);

    // Set pin to input
    pinMode(PEDAL2_PIN, INPUT);
    // Enable pullup resistor
    digitalWrite(PEDAL2_PIN, HIGH);
}

void loop(void)
{
    static uint8_t pedal1StateLast = 0;
    static uint8_t pedal2StateLast = 0;
    uint8_t pedalState;

    pedalState = digitalRead(PEDAL1_PIN);
    if (pedalState != pedal1StateLast) {
        pedal1StateLast = pedalState;

        if (pedalState == 0) {
            Pedal1Down();
            delay(100);
            Keyboard.releaseAll();
        }
    }

    pedalState = digitalRead(PEDAL2_PIN);
    if (pedalState != pedal2StateLast) {
        pedal2StateLast = pedalState;

        if (pedalState == 0) {
            Pedal2Down();
            delay(100);
            Keyboard.releaseAll();
        }
    }

    delay(50);
}

Select your board (Arduino Leonardo) with corresponding Serial port and press the Upload button.


Tip: Feel free to customize your key strokes!

You can find other keystrokes here.

Step 7: Test With a Windows or Linux Computer

1. Connect the pedal to your Arduino board.

2. Make sure your pedal is set in N.O. (Normally Open) mode. Some pedals have a switch at the bottom of the pedal.

3. Connect the Arduino board to your computer.

Open a PDF reader and press the pedal. It scrolls down when everything works correctly!

If you have one pedal, move digital pin 2 to digital pin 3 if you want to test page up.

Step 8: Test With an Android Tablet

Connect the Arduino USB cable via a USB OTG cable to your tablet or phone.

Open a web browser or PDF reader and press the pedal. This should scroll down when it works correctly!

Step 9: Finished!

Congratulations! Your experimental USB pedal has been finished!

Next step is to build a nice case which is beyond the scope of this Instructable.

Feel free to leave a comment with feedback or your success story. :-)
Thanks!

About This Instructable

837views

12favorites

License:

More by Erriez:USB pedal HID keyboard with Arduino Leonardo Dupont crimp tool tutorial Build Arduino IDE from GIT sources on Windows 
Add instructable to: