Get the Most Out of Your Raspberry Pi Experience with a Wireless Bluetooth Keyboard

Learn how to connect your trusty Bluetooth keyboard to your Raspberry Pi 4 for a more convenient and hassle-free computing experience. …


Updated September 4, 2023

Need help with your Raspberry Pi?
Contact Me!

Do you love silly Raspberry Pi Projects?
Check out my this YouTube Channel!


Learn how to connect your trusty Bluetooth keyboard to your Raspberry Pi 4 for a more convenient and hassle-free computing experience.

Before you begin, ensure that you have the following:

  • A Raspberry Pi with Raspbian OS installed (we will assume you are using Raspbian for this guide)
  • A Bluetooth keyboard or mouse (this guide focuses on keyboards but can be adapted for mice as well)
  • A Micro USB to USB adapter if your keyboard does not have a micro USB port

Step 1: Pairing Your Keyboard with the Raspberry Pi First, we need to enable Bluetooth on your Raspberry Pi. Open a terminal and type in the following command:

sudo systemctl enable bluetooth && sudo systemctl start bluetooth

This will enable and start the Bluetooth service on your Raspberry Pi. Next, check if your keyboard is discoverable by typing:

bluetoothctl scan on

You should see your keyboard’s name listed among other available devices. Note down the MAC address (a unique identifier) of your keyboard.

Now, pair your Bluetooth keyboard with the Raspberry Pi using the following command (replace XX:XX:XX:XX:XX:XX with the actual MAC address):

bluetoothctl pair XX:XX:XX:XX:XX:XX

Enter the passkey when prompted, and your keyboard is now paired!

Step 2: Making Your Keyboard Work with Raspberry Pi To ensure that your Bluetooth keyboard works seamlessly with your Raspberry Pi, you need to add it to the input devices list. First, check if your keyboard is already recognized by typing:

ls /dev/input/by-id/

Look for a file named bluetooth-XXXXXXXXXX (replace XXXXXXXXX with part of your keyboard’s MAC address). If it exists, skip to Step 3. Otherwise, create a new udev rule by typing:

sudo nano /etc/udev/rules.d/99-btkbd.rules

Add the following line to the file (replace XXXX with the last four characters of your keyboard’s MAC address):

SUBSYSTEM=="input", ATTRS{idVendor}=="05ac", ATTRS{idProduct}=="XXXX", MODE:="6664", GROUP="plugdev"

Save and exit the file (Ctrl + X, Y, Enter). Now, reboot your Raspberry Pi for the changes to take effect:

sudo reboot

After the reboot, check if your keyboard is recognized by running:

ls /dev/input/by-id/

You should now see a file named bluetooth-XXXXXXXXXX.

Step 3: Configuring the Keyboard as an Input Device Finally, we need to configure your Bluetooth keyboard as an input device so that it can be used in graphical environments like the Raspberry Pi Desktop or when running GUI applications. Open /etc/rc.local using a text editor (before the exit 0 line):

sudo nano /etc/rc.local

Add the following lines before the exit 0 line:

modprobe btusb
/bin/bash -c "cat /dev/input/by-id/bluetooth-XXXXXXXXXX > /dev/null &"

Replace XXXXXXXXX with the last four characters of your keyboard’s MAC address. Save and exit the file (Ctrl + X, Y, Enter). Reboot your Raspberry Pi for the changes to take effect:

sudo reboot

Now, you should be able to use your Bluetooth keyboard on your Raspberry Pi!

Note: If you want to connect multiple Bluetooth devices, repeat Steps 1 and 2 for each device and add another line in /etc/rc.local for each device.

Conclusion Now that your Bluetooth keyboard is connected to your Raspberry Pi, you can enjoy a more comfortable and hassle-free computing experience. You can easily switch between devices without having to unplug and reconnect your keyboard every time you power on your Raspberry Pi. Additionally, if you use a wireless mouse, the same process applies for connecting it to your Raspberry Pi.

Happy tinkering!