Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Talk:Windows Phone 8 communicating with Arduino using Bluetooth

From Wiki
Jump to: navigation, search


Influencer - Very interesting

Hi mfabiop,

very interesting. I'm currently working on a small home automation project with the Raspberry Pi involving temperature control and heating of a pond and am planning to write on the WP8 side here later. Regarding your article, I got some open points:

  • A section on what exactly the example is expected to do should precede the code.
  • Regarding the hardware schema, I'm missing a parts list.
  • How are your commands built?

Maybe you can clarify these points...



influencer 18:13, 18 March 2013 (EET)

Mfabiop -

Hi Thomas,

Thanks for your comment, it's very appreciated.

- The example is really simple. It does'nt do anything specific; Just turn on/off leds and detect the presence of someone. But I'll try to clarify what it is expected to do. - A command consist of one byte to define the command size (what limits the command to 255 bytes) and the command as string just after the command size. I'll put this on the article.

Thanks again,

Marcos Fábio

mfabiop 18:25, 18 March 2013 (EET)

Influencer - Man - that was quick!


influencer 19:03, 18 March 2013 (EET)

Mfabiop - I was at work and my e-mail was opened :)

Hi Thomas,

Your home automation project looks interest, I'm waiting for see it.

Thanks again for your comments! They really improved the article. And thanks to kiran10182 too, he did a lot of good fixes.

mfabiop 16:59, 19 March 2013 (EET)

Kiran10182 - Thanks for the "thanks" !

Hi Marcos,

Thanks for writing this article and making this Wiki more rich. By the way, I am your friendly Wiki moderator who fixes some minor details to make the articles look more elegant. :)

Thanks for the appreciation.

- Kiran

kiran10182 21:19, 19 March 2013 (EET)

Chintandave er - Thanks and great article.

Hi Marcos,

First thanks for writing this great article. I like your article. You can explore more by working on this topic in other functionality.


- Chintan.

Chintandave er 13:00, 21 March 2013 (EET)

Mfabiop - Thanks

Hi Chintan,

Thanks for the compliment!

- Marcos.

mfabiop 00:49, 22 March 2013 (EET)

Lanceseidman - No Data Received

I actually made a few Open projects for Arduino as well and on GitHub but seems when I try your project, the Arduino doesn't send or its not being received by the Phone.

Unsure why.

lanceseidman 01:45, 25 March 2013 (EET)

Mfabiop - More information

Hi Lanceseidman,

I need more information to help you. Please, answer these questions:

1) Is the another direction working? i.e: From Windows Phone to Arduino. 2) Could you show me the Arduino code that send messages to WP8? 3) Before send messages from Arduino to WP8, are you calling the Connect method of the ConnectionManager class in the WP8 application?


- Marcos.

mfabiop 04:46, 25 March 2013 (EET)

Lanceseidman - Both Projects

Hi Marcos,

I am actually using both of your projects "AS IS". I haven't modified any of the code.

I am able to successfully connect to the the Device just when I select "Red" or any color, nothing is received from the Arduino, it continues to say No body detected.

Any ideas?



lanceseidman 07:36, 2 April 2013 (EEST)

Mfabiop -

Hi Lance,

This text only changes from "No Body detected" to "Intruder detected" if something is detected by the proximity sensor that is connected to the Arduino.



mfabiop 13:08, 2 April 2013 (EEST)

Bintk - NFC

Hello i am looking for article explains how to communicate with an Arduino board using Windows Phone 8 through NFC . I have Arduino Uno and NFC Shield and Relay module .


bintk 14:56, 10 April 2013 (EEST)

Mfabiop - Great idea!

Hi Bintk,

I've thought about NFC too. Mainly to auto-pairing or detect if the user is at home, but i don't have this NFC shield, so I'm not able to do this right now. I've just bought a relay module and I'm waiting for shipment.

How are you doing this? What Lumia devices are you using?


mfabiop 18:25, 10 April 2013 (EEST)

Bintk - NFC

I did not do it until now correctly, but I Make a trials since 3 days And I hope finish soon

I have nokia Lumia 820/620

I hope you will being this exciting trial soon

bintk 10:35, 11 April 2013 (EEST)

Aady - Great idea & article

Amazing concept !!! Keep ideating !!!



Aady 07:32, 13 April 2013 (EEST)

Mfabiop - Wrong image fixed

I've just made a small fix in the schematic image.

In the schematic figure the proximity sensor has plugged in pin 2, but in the Arduino code it is plugged in pin 3. Sorry for that.


mfabiop 02:41, 26 April 2013 (EEST)

Bintk - WP8 & Arduino Uno communicating Problem

bintk 12:41, 10 May 2013 (EEST)

Karmakargopal - How to port the Windows Phone 8 ccore code

Hi everyone,

I have visual studio 2010 installed in my system. So couldn't run the source code you have provided. But I have NOKIA LUMIA 520 model which runs Windows 8. How do i port/flash the Windows Phone code in my phone and get started with Arduino. I have all the hardware setup ready. Thanks in advance for your co-operation.

karmakargopal 20:44, 28 June 2013 (EEST)

Influencer - U need 2012

Hi Karmakargopal, you need VS2012 to develop for windows phone 8. If you want to run the emulator, you need a CPU capable of SLAT. That is only supported by newer models, my 2009 notebook doesn't work. But you can debug on the device. Hth


influencer 20:48, 28 June 2013 (EEST)

Deesymtc - Sending Text Messages from WP8

Hi, I have a Nokia Lumia 820 dev unlocked through which i am trying to exchange Text Messages to and fro a Windows 8 PC. Sending the Text Message is easy but while receiving i used the above code and am unable to make it work, Can someone please explain to me how exactly the sendMessage code works for the Windows Phone 8.

Thanks in Advance !

deesymtc (talk) 09:22, 7 August 2013 (EEST)

Mfabiop - Windows 8 PC?

Hi Deesymtc,

How exactly are you using the above code? The article is about the communication between a Windows Phone 8 device and an Arduino board.


mfabiop (talk) 14:28, 7 August 2013 (EEST)

Deesymtc - Re:Sending Text Messages from WP8

On the Windows 8 PC side i am using Winsock and on WP8 side i am using the Bluetooth API, namely peerfinder and then using a stream socket to establish a connection.

I am able to send String messages from the phone but i dont know how to send a message from the PC to the Phone-so in this part i tried using the code which you used to receive messages from arduino but i was unable to get it working.

deesymtc (talk) 08:22, 8 August 2013 (EEST)

Yasasri - Receive integer value in Windows Phone

I want to receive a integer value set via my windows Phone 8 App. My Arduino code is as follows

int cnt = 0; // Counter

void setup() {
  Serial.begin(9600);   // Initialization

void loop() {
  Serial.println(cnt);    // print counter
  delay(1000);   // wait 1 sec

How to write a simple WP8 code to receive these values via Bluetooth .

yasasri (talk) 21:11, 11 August 2013 (EEST)

Mfabiop - Yasasri

Hi Yasasri,

First of all, sorry for late response.

I'm going to do some tests and report to you as soon as possible. Feel free to send me a private message to the Forum Nokia discussion board. I always receive notification e-mails from there.


mfabiop (talk) 22:56, 23 August 2013 (EEST)

Lanceseidman - Re: Yasasri - Receive integer value in Windows Phone

Your problem is you're not setting up nor listening to a Bluetooth Module (RX/TX) on the Arduino PIN's.

Once you're listening in on the RX/TX of your Module, then establish a connection to the Module to set it up, each BT Module is different and some vary on the actual speeds.

If you visit: I have 2 projects that show the WP8 Code & Arduino code. A video of it on YouTube exists for both the RC Car/Motion Controller & basic WP8 to Arduino via Bluetooth at

More important, nothing will work without obtaining a Bluetooth Module for your Arduino, I use the Blue SMuRF Silver.

But remember, once you have an established connection, in your loop make sure to see if the Bluetooth/Serial is established and write your code within it then all you need to do is BT_Name.print("content"); and listen for incoming in your WP App.

- Lance

lanceseidman (talk) 00:12, 24 August 2013 (EEST)

Mfabiop - Re: Lanceseidman

Hi Yasasri,

Lanceseidman noticed well. Are you configuring the RX/TX bluetooth module as the article says? I thought that this wasn't your complete code and the Arduino RX/TX module configuration had been omitted.

Is it right?


mfabiop (talk) 04:46, 25 August 2013 (EEST)

Yasasri - Dear Mfabiop and Lance

Of cause I am using a Bluetooth module and only difference with my above code is I am not using your method " #include <SoftwareSerial.h> " to send the data via Bluetooth since it is possible in other ways.

I haven't configured any RX/TX as well since I don't have to. I plug the RX/TX of my Bluetooth module(HC-06 Bluetooth Module) to 0 and 1 the original RX/TX pins in the Arduino Mega board. So you do not want any library. The data that you send via serial port to the serial monitor can be intersected by the Bluetooth module and send them to my phone. This thing is working and when I send a value it receives to the mobile device. The problem is the values received are received partially for example 83 is received as 8. I don't know how to receive the data via Windows Phone the code that I am using to get the data is given below. I think the problem is with the encoding since I am sending an int value and the data taken are taken are converted into UTF8.

               byte[] bytes = new byte[5];
               await socket.InputStream.ReadAsync(bytes.AsBuffer(), 5, InputStreamOptions.Partial);
               bytes = bytes.TakeWhile((v, index) => bytes.Skip(index).Any(w => w != 0x00)).ToArray();
               string str = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
Please reply if you have tried sending a integer value set dynamically over time and if it does work and correct values are received. I will contact you via sending a private message to discuss the matter more deeply. Thanks .

yasasri (talk) 07:32, 25 August 2013 (EEST)

Mfabiop - Ok

Now i'm understanding.

I didn't try to send int values, but I guess that the problem is happening because you're sending the int as a string (Using the Serial.println). You can confirm this printing the return of 'Serial.println(cnt);' call in Arduino board.

If the value is sent as int the println function should returns 4, but if the value is sent as string the println function should returns the number of characters (2 for '83', 1 for '8', 3 for '832', etc...) .

I guess that the better option is:

Send the integer as it is, a integer. Use the Serial.write function to do this. Something like this.

int cnt = 12;
byte[] intToSend = new byte[4];
intToSend[0] = (cnt);
intToSend[1] = (cnt >> 8);
intToSend[2] = (cnt >> 16);
intToSend[3] = (cnt >> 24);
Serial.write(intToSend, 4);

In the Windows Phone side you can get the 4 bytes and re-create the integer value using a similar shift operation.

PS: Don't worry about the shift operation, it's really fast.

PS2: If your cnt value is always lower than 255, think about send it as a byte. This make the code really simpler.

mfabiop (talk) 01:45, 26 August 2013 (EEST)

Thouzie - Background

Hi Mfabiop!

great article!

Is it possible to keep this connection running in the background?


Thouzie (talk) 17:20, 2 October 2013 (EEST)

Mfabiop - Re: Background

Hi Thouzie,


In my tests to keep the Bluetooth connection opened in background, the Bluetooth connection was kept active, but no message was received by the WP8 application. Some time after, the JY-MCU module is desconnected. :(

I guess it is happening because the WP8 apps lifecyle.

A possibility is to create a background task to connect and request the pending Bluetooth messages from Arduino. Of course, you'll have to create a message list in Arduino that will be delivered when the WP8 application request it.

PS: The background task for WP8 executes each 15 minutes.


mfabiop (talk) 22:05, 2 October 2013 (EEST)

Sky Net - C# Windows Phone Code

Hello everybody,

Everything works perfect, but I have a little issue. In C# code, there is an async method called "ReceiveMessages". This method reads only the characters indicated by the first byte received on Input-Buffer, but what if I need to read all the characters available without sending the number of bytes to read at the beginning. How can I do that?

Thanks for your help guys.


Sky_Net (talk) 06:02, 3 December 2013 (EET)

Mfabiop - Re: Sky Net

Hi Sky Net,

You can use a terminator character and receive the message until this character is read. The implementation will change a little bit, but not so much.


mfabiop (talk) 20:15, 3 December 2013 (EET)

Sky Net - Sky Net - C# Windows Phone Code

Hello Mfabiop,

Thank you very much, I'm using a terminator character and that works great!.


Sky_Net (talk) 21:29, 4 December 2013 (EET)

Mfabiop - JY-MCU not working anymore

Hi Sky Net,

Are you still able to connect to the JY_MCU module using Windows Phone 8. I'm asking it because I can't connect it anymore.

Even if I try to connect using the Configuration menu option in Windows Phone 8. It doesn't work. The JY-MCU never stop to blink.

Another guy also got this same issue.


mfabiop (talk) 01:16, 27 February 2014 (EET)

Degr8sid - Arduino to Windows Phone 8 Emulator

Hi! I found your tutorial to be very helpful but I wanted to ask whether is this code for Windows Phone 8 device or emulator? I mean, I dont own windows Phone and I test every app on emulator. So is there anyway we can create communication between emulator and arduino? Even if it's simple LED ON/OFF program?

Mfabiop - Res: Emulator

Hi Degr8sid,

Unfortunately, the code does not work on emulator.

mfabiop (talk) 20:57, 13 August 2014 (EEST)