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:
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:
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!
You need the following components:
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.
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.
In this step a custom cable will be created to connect the pedal to the Arduino board.
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/
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.
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.
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!