Bluetooth communication between Arduino and Windows Phone 8.1

Wireless communication is very useful in many real time situations such as home automation systems, we can establish a wireless communication using Bluetooth, WIFI and Zigbee.
Bluetooth is very cheap and easily available so we first start with  Bluetooth. Please check my previous post to setup  Windows Remote Arduino with USB.
come lets play with Bluetooth

Parts we need

Hardware:
  1. Arduino Uno R3 board – 1
  2. Buletooth module HC-05 – 1
  3. Arduino USB connector - 1
  4. Light Emitting Diode (LED) –1
  5. Bread board- 1
Software:
  1. Windows 8.1OS
  2. Visual studio 2013

Set up a connection

The HC-05 bluetooth module come up with 6 pins, refer the below image.

HC-05Arduino_connections

  1. Connect VCC to 5V
  2. Connect GND to GND pin of Arduino
  3. Connect Bluetooth RX to Arduino TX pin 1
  4. Connect Bluetooth TX to Arduino RX pin 0
refer the below connection diagram.
circuit

Note:
  1. The standard firmata must be loaded in the arduino, check my previous post
  2. set the baud rate to 9600 in standard firmata as given below, the default baud rate of HC-05 is 9600
            Firmata.begin(9600); //you can find this line under Setup() function for standardFrimata

Paring the Bluetooth HC-05 to windows phone.

The HC-05 come up with default password “1234” and baud rate is 9600, once you are power up the Ardunio pair the Bluetooth device to windows phone using the password, check the below link to pair Bluetooth device to windows phone.
https://www.windowsphone.com/en-in/how-to/wp8/connectivity/pair-my-phone-with-a-bluetooth-accessory

Creating and Deploying the application:

Create a new Universal application in visual studio 2013, and add the following projects as reference.
remoteblinky
!Add the Bluetooth capabilities in “Package.appxmanifest”, for more details refer below link under “Device Capabilities”.
https://ms-iot.github.io/content/en-US/win10/SetupPCWRA.htm
Add the following code in “MainPage.Xaml.cs”.
[C#]
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Microsoft.Maker.Serial;
using Microsoft.Maker.RemoteWiring;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace RemoteBlinky
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        //Usb is not supported on Win8.1. To see the USB connection steps, refer to the win10 solution instead.
        BluetoothSerial bluetooth;
        RemoteDevice arduino;
        public MainPage()
        {
            this.InitializeComponent();
                /*
                 * I've written my bluetooth device name as a parameter to the BluetoothSerial constructor. You should change this to your previously-paired
                 * device name if using Bluetooth. You can also use the BluetoothSerial.listAvailableDevicesAsync() function to list
                 * available devices, but that is not covered in this sample.
                 */
                bluetooth = new BluetoothSerial( "HC-05" );
                arduino = new RemoteDevice( bluetooth );
                bluetooth.ConnectionEstablished += OnConnectionEstablished;
                //these parameters don't matter for bluetooth
                bluetooth.begin( 115200, SerialConfig.SERIAL_8N1 );
        }
        private void OnConnectionEstablished()
        {
            //enable the buttons on the UI thread!
            var action = Dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler( () => {
                OnButton.IsEnabled = true;
                OffButton.IsEnabled = true;
            }));
        }
        private void OnButton_Click( object sender, RoutedEventArgs e )
        {
            //turn the LED connected to pin 5 ON
            arduino.digitalWrite(5, PinState.HIGH );
        }
        private void OffButton_Click( object sender, RoutedEventArgs e )
        {
            //turn the LED connected to pin 5 OFF
            arduino.digitalWrite(5, PinState.LOW);
        }
    }
}
Build and deploy the application to the winodws Phone 8.1.
wp_ss_20150909_0001
Now you can control the LED from Windows phone application via Bluetooth. provide your feedback in comments
we will see in next experiment.
By
Praveen

Comments

Popular posts from this blog

ID card detection using Emgu and Tesseract OCR

I got my Ardunio