909  Bluetooth Profiles

909.1 Learning Objectives

By the end of this chapter, you will be able to:

  • Understand the role of Bluetooth profiles in enabling interoperability
  • Implement Serial Port Profile (SPP) for wireless UART communication
  • Use Human Interface Device (HID) profile for keyboards, mice, and game controllers
  • Configure Advanced Audio Distribution Profile (A2DP) for high-quality audio streaming
  • Choose the right profile for different IoT application requirements

909.2 Prerequisites

Before diving into this chapter, you should be familiar with:

909.3 What Are Bluetooth Profiles?

Bluetooth profiles define how devices should behave for specific use cases. They ensure interoperability between devices from different manufacturers.

Profile Types:

Category Examples Protocol
Audio A2DP, HFP, HSP, AVRCP Classic Bluetooth
Input HID Classic or BLE
Data SPP, FTP, OPP Classic Bluetooth
Health HRS, BLP, GLS BLE GATT
Proximity Find Me, Proximity BLE GATT
Automation Mesh Models BLE Mesh

909.4 Serial Port Profile (SPP)

SPP emulates a serial cable connection, replacing RS-232 with wireless communication.

909.4.1 Architecture

MCU <--UART--> Bluetooth Module <--SPP--> Phone <--Virtual COM--> App

Use Cases:

  • Serial debugging
  • Sensor data transmission
  • Wireless UART for embedded systems
  • Legacy device communication

909.4.2 Implementation

SPP uses RFCOMM (Radio Frequency Communication) to create virtual serial ports:

# Python example using PyBluez
import bluetooth

# Server (peripheral device)
server_sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
server_sock.bind(("", bluetooth.PORT_ANY))
server_sock.listen(1)

# Advertise SPP service
uuid = "00001101-0000-1000-8000-00805F9B34FB"  # SPP UUID
bluetooth.advertise_service(server_sock, "SensorData",
                           service_id=uuid,
                           service_classes=[uuid, bluetooth.SERIAL_PORT_CLASS],
                           profiles=[bluetooth.SERIAL_PORT_PROFILE])

print("Waiting for connection...")
client_sock, client_info = server_sock.accept()
print(f"Connected: {client_info}")

# Send/receive data like a serial port
while True:
    data = read_sensor()
    client_sock.send(f"{data}\n")

909.4.3 Arduino Example

#include <SoftwareSerial.h>

// HC-05 Bluetooth module on pins 10, 11
SoftwareSerial bluetooth(10, 11);  // RX, TX

void setup() {
    Serial.begin(9600);
    bluetooth.begin(9600);
    Serial.println("Bluetooth SPP Ready");
}

void loop() {
    // Send sensor data over Bluetooth
    int sensorValue = analogRead(A0);
    bluetooth.println(sensorValue);

    // Receive commands from phone
    if (bluetooth.available()) {
        char cmd = bluetooth.read();
        processCommand(cmd);
    }

    delay(100);
}

909.4.4 SPP Limitations

Limitation Impact Workaround
No BLE support Won’t work with BLE-only devices Use BLE UART service
Discovery required User must pair manually Implement NFC pairing
Power consumption Higher than BLE Use for streaming only
No standard data format App must parse data Define protocol

909.5 Human Interface Device (HID)

HID profile enables input devices like keyboards, mice, and game controllers.

909.5.1 HID over Classic Bluetooth

Used by most wireless keyboards and mice:

Characteristics:

  • Low latency (8-11ms typical)
  • Report-based data structure
  • Boot protocol for BIOS compatibility
  • Encryption required

909.5.2 HID over GATT (BLE)

BLE version for lower power devices:

Service UUID: 0x1812

Characteristics:

UUID Name Properties
0x2A4A HID Information Read
0x2A4B Report Map Read
0x2A4C HID Control Point Write No Response
0x2A4D Report Read, Write, Notify
0x2A4E Protocol Mode Read, Write No Response

909.5.3 HID Report Types

Type Direction Use
Input Device -> Host Keystrokes, mouse movement
Output Host -> Device LED status (Caps Lock)
Feature Bidirectional Configuration

909.5.4 Example: BLE Keyboard

#include <BleKeyboard.h>

BleKeyboard bleKeyboard("ESP32 Keyboard");

void setup() {
    bleKeyboard.begin();
}

void loop() {
    if (bleKeyboard.isConnected()) {
        // Type a message
        bleKeyboard.print("Hello from ESP32!");

        // Special keys
        bleKeyboard.press(KEY_LEFT_CTRL);
        bleKeyboard.press('c');
        bleKeyboard.releaseAll();

        delay(1000);
    }
}

909.5.5 Game Controller Support

Modern game controllers use HID:

Platform Protocol Latency
Xbox Series Bluetooth HID ~8ms
PlayStation 5 Bluetooth HID ~10ms
Nintendo Switch Bluetooth HID ~15ms

909.6 Advanced Audio Distribution Profile (A2DP)

A2DP enables high-quality stereo audio streaming.

909.6.1 Architecture

Audio Source                    Audio Sink
(Phone)                        (Headphones)
   |                               |
   +--[SBC/AAC/aptX Encoder]-->   +--[Decoder]-->
   +--[L2CAP]---------------->    +--[L2CAP]-->
   +--[ACL Link]------------->    +--[DAC]-->
                                   +--[Speaker]

909.6.2 Audio Codecs

Codec Bitrate Latency Quality License
SBC 328 kbps ~200ms Good Free (mandatory)
AAC 256 kbps ~100ms Very Good Licensed
aptX 352 kbps ~70ms Excellent Licensed
aptX HD 576 kbps ~100ms Near CD Licensed
LDAC 990 kbps ~200ms Hi-Res Licensed
LC3 Variable ~20ms Excellent BLE Audio

909.6.3 Codec Selection

Connection Negotiation:
1. Source advertises supported codecs
2. Sink selects preferred codec
3. Both sides confirm codec parameters
4. Streaming begins

Priority (typical):
LDAC > aptX HD > aptX > AAC > SBC

909.6.4 A2DP Latency Considerations

Audio latency affects user experience:

Use Case Acceptable Latency Recommended Codec
Music listening <200ms Any
Video watching <100ms aptX, AAC
Gaming <50ms aptX Low Latency
Live performance <20ms Wired or LC3

909.7 Audio/Video Remote Control Profile (AVRCP)

AVRCP provides media playback control alongside A2DP:

Supported Commands:

Command Description
Play Start playback
Pause Pause playback
Stop Stop playback
Next Skip to next track
Previous Skip to previous track
Fast Forward Speed up playback
Rewind Reverse playback
Volume Up/Down Adjust volume

Metadata (AVRCP 1.3+):

  • Track title
  • Artist name
  • Album name
  • Track duration
  • Playback position

909.8 Hands-Free Profile (HFP)

HFP enables voice calls through Bluetooth devices:

Features:

  • Voice call audio routing
  • Call control (answer, reject, hold)
  • Voice dialing
  • Caller ID display
  • Volume control

Use Cases:

  • Car hands-free systems
  • Bluetooth headsets
  • Smart speakers

909.8.1 HFP vs HSP

Feature HFP HSP
Call control Full Limited
Voice dial Yes No
Caller ID Yes No
Three-way calling Yes No
Audio codec CVSD, mSBC CVSD
Use case Modern devices Legacy

909.9 Technology Comparison

Choosing the right profile for your application:

Feature Classic BT BLE BLE Mesh
Range ~100m ~50m Multi-hop
Data Rate 1-3 Mbps 125k-2M Low
Power Medium Very Low Low
Latency ~100ms ~7.5ms Variable
Devices 7 active Many 32,000+
Setup Pairing Advertising Provisioning
Best For Audio, files Sensors Building-wide

909.9.1 Profile Selection Guide

Application Recommended Profile Why
Wireless earbuds A2DP + AVRCP + HFP Full audio + calls
Fitness tracker BLE HRS + GATT Low power, phone sync
Game controller HID (Classic or BLE) Low latency input
Smart lock BLE Custom GATT Security, battery life
Industrial sensor BLE or Mesh Power efficiency
Debug console SPP Serial compatibility
Car audio A2DP + HFP Music + calls

909.10 Case Study: Wireless Earbuds

Modern wireless earbuds demonstrate multi-profile integration:

Profiles Used:

  1. A2DP - Stereo music streaming
  2. AVRCP - Play/pause/skip control
  3. HFP - Voice calls
  4. BLE GATT - Battery level, custom settings

Dual-Mode Operation:

Classic Bluetooth: A2DP + HFP audio streaming
                   |
                   v
BLE: Battery service, touch controls, firmware update

Power Optimization:

  • A2DP codec selection affects battery life
  • BLE for low-power status updates
  • Sleep mode when not playing
  • Active noise cancellation power budget

909.11 Summary

This chapter covered Bluetooth profiles for different applications:

  • SPP enables wireless UART for embedded systems and debugging
  • HID provides standardized input device communication (keyboards, mice, controllers)
  • A2DP streams high-quality stereo audio with various codecs
  • AVRCP adds media playback control to audio streaming
  • HFP enables hands-free voice calls for headsets and car systems
  • Profile selection depends on data rate, power, latency, and device compatibility
  • Modern devices often combine multiple profiles (A2DP + HFP + BLE GATT)

909.12 What’s Next

The next chapter, Bluetooth Hands-On Lab, provides a complete Wokwi-based lab where you’ll build a BLE sensor beacon from scratch, implementing GATT services, notifications, and connection handling.