Controls
Foot pedal for the computer
Step on it to press a key with your hands free: turn a page of sheet music, pause a video or move to the next slide.
- Easy
- about 30 min
- ESP32-S3
- 6 parts
- 4 wires
- 39 lines of code
ESP32 packs are built on real parts: the simulator runs Arduino Uno circuits only.
Idea
Four wires and a few lines of code. The computer sees an ordinary keyboard, so it works in every program without installing anything.
What you learn
Acting as a USB keyboard, and holding a key down for as long as a switch is closed.
How it works
input
Foot switch
Mode switch
decides
ESP32-S3
output
Computer (USB keyboard)
Powered with 5 V through the board's USB-C port.
A reference design. The sketch is compiled with the real ESP32 toolchain, and its pins are checked against the wiring table automatically. It has not yet been built and tested on real parts by us, so wire it on the bench and run the checks before you build it into a case. Real modules vary: follow the labels printed on yours, not their position in the picture.
Parts
0 of 6 ready
No prices here: they change by shop and by week. Buy each part by its name and the note beside it.
You also need
A computer with Arduino IDE 2 installed (free)
3D wiring
One jumper per step, with the USB cable unplugged. Several wires may share 3V3, 5V or GND: the expansion board or breadboard gives each its own pin.
Step 0 of 4
Lay out the parts
Seat the board on its expansion board or breadboard and lay the modules out round it. Nothing is connected yet.
All connections
foot-pedal.ino
// Foot pedal for the computer
// Step on it to press a key, hands free. The mode switch chooses which key.
// Arduino IDE: Tools > USB Mode > "USB-OTG (TinyUSB)", then plug the cable
// into the DevKit's port marked USB (not UART) to use it as a keyboard.
#include "USB.h"
#include "USBHIDKeyboard.h"
const int PIN_PEDAL_A = 5;
const int PIN_MODE_A = 6;
// Mode switch open: page down (reading music, turning pages).
// Mode switch closed: space bar (play/pause a video, next slide).
const uint8_t KEY_MODE_OPEN = KEY_PAGE_DOWN;
const uint8_t KEY_MODE_CLOSED = ' ';
USBHIDKeyboard Keyboard;
bool wasDown = false;
void setup() {
pinMode(PIN_PEDAL_A, INPUT_PULLUP);
pinMode(PIN_MODE_A, INPUT_PULLUP);
Keyboard.begin();
USB.begin();
}
void loop() {
bool down = digitalRead(PIN_PEDAL_A) == LOW;
if (down != wasDown) {
delay(15); // let the contacts settle
down = digitalRead(PIN_PEDAL_A) == LOW;
}
if (down && !wasDown) {
uint8_t key = digitalRead(PIN_MODE_A) == LOW ? KEY_MODE_CLOSED : KEY_MODE_OPEN;
Keyboard.press(key);
}
if (!down && wasDown) Keyboard.releaseAll();
wasDown = down;
delay(2);
}
Libraries
None. It uses only what the Arduino IDE has built in.
Uploading
First time with an ESP32: in Arduino IDE open Boards Manager, search “esp32” and install “esp32 by Espressif Systems”.
- Set Tools > USB Mode to “USB-OTG (TinyUSB)”. Upload through the port marked UART, then move the cable to the port marked USB to use it.
- Open the sketch in Arduino IDE.
- Plug the board in with the USB-C cable.
- Tools > Board > ESP32S3 Dev Module, then Tools > Port and choose the board's port.
- Press Upload (the arrow). Wait for “Done uploading”.