How to start a PC program using a switch

Hello,

I want to interact with a Windows program using a switch. One way to do this is to connect the switch to a USB port. The program runs under Windows and polls the com port that the switch is connected to. If the switch is pressed, the buffer of the com port will briefly have data. The program will detect this and initiate something (always the same). So the switch should act as if it is an USB device. This means that a driver for the USB should be necessary. This is something I cannot do. Therefore, instead of this solution, can Arduino be used? That is the switch will be connected to one of the inputs on the Arduino. When this input is on, Arduino will send the relevant output to a USB port. Is this possible? Are there any simpler way?

Thank you,

It sure is possible. you can use the arduino to send serial data to the usb port (which acts then as a COM port)

But do you want to start a program, you should use gobetwino, it can launch programs on your pc by sending specific commands to it.

I googled up the program and boy it's cool. I didn't know there was such a program. But the sad thing is it's still in beta.

Why is that a problem? If it works, then that won't matter. I'm sure I've seen the author post on these forums.

I have limited knowledge of this but you probably could solve it using RobotBASIC also. A book I've just started reading about the Arduino and RobotBASIC have some examples that sounds very similar.

Hello,

Thank you for all replied. I put together a small project using a switch and a LED to show that the button switch is pressed. When pressed I send a message to com port 3 also that the button is pressed. The idea is to use say a VB program to check if the button is pressed by detecting that there is predefined string in the Com buffer such as "button is pressed"), take an action. The circuit works within Arduino workspace, i.e. when I press the button, the LED lights and I see the text in the Arduino Serial Monitor. But I cannot monitor this com port from the VB program after sketch opened the port, since VB program complains that the com port is already opened. On the other hand, if I first run the VB program to open the port, then run the sketch, this time Arduino complains that port is used by another application. Any idea how I can monitor the com port that Ardunio is using from VB? Both the sketch and the VB program listings are given below. Any ideas will be appreciated a lot. Thank you.


The sketch:
/*

  • Alternating switch
    */

int switchPin = 2; // switch is connected to pin 2
int ledPin = 12; // LED is connected to pin 12
int val; // variable for reading the pin status
int buttonState; // variable to hold the last button state

void setup() {
pinMode(switchPin, INPUT); // Set the switch pin as input
pinMode(ledPin, OUTPUT); // Set the LED pin as output

Serial.begin(9600); // Set up serial communication at 9600bps
buttonState = digitalRead(switchPin); // read the initial state
}

void loop(){
val = digitalRead(switchPin); // read input value and store it in val

if (val != buttonState) { // the button state has changed!
if (val == LOW) { // check if the button is pressed
Serial.println("Button is pressed");
digitalWrite(ledPin, HIGH); // turn LED on
} else { // the button is -not- pressed...
Serial.println("Button is released");
digitalWrite(ledPin, LOW); // turn LED off
}
}

buttonState = val; // save the new state in our variable
}


the VB6 program:

Private Sub comScan_OnComm()

Select Case comScan.CommEvent

' Events
Case comEvReceive ' Received RThreshold # of chars.
Do
DoEvents
buffer$ = buffer$ & comScan.Input
Loop Until Len(buffer$) > 3
txtDisplay.Text = buffer$

End Select

End Sub

Private Sub Form_Load()

comScan.CommPort = 3
' 9600 baud, no parity, 8 data, and 1 stop bit.
comScan.Settings = "9600,N,8,1"

comScan.PortOpen = True

End Sub

Only one program can open the COM port at a time. If your VB program has it open, the Arduino IDE can't access it. If the Arduino IDE has it open, the VB program can't access it.

If you want to see what's happening and have your VB program respond to messages from the Arduino, have your VB program echo all the input to its output so that you can see it in the console window.

By the way, assuming you're running Windows on the PC, you can use the Gobetwino application instead of writing a VB app of your own. Gobetwino is designed to do exactly what you're trying to do on the PC side.

Hello All,

The com port was under Arduino control when I wanted to access it from the VB program. When I exited from the Arduino, everything worked. I can now use it to actuate a function from Arduino by accessing an USB port. Very exciting. This was my first Arduino project. Thank you all the responded.

Sincerely,

I'm late to the party but you could also use something like vUSB or similar to use the Arduino as an HID input (keyboard).

Then when you press a button it automatically keys in a button combo.
Just get a hotkey program for the computer to start the program you want when that combo is entered.

the simple way is using an usb joystick to will launch a software on the pc if a button is pressed.

No need of an arduino to do that !

If your pc is an old one, no need of a joystick, use the parralel port.