Introduction: PC Apps Control Using Arduino

About: In my free time I used to write software in c# language and my long time application is for JARVIS a computer assistant like in Iron Man film, I'm designing my own home automation. I'm also learning to develop…

This is my first instructable and I made this due to my curiosity on the possibilities of interfacing devices such as smartphone and laptop using arduino.

The objective is to wirelessly control the laptop using smartphone via Bluetooth with the help of arduino. The arduino will receive the serial data from android via Bluetooth and transmit it to computer via com port. The android app is required to connect to arduino via Bluetooth module and a computer app to listen and execute the commands.

Step 1: Parts

1. Arduino Mega or any board.

2. HC-05 Bluetooth module.

3. Jumper wires.

4. Android device.

5. Computer with Bluetooth.

Step 2: Programming (Arduino)

Arduino code:

String device;

int resetPin = 12;

void setup() { // put your setup code here, to run once:

Serial.begin(9600);

Serial1.begin(9600);

Serial.println("ready");

Serial1.write("ready");

digitalWrite(resetPin, HIGH);

delay(200); // initialize the digital pin as an output.

pinMode(led, OUTPUT);

pinMode(resetPin, OUTPUT);

}

void loop() { // put your main code here, to run repeatedly:

while (Serial1.available()){ //Check if there is an available byte to read

delay(10); //Delay added to make things stable

char c = Serial1.read(); //Conduct a serial read

device += c; //build the string.

}

if (device.length() > 0)

{

Serial.println(device);

if(device == "skype")

{

Serial.println("skype");

Serial1.write("skype");

reset();

}

else if(device == "closeskyp3")

{

Serial.println("closeskyp3");

Serial1.write("closeskyp3");

reset();

}

else if(device == "viber")

{

Serial.println("viber");

Serial1.write("viber");

reset();

}

else if(device == "closevib3r")

{

Serial.println("closevib3r");

Serial1.write("closevib3r");

reset();

}

else if(device == "chrome")

{

Serial.println("chrome");

Serial1.write("chrome");

reset();

}

else if(device == "closechrom3")

{

Serial.println("closechrom3");

Serial1.write("closechrom3");

reset();

}

else if(device == "keyboard")

{

Serial.println("keyboard");

Serial1.write("keyboard");

reset();

}

else if(device == "closek3yboard")

{

Serial.println("closek3yboard");

Serial1.write("closek3yboard");

reset();

}

else if(device == "lockpc")

{

Serial.println("lockpc");

Serial1.write("lockpc");

reset();

}

else if(device == "shutdown")

{

Serial.println("shutdown");

Serial1.write("shutdown");

reset();

}

else if(device == "abortshutdown")

{

Serial.println("abortshutdown");

Serial1.write("abortshutdown");

reset();

}

else if(device =="logoff")

{

Serial.println("logoff");

Serial1.write("logoff");

reset();

}

else if(device == "reset")

{

reset();

}

else if(device == "controlStatus")

{

Serial.println("ready");

Serial1.write("ready");

}

else if(device == "notepad")

{

Serial.println("notepad");

Serial1.write("notepad");

}

else if(device == "eclipse")

{

Serial.println("eclipse");

Serial1.write("eclipse");

}

else if(device == "mediaplayer")

{

Serial.println("mediaplayer");

Serial1.write("mediaplayer");

}

else if(device == "ccleaner")

{

Serial.println("ccleaner");

Serial1.write("ccleaner");

}

else if(device == "calculator")

{

Serial.println("calculator");

Serial1.write("calculator");

}

delay(500);

device=""; //Reset the variable

} }

void reset()

{

delay(10);

digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)

delay(1000); // wait for a second

digitalWrite(led, LOW); // turn the LED off by making the voltage LOW

delay(1000); // wait for a second

delay(10);

digitalWrite(resetPin, LOW); //this never happens because Arduino resets

}

Step 3: Android App

The app is very simple created in MIT App Inventor and this article Android Arduino Bluetooth will help you.

If you don't want to create app don't change the codes in arduino file.

1. Bluetooth device button in the android app is to pick the module address.

2. Connect/Disconnect button to start/stop connection.

3. PC app list button is for other computer apps.

3. Send command button is after picking in the PC app list.

4. Close application checkbox is use to tell that the computer app going to close, uncheck if not.

5. Default buttons are for sending data which app is going to open.

Step 4: Wiring

Notice in the arduino code I added reset function to send data to computer once not repeatedly that's why jumper wire between is placed in pin 12 and pin reset for the reset mode.

When the android send serial data to arduino

if(device == "skype")
{

Serial.println("skype"); //Serial0

Serial1.write("skype"); //Serial1 means send back data to android bcoz Serial0 is the default and it use for com

//port and serial monitor in the computer

reset();

}

Arduino will send serial data to computer by doing [Serial.println], and call reset function

void reset() {
delay(10);

digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)

delay(1000); // wait for a second

digitalWrite(led, LOW); // turn the LED off by making the voltage LOW /

delay(1000); // wait for a second

delay(10);

digitalWrite(resetPin, LOW); //this never happens because Arduino resets

}

Just make sure to remove the connection of pin 12 to pin reset when you upload the code to arduino to avoid errors.

Step 5: Computer App

Computer app was written in Visual Studio 2013 (Download link) under framework 4.0, your system should have this in order to run the app if you don't have you may find it here Microsoft download.


If you want to create your own this will help Interfacing your arduino with a C# program

Step 6: Video

Step 7: Finished

Finally, we can control the computer wirelessly to perform some tasks and you can add speech recognition features to android app. I haven't check if there is existing article like this, I've done this for personal use but I thought of sharing to others.

I hope you find this helpful and my apologies about my poor writing skills because I don't used to write something like this but I did my first.

Thank you for reading.

Have fun!

Arduino All The Things! Contest

Participated in the
Arduino All The Things! Contest