Bluetooth communication between Arduino and Windows 8.1


Bluetooth, arduino, Windows 8.1
Bluetooth, Bluetooth RF Comm
Windows RT
en-US
11/13/2014

Introduction

In this sample you can learn how to establish a serial Bluetooth link between an Arduino and a Windows 8.1 app.

Building the Sample

To test this, you need an Arduino with Bluetooth capabilities (for example an Arduino Uno R3 and a JY-MCU Bluetooth module) and a Windows 8.1 device with Bluetooth capabilities. (A Bluetooth dongle will do as well.)

The sample is provided as a Visual Studio 2013 solution that includes the Windows Store app code and the Arduino code. You can open the Arduino code with the default Arduino IDE.

This sample was inspired by and is based on the Windows Phone 8 implementation of Bluetooth/Arduino communication by Marcos Pereira. This BUILD talk by Ellick Sung and the related sample application were also helpful in porting the code to WinRT.

Description

Set up the Arduino with a Bluetooth module, two LEDs and a potentiometer, according to the following diagram:


Communication with the Bluetooth module is accomplished using the SoftwareSerial.h library.

The Windows 8.1 app has to declare Bluetooth serial communication capabilities in Package.appxmanifest:

 

XML
Edit|Remove
<Capabilities  <m2:DeviceCapability Name="bluetooth.rfcomm"    <m2:Device Id="any"      <m2:Function Type="name:serialPort" /> 
    </m2:Device> 
  </m2:DeviceCapability> 
</Capabilities>

To deploy the Arduino code with VisualMicro, right click the Project in the Solution Explorer and select Debug\Start new instance.

IMPORTANT: Before running the Windows App you need to "pair" your Bluetooth device with your computer. To do this, go to the "PC Settings" and select Devices/Bluetooth. Then select your Bluetooth device, enter the pin (try 1234 if you are not sure..) and the device will be paired. (You only have to do this once!)

When the Windows 8.1 app starts, you can establish a connection and control the LEDs, or subscribe to analog inputs as seen in the following video:

<object type="application/x-silverlight-2" width="350" height="300" data="data:application/x-silverlight-2,"> <param name="source" value="/Content/Common/videoplayer.xap" /> <param name="initParams" value="deferredLoad=false,duration=0,m=http://i1.code.msdn.s-msft.com/bluetooth-communication-7130c260/image/file/113904/1/bluetoothcommunicationsample.wmv,autostart=false,autohide=true,showembed=true" /> <param name="background" value="#00FFFFFF" /> <param name="minRuntimeVersion" value="3.0.40624.0" /> <param name="enableHtmlAccess" value="true" /> <param name="src" value="http://i1.code.msdn.s-msft.com/bluetooth-communication-7130c260/image/file/113904/1/bluetoothcommunicationsample.wmv" /> <param name="id" value="113904" /> <param name="name" value="BluetoothCommunicationSample.wmv" />Get Microsoft Silverlight </object>
 Download video

Youtube backup link

Source Code Files

More Information

For more information on this sample, see my blogpost about it.