How to connect Raspberry Pi to Bluetooth Keyboard

Follow the steps below to connect your Bluetooth Keyboard or Mouse to your Raspberry Pi.

I’m using a Logitech K380 on the examples below since that is my Bluetooth keyboard. But you can follow the same steps if you are using a different Bluetooth keyboard or device, such as a Bluetooth mouse.

Update the Raspberry Pi before Connecting the Bluetooth Keyboard

During the writing of this post, a lot of time I encountered the Raspberry Pi failed to find my bluetooth keyboard even though it was already in pairing mode.

I solved this by upgrading my Raspberry Pi OS.

To do this, open a Terminal and run the following commands.

sudo apt update
sudo apt upgrade -y

After the upgrade, you should be able to have no issues following the steps below.

Connecting Raspberry Pi to a Bluetooth Keyboard via Desktop

First put your Bluetooth Keyboard in Pairing Mode.

Since I am using Logitech K380 Keyboard, I will have to long press one of the yellow keys for it to be in pairing mode.

On your Raspberry Pi, click on the Bluetooth icon on the taskbar, then click Add Device….

This will open the Add New Device window.

At first it will show that it has discovered a device with letters and numbers. Wait until it changes to a more descriptive name.

Once it changes, select your keyboard name, then click Pair.

A panel will say that it has sent a pairing request to your keyboard. Wait for this to finish.

Then it will ask for a 6-digit code.

Enter the 6-digit code in your bluetooth keyboard, and then press Enter.

The 6-digit code changes everytime. So yours is most likely different.

Once you have successfully entered the code, the panel will change to Pairing successful – connecting…

Once it says Connection successful, click OK.

Test the bluetooth keyboard by opening the Text Editor. Weirdly, the bluetooth keyboard will not be fully working by this time.

Here is a screenshot of what it looks like when I type “The quick brown fox jumps over the lazy dog.”

Notice that it does not register some of the keys like spacebar and the letter ‘c’.

To solve this, reboot the Raspberry Pi and test again.

Here is what it looks like when I type “The quick brown fox jumps over the lazy dog” after the reboot.

You may now enjoy typing on your Bluetooth Keyboard in the Raspberry Pi Desktop.


Remove Bluetooth Keyboard from being paired with a Raspberry Pi Desktop

If you want to disconnect your Bluetooth Keyboard and do not want it to automatically connect again, then click on the Bluetooth Icon on the taskbar.

Hover over your Bluetooth Keyboard name. Then click Remove.

In the example below, my Logitech K380 Keyboard is shown as Keyboard K380.

A window will appear, confirming if you want to remove your bluetooth device.

Click OK.

Once this is done, your bluetooth keyboard will no longer automatically connect to the Raspberry Pi.


Connecting Raspberry Pi to a Bluetooth Keyboard via Terminal

If you are using Raspberry Pi OS Lite without the Desktop GUI or you just simply want to use the Terminal to connect your Bluetooth Keyboard, then follow the instructions below.

Put your Bluetooth Keyboard in Pairing Mode.

Since I am using Logitech K380 Keyboard, I will have to long press one of the yellow keys for it to be in pairing mode.

Open a Terminal in Raspberry Pi.

Run the command below to enter the interactive bluetooth control tool, bluetoothctl.

sudo bluetoothctl

Once inside bluetoothtl, run the commands below.

agent on
default-agent

The two commands above are optional, I only use them whenever the next commands do not work. So if you are not sure, just run them.

Next is to scan for available bluetooth devices that are broadcasting their ID.

scan on

Wait until it shows the target bluetooth device name.

Once your device can be seen, stop scanning by running the command below.

scan off

Get the Media Access Control (MAC) Address of your bluetooth keyboard. In my case, its F4:73:35:45:3E:C2.

Then pair the Raspberry Pi with your keyboard.

pair <MAC Address>

This will ask for a 6-digit passkey. Type the passkey on your bluetooth keyboard and press Enter.

Next is to connect the bluetooth of Raspberry Pi and your keyboard.

connect <MAC Address>

Then for the Raspberry Pi to automatically allow the bluetooth keyboard to connect, run the command below.

trust <MAC Address>

You have now successfully connected your Bluetooth Keyboard to the Raspberry Pi using the Terminal.

To exit bluetoothctl, enter the exit command.

exit

After, reboot the Raspberry Pi to avoid the issue above where the Bluetooth Keyboard keys are not typing all the characters on the keyboard.

sudo reboot

After the reboot, you may use the Bluetooth Keyboard in Raspberry Pi OS lite or Raspberry Pi OS desktop.


Remove Bluetooth Keyboard pairing with Raspberry Pi via Terminal

If you want to remove the pairing of your Bluetooth Keyboard from your Raspberry Pi, then do the following.

Enter bluetoothctl.

sudo bluetoothctl

List the paired devices on your Raspberry Pi.

paired-devices

Your Bluetooth keyboard should be listed here along with its MAC Address.

Untrust your Bluetooth device.

untrust <MAC Address>

Remove your Bluetooth device.

remove <MAC Address>

With the confirmation message that your keyboard or mouse has been removed, you have successfully remove your Bluetooth device.

Exit bluetoothctl.

exit

bluetoothctl Command List

If you want to know all the available commands in bluetoothctl, then run the help command.

help

This will open a menu that lists down the available commands and their descriptions.


I hope this helps you connect your Bluetooth Keyboard to the Raspberry Pi. Let me know what you think in the comments below.

2 thoughts on “How to connect Raspberry Pi to Bluetooth Keyboard”

  1. Thanks the bluetoothctr command line did the trick. I could never get Raspberry Pi to pair from the gui; but no issues with the command line. Thanks again.

  2. For some reason my Raspberry Pi couldn’t find my keyboard with the scan. So I paired the keyboard with my Macintosh, then used ‘system_profiler SPBluetoothDataType’ to obtain the keyboard’s MAC address, then paired it with the Raspberry Pi as described above.

Leave a Reply

Your email address will not be published. Required fields are marked *

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