Welcome to Project 41! Letâs be honest for a second: there is nothing quite as humblingâor infuriatingâas trying to elegantly land a Boeing 747 in Microsoft Flight Simulator while frantically dragging your mouse around to click a virtual toggle switch. By the time you find the landing gear button, youâve already plowed into a virtual Wendyâs.
You could go online and drop $300 on a commercial flight sim control panel, but whereâs the fun in that? We are makers. We like the smell of rosin core solder in the morning. We want tactile, satisfyingly loud clack noises and switches with those red missile covers that make us feel like weâre arming an ejection seat in a fighter jet.
Today, weâre building a custom USB HID Flight Simulator Switch Panel using an Arduino Leonardo. Weâre going to trick your computer into thinking your homemade box of spaghetti wiring is a standard keyboard or joystick.

If you read Lesson 111: Meet the Arduino Uno, you might be wondering why we arenât using our trusty Uno for this. The secret lies in the microcontroller chip. The Uno uses the ATmega328P, but the Arduino Leonardo uses the ATmega32U4.
This magical little chip has built-in USB communication. That means it can natively emulate a USB Human Interface Device (HID)âlike a mouse, keyboard, or gamepad.
To build your cockpit, youâll need:
The wiring is going to utilize the magic of internal pull-up resistors, exactly like we learned back in Lesson 114: Digital Inputs. We donât need any external resistors!
When you flip a switch, it connects the digital pin to Ground, pulling the voltage LOW.
We will use the built-in Keyboard.h library. When a switch is flipped, the Arduino will âpressâ a key on your computer, just like a real keyboard.
Here is the code to get you started with mapping a toggle switch to the âGâ key (which toggles landing gear in most flight sims).
#include <Keyboard.h>
const int gearSwitchPin = 2; // The pin for our landing gear switch
int previousGearState = HIGH;
void setup() {
// Use the internal pull-up resistor
pinMode(gearSwitchPin, INPUT_PULLUP);
// Initialize control over the keyboard
Keyboard.begin();
}
void loop() {
// Read the current state of the switch
int currentGearState = digitalRead(gearSwitchPin);
// Check if the switch state has changed (been flipped)
if (currentGearState != previousGearState) {
// Send the 'G' keypress to toggle landing gear
Keyboard.press('g');
delay(100); // Hold the key for a fraction of a second
Keyboard.release('g');
// Add a debounce delay to avoid sending double-clicks
delay(50);
}
// Save the state for the next loop
previousGearState = currentGearState;
}
Upload this code, flip your physical switch, and watch your virtual landing gear drop! You can expand this code to include dozens of switches mapped to flaps, lights, brakes, and autopilot functions. Happy flying, Captain!