Aritro Mukherjee
Published © GPL3+

Build a Windows App to Control Your Arduino!

This tutorial will cover all the details that are required to create your own app for Windows phone to connect with the Arduino.

IntermediateFull instructions provided1.5 hours6,444

Things used in this project

Hardware components

HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
LED (generic)
LED (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Arduino Mega 2560 & Genuino Mega 2560
Arduino Mega 2560 & Genuino Mega 2560
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Windows Phone

Story

Read more

Schematics

Circuit diagram for the Bluetooth system

Connect the hardware components as per the wiring diagram shown here.
Bluetooth

Code

Code for designing the UI for BLUE ARDUINO application

XML
Copy this XAML code onto your Visual Studio editor.
 <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock Text="Blue Arduino" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0" FontSize="64" FontFamily="Segoe WP Black" Foreground="#FF1C23C7"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Grid.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Color="#FF3DB8DC" Offset="1"/>
                </LinearGradientBrush>
            </Grid.Background>
            <TextBox x:Name="DeviceName" HorizontalAlignment="Left" Height="72" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="217" Margin="39,437,0,0">
                <TextBox.Background>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FFF8F9FB" Offset="0"/>
                        <GradientStop Color="#FFC1C1D1" Offset="1"/>
                    </LinearGradientBrush>
                </TextBox.Background>
            </TextBox>
            <Button x:Name="on" Content="ON" HorizontalAlignment="Left" Margin="116,254,0,0" VerticalAlignment="Top" Click="on_Click" Height="100" Width="101" RenderTransformOrigin="0.5,0.5" Foreground="Black" BorderBrush="White">
                <Button.Background>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FF3FD613" Offset="0"/>
                        <GradientStop Color="#FFF0EEF1" Offset="1"/>
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <Button x:Name="off" Content="OFF" HorizontalAlignment="Left" Margin="246,254,0,0" VerticalAlignment="Top" Click="off_Click" Height="100" Width="100" RenderTransformOrigin="0.5,0.5" Foreground="#FF040404" BorderBrush="White">
                <Button.Background>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FFEC391D" Offset="0.377"/>
                        <GradientStop Color="#FFF0EEF1" Offset="1"/>
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <Button x:Name="connect" Content="CONNECT" HorizontalAlignment="Left" Margin="261,437,0,0" VerticalAlignment="Top" Width="161" Click="connect_Click" Foreground="Black" Height="72" BorderBrush="White">
                <Button.Background>
                    <LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
                        <GradientStop Color="#FFE4E5F1" Offset="0"/>
                        <GradientStop Color="#FFC0C2E8" Offset="1"/>
                    </LinearGradientBrush>
                </Button.Background>
            </Button>
            <TextBlock Style="{StaticResource PhoneTextNormalStyle}" Margin="10,23,2,528" FontSize="64" FontFamily="Segoe WP Black" Foreground="White">
            	<Run FontSize="17.777" Text="               Simplest Windows Bluetooth Application"/>
            </TextBlock>
        </Grid>

Code for AppToDevice method [BLUE ARDUINO]

C#
No need to download/copy this code separately. Entire code has been uploaded separately in POWERUP.ZIP.
Refer to this code for reference purposes.

For any kind of assistance regarding the hardware or software setup of this project comment below.
private void connect_Click(object sender, RoutedEventArgs e)    
{    
    //Saving the status    
    s = DeviceName.Text;    
    if (DeviceName.Text == "")    
    {    
        MessageBox.Show("Enter Device Name");    
        connect.Content = "Click to Connect";    
    }    
    else    
    {    
        AppToDevice();    
    }    
}    
private async void AppToDevice()    
{    
    connect.Content = "Connecting...Please wait";    
    PeerFinder.AlternateIdentities["Bluetooth:Paired"] = "";    
    var pairedDevices = await PeerFinder.FindAllPeersAsync();    
  
    if (pairedDevices.Count == 0)    
    {    
        MessageBox.Show("Compatible devices not found.Try again");    
    }    
    else    
    {    
        foreach (var pairedDevice in pairedDevices)    
        {    
            if (pairedDevice.DisplayName == DeviceName.Text)    
            {    
                connectionManager.Connect(pairedDevice.HostName);    
                connect.Content = "Connection Successful";      
                continue;    
            }    
        }    
    }    
}    

Arduino Code

Arduino
Copy this code to your ArduinoIDE
#include <SoftwareSerial.h>  
SoftwareSerial BTSerial(10, 11); // We configure PIN 10 as RX and PIN 11 as TX
void setup()  
{  
  pinMode(13,OUTPUT); //Led is connected here  
  BTSerial.begin(9600); //Begin the serial communication using bluetooth  
}  
void loop()  
{  
  char c;  
  if(BTSerial.available())  
  {  
    c=BTSerial.read();  
    if(c=='1')  // Simplest way of detecting HIGH
    {  
      digitalWrite(13,HIGH); //Set pin 13 to high "LED GLOWS" 
    }  
    else if(c=='0') // Simplest way of detecting LOW 
    {  
      digitalWrite(13,LOW); //Set pin 13 to low "LEDS STOPS GLOWING" 
    }  
   }  
  }  
}  

POWERUP App

The complete app can be downloaded and the user is granted permission to modify the application according to the needs of the project. For any kind of assistance regarding the hardware or software setup of this project comment below.

Credits

Aritro Mukherjee

Aritro Mukherjee

5 projects • 201 followers
Associate Developer @ Altimetrik. B.Tech (Electrical Engineering) Enthusiastic about IOT , Robotics and Automation technologies
Thanks to Marcos Pereira and Avirup171.

Comments