# Build a Bluetooth App using Swift 5

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/099/670/medium800thumb/breakout_boards_ezgif.com-optimize.jpg?1613755965)

This guide will show you the basics of developing your own Bluetooth Low Energy (BLE) app using the **Core Bluetooth Framework** in&nbsp;Xcode.&nbsp;

You'll need a basic understanding of Swift, but no prior experience with&nbsp;Bluetooth Low Energy is required. The example code provided in this guide can be applied to both iPhone and iPad users running the current version of iOS.

**Note:** We don't have equivalent code for Android users, sorry about that!

For this guide I'll be using the [Adafruit Feather 32u4 Bluefruit LE](https://www.adafruit.com/product/2829) to send&nbsp;and receive data.

Before you begin, know that the **Simulator** in Xcode isn't capable of using Bluetooth LE services. You'll need to follow along using an iPhone or iPad running the most current version of iOS **(Version 14+).**

Since you'll need to test your app using an iOS device, you'll also need an **Apple Developer membership** (please note that **free membership**  **enrollment** is fine for following along with this guide) **.&nbsp;** If you need help getting started as an iOS developer, check out the Adafruit guide covering how to enroll to the **Apple Developer program** and gain membership:

- [Introduction to iOS Development](../../../introduction-to-ios-development/how-to-launch-your-app-on-your-ios-device?view=all)

## Before starting...

- Install Xcode. [Click here to download Xcode from the Apple App Store.](https://apps.apple.com/us/app/xcode/id497799835?mt=12)
- Make sure your&nbsp;version of Xcode is up to date. I'm using Xcode **Version 12.4** &nbsp;at the time of making this guide.
- While in Xcode make sure the **Development Target** is **14.0 or higher.**
- Download the **Arduino IDE** from the main website [here](https://www.arduino.cc/en/Main/Software) if you haven't already.

## Parts

You don't need much to start this project, but you'll need these:

### Adafruit Feather 32u4 Bluefruit LE

[Adafruit Feather 32u4 Bluefruit LE](https://www.adafruit.com/product/2829)
Feather is the new development board from Adafruit, and like its namesake it is thin, light, and lets you fly! We designed Feather to be a new standard for portable microcontroller cores.

This is the&nbsp; **Adafruit Feather 32u4 Bluefruit** &nbsp;- our take on an...

In Stock
[Buy Now](https://www.adafruit.com/product/2829)
[Related Guides to the Product](https://learn.adafruit.com/products/2829/guides)
![Angled shot of rectangular microcontroller.](https://cdn-shop.adafruit.com/640x480/2829-16.jpg)

### Or
### Adafruit Feather M0 Bluefruit LE

[Adafruit Feather M0 Bluefruit LE](https://www.adafruit.com/product/2995)
Feather is the new development board from Adafruit, and like its namesake, it is thin, light, and lets you fly! We designed Feather to be a new standard for portable microcontroller cores.

This is the&nbsp; **Adafruit Feather M0 Bluefruit LE** &nbsp;- our take on an...

In Stock
[Buy Now](https://www.adafruit.com/product/2995)
[Related Guides to the Product](https://learn.adafruit.com/products/2995/guides)
![Angled Shot of the Adafruit Feather M0 Bluefruit LE.](https://cdn-shop.adafruit.com/640x480/2995-08.jpg)

### And
### USB cable - USB A to Micro-B

[USB cable - USB A to Micro-B](https://www.adafruit.com/product/592)
This here is your standard A to micro-B USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your Metro, Feather, Raspberry Pi or other dev-board or microcontroller

Approximately 3 feet / 1 meter long

In Stock
[Buy Now](https://www.adafruit.com/product/592)
[Related Guides to the Product](https://learn.adafruit.com/products/592/guides)
![USB cable - USB A to Micro-B - 3 foot long](https://cdn-shop.adafruit.com/640x480/592-01.jpg)

# Build a Bluetooth App using Swift 5

## Code

## Download project from Github

To best visualize how things work, I recommend that you should follow along with the app provided in this guide. The **Basic Chat** app sends and receives data using the **Feather Bluefruit's UART** connection. You can learn more about UARTs [here](https://en.wikipedia.org/wiki/Universal_asynchronous_receiver%2Ftransmitter).

Go&nbsp;to the [download page](https://github.com/adafruit/Basic-Chat) for the project. Once on the page, click on the **"Clone or download"** button.

![](https://cdn-learn.adafruit.com/assets/assets/000/099/657/medium800/breakout_boards_Screen_Shot_2021-02-18_at_9.44.24_PM.png?1613702704)

Once the file is downloaded, click on the **Basic Chat MVC.xcodeproj** app and it will open up the project in **Xcode**.

![](https://cdn-learn.adafruit.com/assets/assets/000/099/658/medium800/breakout_boards_Screen_Shot_2021-02-18_at_9.47.37_PM.png?1613702878)

Once we have the project open, select your iOS device's **scheme** &nbsp;in **Xcode**.

![](https://cdn-learn.adafruit.com/assets/assets/000/099/659/medium800/breakout_boards_Screen_Shot_2021-02-18_at_9.48.42_PM.png?1613703043)

Now just press the **Run** button to test the app on your iOS device.

![](https://cdn-learn.adafruit.com/assets/assets/000/042/449/medium800/feather_www.png?1497018697)

If all goes well, the&nbsp; **Basic Chat MVC** &nbsp;app will run on your iOS device and you'll be able to use the app as a reference while you explore the guide.

Info: 

## Understanding Core Bluetooth

The **Core Bluetooth** framework provides the classes needed for your apps to communicate with Bluetooth-equipped low energy (LE) and Basic Rate / Enhanced Data Rate (BR/EDR) wireless technology.

We need the **CBCentralManager** &nbsp;object that scans for, discovers, connects to, and manages peripherals. We'll also need the **CBPeripheral** object&nbsp;that&nbsp;represents remote peripheral devices that your app discovers with a central manager.

A **CBPeripheral** is used&nbsp;to discover, explore, and interact with the services available on a remote peripheral that supports Bluetooth low energy.

A **service** encapsulates the way part of the device behaves. For example, one service of a heart rate monitor may be to expose heart rate data from a sensor.

Services themselves contain of **characteristics** or included services (references to other services).

**Characteristics** provide further details about a peripheral’s **service**. For example, the heart rate service may contain multiple characteristics.

The following diagram shows the hierarchy of the **CBPeripheral** :

![](https://cdn-learn.adafruit.com/assets/assets/000/043/479/medium800/feather_CB-diagram.jpg?1499199263)

## Getting Started

Before starting to code, you need to create a prompt that asks for permission to use the device's Bluetooth.&nbsp;

In your file hierarchy on the left, locate **Info.plist.**

![](https://cdn-learn.adafruit.com/assets/assets/000/099/662/medium800/breakout_boards_Screen_Shot_2021-02-18_at_10.33.13_PM.png?1613705605)

Add these to your info.plist:

• Privacy - Bluetooth Peripheral Usage Description

• Privacy - Bluetooth Always Usage Description

Add a description you see fit.

![](https://cdn-learn.adafruit.com/assets/assets/000/099/661/medium800/breakout_boards_Screen_Shot_2021-02-18_at_10.21.15_PM.png?1613704897)

In this case, a message&nbsp;tells the user why the app is requesting the ability to connect to Bluetooth peripherals.&nbsp;

Now, to look at some code.

In your project's file hierarchy, locate " **ViewController.swift**". This file handles the majority of the tasks which need to be performed to connect to a Bluetooth device.

![](https://cdn-learn.adafruit.com/assets/assets/000/099/660/medium800/breakout_boards_Screen_Shot_2021-02-18_at_10.08.42_PM.png?1613704185)

At the top of the file, import CoreBluetooth:

```auto
import CoreBluetooth
```

This line adds **Core Bluetooth framework** to the project and **&nbsp;** gives the ability to communicate with Bluetooth devices.

Now create variable to store your central manager. The central manager&nbsp;manages discovered or connected remote peripheral devices (represented by CBPeripheral objects), including scanning for, discovering, and connecting to advertising peripherals.

```python
var centralManager: CBCentralManager!
```

Then in your viewDidLoad, initialize the central manager by setting the delegate to `self`, otherwise the central state never changes on startup.

```python
override func viewDidLoad() {
   super.viewDidLoad()
   centralManager = CBCentralManager(delegate: self, queue: nil)
 }
```

Now add a **CBCentralManagerDelegate** protocol to the **ViewController** in order to scan, discover and connect a peripheral.

The **CBCentralManagerDelegate&nbsp;** protocol defines the methods that a delegate of a CBCentralManager object must adopt.

```python
extension ViewController: CBCentralManagerDelegate {

  func centralManagerDidUpdateState(_ central: CBCentralManager) {
    
     switch central.state {
          case .poweredOff:
              print("Is Powered Off.")
          case .poweredOn:
              print("Is Powered On.")
              startScanning()
          case .unsupported:
              print("Is Unsupported.")
          case .unauthorized:
          print("Is Unauthorized.")
          case .unknown:
              print("Unknown")
          case .resetting:
              print("Resetting")
          @unknown default:
            print("Error")
          }
  }

}
```

The only&nbsp;method&nbsp;required for&nbsp; **CBCentralManagerDelegate** &nbsp;would be&nbsp;centralManagerDidUpdateState(\_:); the central manager calls this when its state updates, thereby indicating the availability of the central manager.

This required method is added to ensure that the central device (your iPhone or iPad) supports Bluetooth low energy and that it’s available to use.&nbsp;

Also add a CBPeripheralDelegate protocol. The CBPeripheralDelegate provides updates on the use of a peripheral’s services. This will be needed later.

```python
extension ViewController: CBPeripheralDelegate {
}
```

Before going any farther, you need to store a list of unique identifiers to help look for specific Bluetooth devices. Create a new file called CBUUIDs that stores the unique identifiers.

```python
import Foundation
import CoreBluetooth

struct CBUUIDs{

    static let kBLEService_UUID = "6e400001-b5a3-f393-e0a9-e50e24dcca9e"
    static let kBLE_Characteristic_uuid_Tx = "6e400002-b5a3-f393-e0a9-e50e24dcca9e"
    static let kBLE_Characteristic_uuid_Rx = "6e400003-b5a3-f393-e0a9-e50e24dcca9e"

    static let BLEService_UUID = CBUUID(string: kBLEService_UUID)
    static let BLE_Characteristic_uuid_Tx = CBUUID(string: kBLE_Characteristic_uuid_Tx)//(Property = Write without response)
    static let BLE_Characteristic_uuid_Rx = CBUUID(string: kBLE_Characteristic_uuid_Rx)// (Property = Read/Notify)

}
```

CBUUID class represents universally unique identifiers (UUIDs) of attributes used in Bluetooth low energy communication, such as a peripheral’s services, characteristics, and descriptors.

By specifying what service to looking for, you tell the **CBCentralManager** to ignore all peripherals which don't advertise that specific service, and return a list of **only** the peripherals that offer this service.

Now to head back into the ViewController to start scanning for peripherals.

# Build a Bluetooth App using Swift 5

## Scanning for Peripherals

## Scanning for Peripherals

Once the CBCentralManager is up and powered on, you can create a function that scan for peripherals around us.

Create a function called `startScanning`. Call the method `scanForPeripherals(withServices:)`.

This method scans for peripherals that are advertising services. Now since the unique identifier is set up, add that reference to the method.

```python
func startScanning() -> Void {
  // Start Scanning
  centralManager?.scanForPeripherals(withServices: [CBUUIDs.BLEService_UUID])
}
```

Now add the `startScanning()` function to the `centralManagerDidUpdateState` to scan as soon as the app opens.

```python
extension ViewController: CBCentralManagerDelegate {

  func centralManagerDidUpdateState(_ central: CBCentralManager) {
    
     switch central.state {
          case .poweredOff:
              print("Is Powered Off.")
          case .poweredOn:
              print("Is Powered On.")
              startScanning()
          case .unsupported:
              print("Is Unsupported.")
          case .unauthorized:
          print("Is Unauthorized.")
          case .unknown:
              print("Unknown")
          case .resetting:
              print("Resetting")
          @unknown default:
            print("Error")
          }
  }

}
```

When you run your app, your device will start scanning for peripherals.

## Discovering Peripherals

Now that scanning is started, what happens when a peripheral is discovered?

Every time a peripheral is discovered, the&nbsp; **CBCentralManager** will notify you by calling the `centralManager(_:didDiscover:advertisementData:rssi:)` function on its delegate.

This function&nbsp;provides the following&nbsp;information about the newly discovered peripheral:

- The discovered peripheral is recognized and can be stored as a **CBPeripheral.**
- The discovered peripheral has stored advertisement data.
- The current received signal strength indicator ( **RSSI** ) of the peripheral, in decibels.

Since you are interested in connecting to one peripheral, create an instance of a peripheral.

```python
private var bluefruitPeripheral: CBPeripheral!
```

Call the didDiscover function. This tells the delegate the central manager discovered a peripheral while scanning for devices.

```python
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral,advertisementData: [String : Any], rssi RSSI: NSNumber) {

    bluefruitPeripheral = peripheral

    bluefruitPeripheral.delegate = self

    print("Peripheral Discovered: \(peripheral)")
  	print("Peripheral name: \(peripheral.name)")
    print ("Advertisement Data : \(advertisementData)")
        
    centralManager?.stopScan()
   }
```

The implementation of this function performs the following actions:

- Set the&nbsp;`bluefruitPeripheral` variable to the new peripheral found.
- Set the peripheral's **delegate** to self ( **ViewController** )
- Printed the newly discovered peripheral's information in the console.
- Stopped scanning for peripherals.

Next up - actually connect to that peripheral.

# Build a Bluetooth App using Swift 5

## Connecting to a Peripheral

To connect to a peripheral, use this method to establish a local connection to the desired peripheral.&nbsp;

```python
centralManager?.connect(blePeripheral!, options: nil)
```

Add this to the `didDiscover`&nbsp;function.

```python
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral,advertisementData: [String : Any], rssi RSSI: NSNumber) {

    bluefruitPeripheral = peripheral
    bluefruitPeripheral.delegate = self

    print("Peripheral Discovered: \(peripheral)")
  	print("Peripheral name: \(peripheral.name)")
    print ("Advertisement Data : \(advertisementData)")
    
    centralManager?.connect(bluefruitPeripheral!, options: nil)

   }
```

Once&nbsp;the connection is made, the central manager calls the&nbsp;`centralManager(_:didConnect)`&nbsp;delegate function to provide&nbsp;incoming information about&nbsp;the newly connected peripheral.

Once this function is called, you'll discover a service that the peripheral is holding.

```python
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
   bluefruitPeripheral.discoverServices([CBUUIDs.BLEService_UUID])
}
```

Finishing the discovering services, you'll get a `didDiscoverServices` event. Iterate through all the "available" services.

## Discovering Services

Now that the peripheral's services are successfully discovered, the central manager will call the&nbsp;`didDiscoverServices()`&nbsp;delegate function.&nbsp;`didDiscoverService()` handles and filters services, so that you can use whichever service you are interested in right away.

```python
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
        print("*******************************************************")

        if ((error) != nil) {
            print("Error discovering services: \(error!.localizedDescription)")
            return
        }
        guard let services = peripheral.services else {
            return
        }
        //We need to discover the all characteristic
        for service in services {
			peripheral.discoverCharacteristics(nil, for: service)
        }
        print("Discovered Services: \(services)")
    }
```

First, handle any possible errors returned by the central manager, then request characteristics for each service returned by calling `discoverCharacteristics(_:)`

## Discovering Characteristics

Create two characteristic variables to reference.

```python
private var txCharacteristic: CBCharacteristic!
private var rxCharacteristic: CBCharacteristic!
```

Now call the `discoverCharacteristics(_:)`&nbsp;function, the central manager will call the&nbsp;`didDiscoverCharacteristicsFor()`&nbsp;delegate function&nbsp;and provide the discovered characteristics of the specified service.&nbsp;

```python
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
       
           guard let characteristics = service.characteristics else {
          return
      }

      print("Found \(characteristics.count) characteristics.")

      for characteristic in characteristics {

        if characteristic.uuid.isEqual(CBUUIDs.BLE_Characteristic_uuid_Rx)  {

          rxCharacteristic = characteristic

          peripheral.setNotifyValue(true, for: rxCharacteristic!)
          peripheral.readValue(for: characteristic)

          print("RX Characteristic: \(rxCharacteristic.uuid)")
        }

        if characteristic.uuid.isEqual(CBUUIDs.BLE_Characteristic_uuid_Tx){
          
          txCharacteristic = characteristic
          
          print("TX Characteristic: \(txCharacteristic.uuid)")
        }
      }
}
```

A couple of things are happening in this function:&nbsp;

1. Handle errors and print characteristic info to the debug console
2. Look through the array of characteristics for a match to desired UUIDs.
3. Perform any necessary actions for the matching characteristics
4. Discover descriptors for each characteristic

In this case, the specific UUIDs we're looking for are stored in the&nbsp;`BLE_Characteristic_uuid_Rx`&nbsp;and `BLE_Characteristic_uuid_Tx` variables. &nbsp;

When it finds the RX characteristic, it subscribe to updates to its value by calling `setNotifyValue()` - this is how to receive data from the peripheral. Additionally, read the current value from the characteristic and print its information to the console.

When it finds the TX characteristic, it saves a reference to it to write values to it later - this is how to send data to the peripheral.

## Disconnecting from Peripheral

To disconnect or cancels an active or pending local connection to a peripheral, use the `.cancelPeripheralConnection` method.

```auto
func disconnectFromDevice () {
	if blePeripheral != nil {
	centralManager?.cancelPeripheralConnection(blePeripheral!)
    }
 }
```

This method is nonblocking, and any CBPeripheral class commands that are still pending to `peripheral` may not complete.

Because other apps may still have a connection to the peripheral, canceling a local connection doesn’t guarantee that the underlying physical link is immediately disconnected.

Now, that you've connected to our Bluetooth device, it's time to communicate send and receive data.

# Build a Bluetooth App using Swift 5

## Communication 

## Setting up communication&nbsp;

To start communicating with the Bluetooth device, you'll need to setup a protocol that provides updates for local peripheral state and interactions with remote central devices.

That protocol would be&nbsp; **CBPeripheralManagerDelegate** , so add an extension to the ViewController and add CBPeripheralManagerDelegate.

```python
extension ViewController: CBPeripheralManagerDelegate {

  func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {
    switch peripheral.state {
    case .poweredOn:
        print("Peripheral Is Powered On.")
    case .unsupported:
        print("Peripheral Is Unsupported.")
    case .unauthorized:
    print("Peripheral Is Unauthorized.")
    case .unknown:
        print("Peripheral Unknown")
    case .resetting:
        print("Peripheral Resetting")
    case .poweredOff:
      print("Peripheral Is Powered Off.")
    @unknown default:
      print("Error")
    }
  }
}
```

The protocol’s requires one method, `peripheralManagerDidUpdateState(_:)`, which Core Bluetooth calls whenever the peripheral manager’s state updates to indicate whether the peripheral manager is available.

## Reading the Value of a Characteristic

Since `peripheral.setNotifyValue` has been called previously in the `didDiscoverCharacteristicsFor` method, you are able to set notifications or indications for incoming values registered to the **rxcharacteristic**.

Once receiving incoming values from a Bluetooth device, Core Bluetooth invokes&nbsp;`didUpdateValueFor`&nbsp;to handle that incoming data.

```python
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {

      var characteristicASCIIValue = NSString()

      guard characteristic == rxCharacteristic,

      let characteristicValue = characteristic.value,
      let ASCIIstring = NSString(data: characteristicValue, encoding: String.Encoding.utf8.rawValue) else { return }

      characteristicASCIIValue = ASCIIstring

      print("Value Recieved: \((characteristicASCIIValue as String))")
}
```

In&nbsp;`didUpdateValueFor()`, first create an instance of `NSString`, that will be&nbsp; the `characteristicASCIIValue` variable to hold an incoming value, then convert it to an ASCII string, then print the converted ASCII value to the console.

## Writing to a Characteristic

Before writing data to an external peripheral, you need to know how we want to write that data.

There are two types of CBCharacteristic write types. The CBCharacteristic write type can be either `.withResponse` or `.withoutResponse`.

The `.withResponse` property type gets a&nbsp;response from the peripheral to indicate whether the write was successful. The `.withoutResponse` doesn't send any response back from the peripheral.

To write to a characteristic you’ll need to write a value with an instance of **NSData** and do that by calling&nbsp; `writeValue(for: , type: CBCharacteristicWriteType.withResponse)` method:

```python
bluefruitPeripheral.writeValue(data!, for: txCharacteristic, type: CBCharacteristicWriteType.withResponse)
```

Create a new function that will communicate with the Bluetooth device. I've called this function `writeOutgoingValue()`, but call it whatever you'd like.

First, format the outgoing string as **NSData.** Then, make sure `bluefruitPeripheral` and `txCharacteristic` variables are not set to `nil`. &nbsp;

Then add the `writeValue` method into your function.

```python
func writeOutgoingValue(data: String){
      
    let valueString = (data as NSString).data(using: String.Encoding.utf8.rawValue)
    
    if let bluefruitPeripheral = bluefruitPeripheral {
          
      if let txCharacteristic = txCharacteristic {
              
        bluefruitPeripheral.writeValue(valueString!, for: txCharacteristic, type: CBCharacteristicWriteType.withResponse)
          }
      }
  }
```

Awesome. Now that you've given the app the ability to communicate with a Bluetooth device, hook up the device to the Arduino IDE.

Ok, now to hook up some quick UI to test out the app.

In your file hierarchy located on the left, locate and go to Main.storyboard. Here, create a button that will trigger the function to transmit the data to the Bluetooth device.

![](https://cdn-learn.adafruit.com/assets/assets/000/099/684/medium800/breakout_boards_Screen_Shot_2021-02-22_at_12.28.07_AM.png?1613974273)

Above your navigation pane, select the "+" button to display a library of UI elements.

![](https://cdn-learn.adafruit.com/assets/assets/000/099/685/medium800/breakout_boards_Screen_Shot_2021-02-22_at_12.28.30_AM.png?1613974543)

Now that you've opened up the UI library, press and slide "Button" onto you View Controller.

![](https://cdn-learn.adafruit.com/assets/assets/000/099/686/medium800/breakout_boards_Screen_Shot_2021-02-22_at_12.28.53_AM.png?1613974723)

Ok, I gave my changed my button label to "Send Hello World", you can change it to your liking.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/099/688/medium800/breakout_boards_Screen_Shot_2021-02-22_at_1.19.08_AM.png?1613974949)

Now connect the UI to the code. Press this icon on the upper right corner of your Navigation Pane, and locate your **ViewController.swift** file.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/099/689/medium800/breakout_boards_Screen_Shot_2021-02-22_at_1.23.57_AM.png?1613975160)

Once you've done that, Control drag and drop the button to the **ViewController.swift** file. Instead if adding an Outlet, create an action and name it "buttonPress".&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/099/690/medium800/breakout_boards_Screen_Shot_2021-02-22_at_1.25.32_AM.png?1613975396)

Now head back into the **ourViewController.swift** file. Within the buttonPress method, add the `writeOutgoingValue()`&nbsp;method and add a string into the parameter. I've chosen to send "Hello Word".&nbsp;

```python
@IBAction func buttonPress(_ sender: Any) {
    writeOutgoingValue(data: "Hello World")
  }
```

Great! Now to set up communications on the Bluetooth device.

# Build a Bluetooth App using Swift 5

## Communicating with the Arduino IDE

## Sending Data

To demonstrate the functionality of the app using an [Adafruit Feather Bluefruit 32u4](https://www.adafruit.com/product/3379) board, connect it to a computer running the Arduino IDE. If you don't already have your Arduino IDE setup or if it's not recognizing your board, take a look at this learn guide on how to do so:

- [Adafruit Feather 32u4 Bluefruit LE Learn Guide](../../../../adafruit-feather-32u4-bluefruit-le/pinouts?view=all#setup)

You can use the serial monitor to read and write messages back and forth with the Basic Chat app.

Within the Arduino IDE, go to **File-\>Examples-\>Adafruit BluefruitLEnRF51&nbsp;** then select **bleart\_cmdmode**. &nbsp;Once the sketch is opened, **upload** it to your Feather and click on the **Serial Monitor** button in the upper right of the Arduino IDE window. &nbsp;A new serial monitor window will open.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/471/medium800/feather_new-450.jpg?1499197214)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/473/medium800/feather_serialcomm-450.jpg?1499197258)

This new serial monitor window is&nbsp;where you'll be able to communicate between your Bluetooth device&nbsp;and your **&nbsp;** app.

Open the app you've made and then hit your button.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/099/702/medium800/breakout_boards_blinka.png?1614097429)

When you tap the button, your message should pop up in the Arduino Serial monitor view.

![](https://cdn-learn.adafruit.com/assets/assets/000/099/693/medium800/breakout_boards_Screen_Shot_2021-02-22_at_2.26.07_AM.png?1613979419)

Now you've successfully sent the string "Hello World!" to the Feather and it displayed in the Serial monitor view.

Now to send "Hello Back" to your app. Type "Hello World!" in the text field of the Arduino IDE's serial monitor window and then hit **Send**.

![](https://cdn-learn.adafruit.com/assets/assets/000/099/694/medium800/breakout_boards_Screen_Shot_2021-02-22_at_2.30.31_AM.png?1613979771)

You should receive a "Hello Back" in the console.&nbsp;

# Congrats!

You've successfully demonstrated the Bluetooth app's functionality and learned the basics of BLE communication using&nbsp;CoreBluetooth. &nbsp;With this knowledge and the Basic Chat MVC app as a reference, you can start building even more complex Bluetooth apps!


## Featured Products

### Adafruit Feather 32u4 Bluefruit LE

[Adafruit Feather 32u4 Bluefruit LE](https://www.adafruit.com/product/2829)
Feather is the new development board from Adafruit, and like its namesake it is thin, light, and lets you fly! We designed Feather to be a new standard for portable microcontroller cores.

This is the&nbsp; **Adafruit Feather 32u4 Bluefruit** &nbsp;- our take on an...

In Stock
[Buy Now](https://www.adafruit.com/product/2829)
[Related Guides to the Product](https://learn.adafruit.com/products/2829/guides)
### Adafruit Feather M0 Bluefruit LE

[Adafruit Feather M0 Bluefruit LE](https://www.adafruit.com/product/2995)
Feather is the new development board from Adafruit, and like its namesake, it is thin, light, and lets you fly! We designed Feather to be a new standard for portable microcontroller cores.

This is the&nbsp; **Adafruit Feather M0 Bluefruit LE** &nbsp;- our take on an...

In Stock
[Buy Now](https://www.adafruit.com/product/2995)
[Related Guides to the Product](https://learn.adafruit.com/products/2995/guides)
### Adafruit Feather nRF52 Bluefruit LE

[Adafruit Feather nRF52 Bluefruit LE](https://www.adafruit.com/product/3406)
The **Adafruit Feather nRF52 Bluefruit** is another easy-to-use all-in-one Bluetooth® Low Energy board, with a native-Bluetooth® chip, the nRF52832!&nbsp; It's our take on an 'all-in-one' Arduino-compatible + Bluetooth® Low Energy with built in USB and...

In Stock
[Buy Now](https://www.adafruit.com/product/3406)
[Related Guides to the Product](https://learn.adafruit.com/products/3406/guides)
### Adafruit Bluefruit LE SPI Friend - Bluetooth® Low Energy

[Adafruit Bluefruit LE SPI Friend - Bluetooth® Low Energy](https://www.adafruit.com/product/2633)
Would you like to add powerful and easy-to-use Bluetooth® Low Energy to your robot, art or other electronics project? Heck yeah! With Bluetooth® Low Energy now included in modern smart phones and tablets, its fun to add wireless connectivity. So what you really need is the new Adafruit...

In Stock
[Buy Now](https://www.adafruit.com/product/2633)
[Related Guides to the Product](https://learn.adafruit.com/products/2633/guides)
### Adafruit Bluefruit LE UART Friend - Bluetooth® Low Energy

[Adafruit Bluefruit LE UART Friend - Bluetooth® Low Energy](https://www.adafruit.com/product/2479)
Would you like to add powerful&nbsp;and easy-to-use Bluetooth® Low Energy to your robot, art or other electronics project? Heck yeah! With Bluetooth® Low Energy now included in modern smart phones and tablets, its fun to add wireless connectivity. So what you really need is the new...

In Stock
[Buy Now](https://www.adafruit.com/product/2479)
[Related Guides to the Product](https://learn.adafruit.com/products/2479/guides)
### Flora Wearable Bluefruit LE Module

[Flora Wearable Bluefruit LE Module](https://www.adafruit.com/product/2487)
Would you like to add powerful and easy-to-use Bluetooth Low Energy to your wearable FLORA project? Heck yeah! With BLE now included in modern smart phones and tablets, its fun to add wireless connectivity. So what you really need is the new Adafruit Flora Bluefruit LE!

The Flora...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/2487)
[Related Guides to the Product](https://learn.adafruit.com/products/2487/guides)
### Bluefruit LE - Bluetooth® Low Energy 4.0

[Bluefruit LE - Bluetooth® Low Energy 4.0](https://www.adafruit.com/product/1697)
Our Adafruit Bluefruit LE (Bluetooth® Smart, Bluetooth® Low Energy, Bluetooth® 4.0) nRF8001 Breakout allows you to establish an easy to use wireless link between your Arduino and any compatible iOS or Android (4.3+) device. It works by simulating a UART device beneath the surface,...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/1697)
[Related Guides to the Product](https://learn.adafruit.com/products/1697/guides)

## Related Guides

- [Adafruit Feather M0 Bluefruit LE](https://learn.adafruit.com/adafruit-feather-m0-bluefruit-le.md)
- [Bluefruit nRF52 Feather Learning Guide](https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide.md)
- [Bluetooth Remote Control for the Lego Droid Developer Kit](https://learn.adafruit.com/bluetooth-remote-for-lego-droid.md)
- [Adafruit NeoPXL8 FeatherWing and Library](https://learn.adafruit.com/adafruit-neopxl8-featherwing-and-library.md)
- [3D Printed Case for Adafruit Feather](https://learn.adafruit.com/3d-printed-case-for-adafruit-feather.md)
- [AtariFruit 2600 Joystick](https://learn.adafruit.com/atarifruit-2600-joystick.md)
- [Using ATSAMD21 SERCOM for more SPI, I2C and Serial ports](https://learn.adafruit.com/using-atsamd21-sercom-to-add-more-spi-i2c-serial-ports.md)
- [Bluefruit Controlled Macetech RGB LED Shades](https://learn.adafruit.com/ledshades.md)
- [Motorized Camera Slider MK3 ](https://learn.adafruit.com/motorized-camera-slider-mk3.md)
- [Bluefruit LE Connect for iOS and Android](https://learn.adafruit.com/bluefruit-le-connect.md)
- [CircuitPython Hardware: Charlieplex LED Matrix](https://learn.adafruit.com/micropython-hardware-charlieplex-led-matrix.md)
- [Wireless UNTZtrument Using BLE MIDI ](https://learn.adafruit.com/wireless-untztrument-using-ble-midi.md)
- [My Mini Race Car](https://learn.adafruit.com/my-mini-race-car.md)
- [What is Web MIDI & BLE MIDI?](https://learn.adafruit.com/web-ble-midi.md)
- [Introducing the Adafruit Bluefruit LE SPI Friend](https://learn.adafruit.com/introducing-the-adafruit-bluefruit-spi-breakout.md)
