DEV Community

Raaju Pahlowan
Raaju Pahlowan

Posted on Edited on

Building an iOS App for a Wearable Assistive Glove with CoreBluetooth, Speech and Haptics

For my final-year project I built the Tactile Navigator Glove: a wearable glove that helps visually impaired people notice obstacles. Ultrasonic sensors on the glove measure distance, and an iPhone app receives those readings over Bluetooth and turns them into speech and vibration. This article walks through how the iOS side works, with the mistakes I'd avoid next time.

The architecture

The system has three parts:

The glove: ultrasonic sensors and a microcontroller with a Bluetooth Low Energy (BLE) module, sending distance readings.
The BLE layer in the app: scans, connects and receives readings using CoreBluetooth.
The feedback layer: decides what to say or vibrate, using AVSpeechSynthesizer and Core Haptics.

I kept these separate on purpose. The BLE layer knows nothing about speech, and the feedback layer knows nothing about Bluetooth. That made it possible to test the feedback logic with fake readings and no hardware.

1. Connect to the glove with CoreBluetooth

Add NSBluetoothAlwaysUsageDescription to your Info.plist, then create a central manager that scans only for your glove's service, which saves battery and avoids unrelated devices.

swift
import CoreBluetooth

final class GloveConnection: NSObject, ObservableObject {
    private var central: CBCentralManager!
    private var glove: CBPeripheral?

    private let serviceUUID = CBUUID(string: "FFE0")          // replace with your module's UUID
    private let distanceUUID = CBUUID(string: "FFE1")         // replace with your characteristic

    var onDistance: ((Int) -> Void)?                          // centimetres

    override init() {
        super.init()
        central = CBCentralManager(delegate: self, queue: nil)
    }
}

extension GloveConnection: CBCentralManagerDelegate {
    func centralManagerDidUpdateState(_ central: CBCentralManager) {
        guard central.state == .poweredOn else { return }
        central.scanForPeripherals(withServices: [serviceUUID])
    }

    func centralManager(_ central: CBCentralManager,
                        didDiscover peripheral: CBPeripheral,
                        advertisementData: [String: Any], rssi RSSI: NSNumber) {
        glove = peripheral
        central.stopScan()
        central.connect(peripheral)
    }

    func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
        peripheral.delegate = self
        peripheral.discoverServices([serviceUUID])
    }

    func centralManager(_ central: CBCentralManager,
                        didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) {
        central.connect(peripheral)                           // reconnect automatically
    }
}
Enter fullscreen mode Exit fullscreen mode

The last method matters more than it looks. A wearable will drop its connection when the user moves, so reconnect automatically. If the app waits for a button tap, a blind user cannot fix it.

2. Subscribe to distance readings

Once connected, find the characteristic and turn on notifications so the glove pushes new values instead of the app polling.

swift
extension GloveConnection: CBPeripheralDelegate {
    func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
        peripheral.services?.forEach {
            peripheral.discoverCharacteristics([distanceUUID], for: $0)
        }
    }

    func peripheral(_ peripheral: CBPeripheral,
                    didDiscoverCharacteristicsFor service: CBService, error: Error?) {
        service.characteristics?.forEach {
            if $0.uuid == distanceUUID { peripheral.setNotifyValue(true, for: $0) }
        }
    }

    func peripheral(_ peripheral: CBPeripheral,
                    didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
        guard let data = characteristic.value, data.count >= 2 else { return }
        let cm = Int(data[0]) | (Int(data[1]) << 8)           // two bytes, little-endian
        DispatchQueue.main.async { self.onDistance?(cm) }
    }
}
Enter fullscreen mode Exit fullscreen mode

Agree the data format with your hardware side early. I lost time debugging "wrong" distances that were simply a byte-order mismatch.

3. Turn distance into guidance

Raw numbers are useless to a person walking. The app needs to map distance to something meaningful, and to avoid talking constantly.

swift
enum Proximity {
    case clear, near, close, danger

    init(cm: Int) {
        switch cm {
        case ..<40:  self = .danger
        case ..<100: self = .close
        case ..<200: self = .near
        default:     self = .clear
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

The most important design decision was to react only when the zone changes, not on every reading. Sensors send many readings per second, and speaking each one would turn into noise. A short cooldown prevents the app from repeating itself.

swift
final class FeedbackEngine {
    private let speech = AVSpeechSynthesizer()
    private var lastZone: Proximity = .clear
    private var lastSpoken = Date.distantPast

    func update(cm: Int) {
        let zone = Proximity(cm: cm)
        guard zone != lastZone else { return }
        lastZone = zone

        speak(for: zone)
        vibrate(for: zone)
    }

    private func speak(for zone: Proximity) {
        guard Date().timeIntervalSince(lastSpoken) > 1.0 else { return }
        lastSpoken = Date()
        let text: String? = {
            switch zone {
            case .danger: return "Stop. Obstacle very close."
            case .close:  return "Obstacle ahead."
            case .near:   return "Object nearby."
            case .clear:  return nil
            }
        }()
        guard let text else { return }
        let utterance = AVSpeechUtterance(string: text)
        utterance.rate = 0.5
        speech.stopSpeaking(at: .immediate)                   // newest warning wins
        speech.speak(utterance)
    }
}
Enter fullscreen mode Exit fullscreen mode

Calling stopSpeaking(at: .immediate) before each new warning means a user never hears an outdated message queued behind a new one.

4. Add haptics

Speech is slow, and in a noisy street it may not be heard. Vibration gives instant feedback, so I use it alongside speech, with stronger patterns for closer obstacles.

swift
import CoreHaptics

extension FeedbackEngine {
    func vibrate(for zone: Proximity) {
        let style: UIImpactFeedbackGenerator.FeedbackStyle = {
            switch zone {
            case .danger: return .heavy
            case .close:  return .medium
            case .near:   return .light
            case .clear:  return .soft
            }
        }()
        UIImpactFeedbackGenerator(style: style).impactOccurred()
    }
}
Enter fullscreen mode Exit fullscreen mode

For a richer feel you can use CHHapticEngine to build repeating patterns that speed up as the obstacle gets closer, like a parking sensor.

5. Make it work with the screen off

An assistive tool that stops when the phone locks is useless. Enable the Uses Bluetooth LE accessories background mode, and keep audio active so speech can continue. Test this early, since background behavior is where most BLE apps fail.

6. Test without hardware

I added a debug mode that feeds the feedback engine fake readings, such as a sequence that goes from 250 cm down to 20 cm. That let me tune the thresholds, wording and haptic strength at a desk, then confirm them on the real glove.

What I learned

Separate layers. Bluetooth, logic and feedback should not know about each other.
Fewer messages are better. Reacting only to changes made the product usable.
Design for reconnection. Wearables disconnect, so recovery must be automatic.
Use more than one sense. Speech plus haptics works better than either alone.
Accessibility is a design problem first. The code is simple. Deciding what to say and when is the hard part.

The full source is on GitHub.

I'm Raaju Pahlowan, an iOS developer in Dhaka, Bangladesh, working with Swift, SwiftUI and UIKit. You can see my projects at raajupahlowan.github.io and connect with me on LinkedIn.

Top comments (0)