Emulating A Bluetooth Keyboard With The ESP32

Most people associate the ESP family of microcontrollers with WiFi, which makes sense as they’ve become the solution of choice for getting your project online quickly and easily. But while the WiFi capability might be the star of the show, the ESP32 also comes equipped with Bluetooth; we just don’t see people using it nearly as often. If you’re looking to get started using Bluetooth on the ESP32, then this simple wireless macro keypad from [Brian Lough] would be a great way to get started.

From a hardware standpoint, this project is incredibly straightforward. All you need to do is connect a membrane keypad up to the GPIO pins on the ESP32. Adding in a battery is a nice touch, and you probably would want to put it into a enclosure of some sort, but as a proof of concept it doesn’t get much easier than this. In this case [Brian] is using the TinyPICO board, but your personal ESP32 variant of choice will work just as well.

The rest of the project is all software, which [Brian] walks us through in the video after the break. There’s a preexisting library for Bluetooth Human Interface Device (HID) emulation on the ESP32, but it needs to be manually installed in the Arduino IDE. From there, he demonstrates how you can build up a functioning keyboard, including tricks such as sending multiple virtual keys at once.

In the past we’ve seen the ESP32 used to create a Bluetooth game controller, but the ability to emulate a keyboard obviously offers quite a bit more flexibility. With a practical demonstration of how easy as it is to turn this low-cost microcontroller into a wireless input device, hopefully we’ll start seeing more projects that utilize the capability.

14 thoughts on “Emulating A Bluetooth Keyboard With The ESP32

  1. I’ve been looking for a keyboard that can do USB and Bluetooth for a long time so that I can switch between my Desktop Gaming machine and my work laptop. I might just have to build my own mechanical keyboard now…

    1. I have a rechargeable folding backlit keyboard that does just that, can work either as a bluetooth keyboard or as an USB keyboard (handy if you need to edit bios settings, for example). I won’t link it here, because there’s tons of the things, rebranded to hell, available by the usual online sellers. Mechanically they are not exactly ideal for gaming or long typing, but using them as brains for another keyboard should be in the realm of the possible.

  2. I’m working on a very similar project to reuse an old Dell laptop keyboard and add bluetooth with an ESP32. This project should be a handy reference to help me later, once I finally manage get the FPC connector soldered to the PCB.

  3. With some more hacking (mouse emulation) this would make an excellent addition to an automated test setup, for simulating user input. Since the simulation is done in hardware, you can put the actual deployed hardware in the test rig.

  4. If I were making a bluetooth keyboard simply to be used as a keyboard, I wouldn’t want the power overhead of an ESP32. There are cheap BLE 4.0 modules available on ebay for a buck or two, and I’ve had good luck with the HM-10. They’re based on a TI CC2541 chip, and it’s possible to flash custom firmware to them so they can be used standalone rather than communicating via serial to an arduino. They take very little power. If you search “geekhack hm-10” you can find a bunch of resources where people have used these to bluetooth-ify a bunch of custom mechanical keyboards.

  5. ESP-32 can emulate many BLE devices, so keyboards are just a beginning. Just have a look at the list of GATT services and characteristics – the list goes on and on… I am using one as a traning bike cadence and distance meter, for example.

  6. Hi all – perhaps I missed something, but what target Board and Processor should I select in the Arduino IDE when uploading the template sketch? Default Genuine Arduino did not do the trick and failed on upload. Was this covered in a different video?

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.