First of all, to be able to send keyboard and mouse commands via USB, I used an Arduino Pro Micro centered around an ATmega32U4 - an 8-bit AVR very similar to the ATmega328. The ATmega32U4 comes equipped with a full-speed USB transceiver, which can emulate any USB device.

Then, I utilized the 4x4 matrix keypad design to send keyboard keys, supporting up to 32 keys with two dynamic keypad options.

Finally, I used two joysticks as a fully-functional mouse, also controlling the dynamic keypad options and modifier keys.

After completing my design on a breadboard and testing the code, I designed a controller-shaped PCB (Arduino-Based Mouse and Keyboard Controller) with an integrated 4x4 matrix keypad and two embedded joysticks, displaying Pikachu as its center logo :)

Huge thanks to PCBWay for sponsoring this project.

Step 1: Designing and Soldering the Mouse and Keyboard Controller PCB

Before prototyping my PCB design, I tested all connections and wiring with the Arduino Pro Micro on the breadboard.

Then, I designed the Mouse and Keyboard Controller PCB by using KiCad. I attached the Gerber file of the PCB below, so if you want, you can order this PCB from PCBWay to create a stylish and fully-functional USB Keyboard/Mouse displaying Pikachu as its center logo :)

Click here to inspect and order this PCB directly on PCBWay.

First of all, by using a soldering iron, I attached headers (female), COM-09032 analog joysticks, 5mm green LED, 5mm blue LED, 6x6 pushbuttons, and 220Ω resistors.

Component list on the PCB:

A1 (Headers for Arduino Pro Micro)

J1, J2 (COM-09032 Analog Joystick)

K1, K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, K12, K13, K14, K15, K16 (6x6 Pushbutton)

D1 (5mm Green LED)

D2 (5mm Blue LED)

R1, R2 (220Ω Resistor)

C1 (Headers for External Keypad)

Step 2: Setting up the Pro Micro in the Arduino IDE

Before coding, we need to add and verify the Pro Micro board settings on the Arduino IDE. With the latest release of Arduino IDE, adding third party boards to the IDE is easily achieved through the Boards Manager.

⭐ Open up the Arduino IDE, then go to the Preferences (File > Preferences). Then, towards the bottom of the window, paste this URL into the "Additional Board Manager URLs" text box:

https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json

You can add multiple URLs by clicking the window icon and pasting one URL per line.

⭐ Click OK. Then, open the Boards Manager by clicking Tools > the Board selection tab > Boards Manager.

⭐ Search for "sparkfun" in the Boards Manager. When the SparkFun AVR Boards package appears, click install, wait a few moments until the IDE confirms all the installed .brd files.

⭐ Now, select the Sparkfun Pro Micro board under the Sparkfun Boards to upload code to the Pro Micro.

Step 3: Programming the Arduino Pro Micro

⭐ Include the required libraries.

Keypad | Library

Keyboard | Library

Mouse | Library

⭐ Define the symbols on the buttons of the dynamic keypad options - letter and number.

⭐ Initialize the dynamic keypads.

char letterKeys[ROWS][COLS] = {  {'e','a','r','i'},  {'o','t','n','s'},  {'p','m','h','w'},  {'l','c','u','d'}};char numberKeys[ROWS][COLS] = {  {'1','2','3','+'},  {'4','5','6','-'},  {'#','0','*','%'},  {'7','8','9','/'}};byte rowPins[ROWS] = {6, 7, 8, 9}; // Connect to the row pinouts of the keypad.byte colPins[COLS] = {2, 3, 4, 5}; // Connect to the column pinouts of the keypad.// Initialize an instance of class NewKeypad for each keypad setting - letter and number.Keypad letterKeypad = Keypad( makeKeymap(letterKeys), rowPins, colPins, ROWS, COLS);Keypad numberKeypad = Keypad( makeKeymap(numberKeys), rowPins, colPins, ROWS, COLS);

⭐ In the read_joysticks() function, collect the data generated by joysticks - J1 and J2.

void read_joysticks(){  joystick_left_x = analogRead(VRX_L);   joystick_left_y = analogRead(VRY_L);  joystick_left_button = digitalRead(SW_L);    joystick_right_x = analogRead(VRX_R);   joystick_right_y = analogRead(VRY_R);    joystick_right_button = digitalRead(SW_R);}

⭐ In the mouse_controls() function, move the cursor according to the left joystick (J1) movements and click using the left (J1) and right (J2) joysticks.

void mouse_controls(){  // Move mouse according to the left joystick movements.  if(joystick_left_y > 700)  Mouse.move(0, -15); // UP  if(joystick_left_y < 300)  Mouse.move(0, 15);  // DOWN  if(joystick_left_x > 700)  Mouse.move(-15, 0); // LEFT  if(joystick_left_x < 300)  Mouse.move(15, 0);  // RIGHT  if(joystick_left_button == 0) Mouse.click(MOUSE_LEFT); // LEFT CLICK  if(joystick_right_button == 0) Mouse.click(MOUSE_RIGHT); // RIGHT CLICK  delay(100);}

⭐ In the keyboard_controls() function, change dynamic keypad settings (letter or number) and press modifier keys (RETURN and BACKSPACE) according to the right joystick (J2) movements.

⭐ Get the custom key depending on the selected dynamic keypad option - letter or number - and write the custom key as a keyboard key.

void keyboard_controls(){  // Change keypad settings (letter or number) and press modifier keys according to the right joystick movements.  if(joystick_right_y > 700){ Keyboard.press(KEY_RETURN); delay(100); Keyboard.releaseAll(); }    // RETURN  if(joystick_right_y < 300){ Keyboard.press(KEY_BACKSPACE); delay(100); Keyboard.releaseAll(); } // BACKSPACE  if(joystick_right_x > 700){ letter = true; number = false; digitalWrite(let_LED, HIGH); digitalWrite(num_LED, LOW); } // Letter Keypad  if(joystick_right_x < 300){ letter = false; number = true; digitalWrite(let_LED, LOW); digitalWrite(num_LED, HIGH); } // Number Keypad    // Get the custom key depending on the selected keypad type - letter or number.  char customKey;  if(letter == true) customKey = letterKeypad.getKey();  if(number == true) customKey = numberKeypad.getKey();    // Write the custom key.  if (customKey){    Keyboard.write(customKey);  }}

Connections and Adjustments

// Connections// Arduino Pro Micro :           //                                JoyStick (Left)// A0  --------------------------- VRX// A1  --------------------------- VRY// D14 --------------------------- SW// 5V  --------------------------- 5V// GND --------------------------- GND//                                JoyStick (Right)// A2  --------------------------- VRX// A3  --------------------------- VRY// D16 --------------------------- SW// 5V  --------------------------- 5V// GND --------------------------- GND//                                KeyPad// D2  --------------------------- C1// D3  --------------------------- C2// D4  --------------------------- C3// D5  --------------------------- C4// D6  --------------------------- R1// D7  --------------------------- R2// D8  --------------------------- R3// D9  --------------------------- R4//                                Letter Keypad LED// D15 --------------------------- +//                                Number Keypad LED// D10 --------------------------- +

After finishing and uploading the code to the Arduino Pro Micro, I attached it to the PCB via headers.

Modes and Features

🎮 The controller lets the user move the cursor by the left joystick (J1) movements and click by pressing the left (J1) or right (J2) joystick buttons.

🎮 The controller allows the user to choose between the dynamic keypad options (letter and number) and send modifier keys by the right joystick (J2) movements.

🎮 The controller includes an integrated 4x4 matrix keypad. With the dynamic keypad options, the controller supports up to 32 keyboard keys.

🎮 Default Keyboard Keys on Keypad Buttons:

Videos and Conclusion

The controller is compatible with Raspberry Pi, as depicted below: