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.
- Turn on Bluetooth: Ensure your Raspberry Pi is powered on and the desktop has loaded. Look at the top right corner of the screen for the Bluetooth icon. If it has a red cross through it, click it and select Turn On Bluetooth.
- Enable Pairing Mode: Put your Bluetooth keyboard or mouse into pairing mode. This usually involves holding down a dedicated Bluetooth button or the power button until a light starts flashing rapidly.
- Search for Devices: Click the Bluetooth icon on the Raspberry Pi taskbar and select Add Deviceā¦. A window will pop up and begin scanning for nearby discoverable electronics.
- Connect the Peripheral: Select your keyboard or mouse from the list of discovered devices and click Pair.
- Complete Authentication: For a mouse, the connection should establish immediately. For a keyboard, the system will display a numeric passcode on the screen. Type this passcode using your Bluetooth keyboard and press Enter to finalize the pairing.
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:
bluetoothctl2. 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.