How to Pair a Bluetooth Keyboard or Mouse with Raspberry Pi

Connecting a Bluetooth keyboard or mouse to a Raspberry Pi is a straightforward process that can be completed either through the graphical desktop interface or via the command line terminal. This guide provides a step-by-step walkthrough for both methods, ensuring you can easily connect your wireless peripherals and get your Raspberry Pi setup up and running without the hassle of tangled cords.

Method 1: Using the Raspberry Pi Desktop GUI

For most users, the graphical user interface (GUI) is the easiest and quickest way to connect a Bluetooth device.

Method 2: Using the Command Line (Bluetoothctl)

If you are running a headless setup (Raspberry Pi OS Lite) or prefer using the terminal, you can manage your connections using the built-in bluetoothctl tool.

1. Launch the Bluetooth Utility

Open a terminal window or connect via SSH, then enter the following command to start the interactive Bluetooth control tool:

bluetoothctl

2. Prepare the Environment

Inside the Bluetooth prompt, turn on the controller, enable the agent, and set it to look for nearby devices by running these commands in sequence:

power on
agent on
default-agent
scan on

3. Pair and Trust the Device

Put your keyboard or mouse into pairing mode. Watch the terminal output for a string of characters that looks like XX:XX:XX:XX:XX:XX followed by the name of your device. Once you see it, note the MAC address and run:

pair XX:XX:XX:XX:XX:XX

If you are pairing a keyboard, type the passkey prompted by the terminal onto the Bluetooth keyboard and press Enter.

Finally, ensure the device reconnects automatically every time you boot your Raspberry Pi by trusting and connecting to it:

trust XX:XX:XX:XX:XX:XX
connect XX:XX:XX:XX:XX:XX

Once the terminal confirms a successful connection, type exit to return to the standard command line.