Introduction: Bottle Cap Keyboard

About: Arduino, NodeMCU, 3D Printer hobbyist.

This is a pretty simple and fun project with Arduino Pro Micro.

You will create a simple version of the president's key(board).

It will do an action in your computer (Mac or Pc) by emulating keyboard shortcuts or commands.

In my case, I use it with CMD+Q (quit application in mac) shortcut key for easy off from working.

Step 1: You Will Need...

  • Arduino Pro Micro (not pro mini)
  • 1 Mechanical switch. (Clicky Blue Switch recommended)
  • Printed parts. (Model files is included in attached zip file)
    • TOP, BOTTOM, KEYCAP
  • 1 Pin-head cable. (female)
  • USB cable micro 5 pin. (Commonly used)

Step 2: Assembly

I recommend to watch the instruction video (ENG SUB). (wiring is bit tricky)

  1. Soldering the Pins on Reverse. (Header Pins on topside)
  2. Place an Arduino Pro Micro on bottom case. (There are slots for pin headers)
  3. Cut a header pin cable in half and solder directly to the switch.
  4. Close the top case on the bottom case.
  5. Connect header pins from outside. ( 8(A8) and GND port)
  6. Insert the switch.
  7. Insert a bottle key cap part.
  8. Done

Step 3: Arduino Sketch

Header pin is connected to port 8(A8) = switch_pin is 8.

We use internal pull-up resistor 'cause the switch directly connected.

I used CMD+q (mac) for using the key as exit application short cut. (Use KEY_LEFT_ALT + KEY_F4 for PC)

Change Keyboard.press( ?? ) part to program your own shotcuts.

#include <HID.h>
#include <Keyboard.h>

// connected PIN8
const int switch_pin        = 8;

int button_state            = 0;
int previous_button_state   = HIGH;
long last_debounce_time     = 0;
const long debounce_delay   = 50;

void setup() 
{
  // We use internal pullup registor 'cause the switch directly connected.
  pinMode(switch_pin,INPUT_PULLUP); 
  digitalWrite(switch_pin, HIGH);
  
  Keyboard.begin();
}


void loop() 
{
  button_state = digitalRead(switch_pin);
  if ((button_state != previous_button_state) && (button_state == HIGH)) 
  {
    if ((millis() - last_debounce_time) > debounce_delay) 
    {
      // Exit Program (CMD+Q in mac) & Have a nice day!
      // Use KEY_LEFT_ALT + KEY_F4 for PC 
      Keyboard.press(KEY_LEFT_GUI);
      Keyboard.press('q');
      delay(100);
      Keyboard.releaseAll(); // This is important after every Keyboard.press it will continue to be pressed
      last_debounce_time = millis();
    }
  }
  previous_button_state = button_state;
}

Step 4: Done

Most soft drink PET bottle lids conform PCO-1881 standard and usable for this project.

I hope you'll have fun.

Pocket Sized Contest

Participated in the
Pocket Sized Contest