write values to arduino from visual basic

I am sending values of 30 and 40 from vb to arduino to control led on and off,but it is not responding.
The receiver led in the arduino blinks.

int ledPin =  13;      // the number of the LED pin

// variables will change:
//int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
//  // initialize the pushbutton pin as an input:
//  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
//  buttonState = digitalRead(buttonPin);
int value;
while(Serial.available()==0)
  value= Serial.read();
  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (value == 30){digitalWrite(ledPin, HIGH);}
  else if (value==40) {digitalWrite(ledPin, LOW);}
}

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

...R

I am sending values of 30 and 40 from vb to arduino

If the Arduino doesn't recognize the value as 30 or 40, then the problem is that you are sending them incorrectly.

PaulS:
If the Arduino doesn't recognize the value as 30 or 40, then the problem is that you are sending them incorrectly.

It seems to me more likely that the OP is not receiving them correctly.

...R

Robin2:
It seems to me more likely that the OP is not receiving them correctly.

...R

My guess is that OP is sending "30" or "40", not 30 or 40.

OP COULD send 30 or 40 with the appropriate VB code.

PaulS:
My guess is that OP is sending "30" or "40", not 30 or 40.

I would bet large sums of money that is what the OP is doing.

His Arduino program is expecting a record separator or a ( .

.

PaulS:
My guess is that OP is sending "30" or "40", not 30 or 40.

That is my guess also, and it is what I would recommend. Debugging is a lot easier when data is sent in human-readable format.

...R

Robin2:
Debugging is a lot easier when data is sent in human-readable format.

No, this is a problem of not knowing that there is a difference between "30" and the number 30.

.

ieee488:
No, this is a problem of not knowing that there is a difference between "30" and the number 30.

.

This MIGHT be a problem of not knowing the difference, but that does not make what Robin2 said wrong.

PaulS:
This MIGHT be a problem of not knowing the difference, but that does not make what Robin2 said wrong.

No, but it is obvious in the OP's code why it (what Robin2 wrote) isn't the problem.
The OP believes he is sending human-readable format!

ieee488:
The OP believes he is sending human-readable format!

I believe this code (from the Original Post) implies that the opposite is the problem.

value= Serial.read();
  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (value == 30)

...R

I should change while(Serial.available()==0) in while(Serial.available() > 0) to get started.

Robin2:
I believe this code (from the Original Post) implies that the opposite is the problem.

value= Serial.read();

// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (value == 30)




...R

No, it actually proves that what I wrote it true.

He think's that his code is sending text 30.
He wants the human-readable 30.
But he doesn't realize that human-readable 30 aka text 30 aka "30" is not 30.

@ieee488, that's a fact he should realize the difference between the two.

ieee488:
No, it actually proves that what I wrote it true.

He think's that his code is sending text 30.

If he thinks that the VB program is sending the 30 as text (i.e. 2 characters) why is he only reading one character?

Maybe you and I both think the same but have different ways of expressing ourselves.

...R

if you wish to transmit binary values 30 ans 40 you can use the SerialPort Write method which takes a byte array as a parameter, e.g.

' every second transmit binary sequence 30 40 30 40 to blink LED
Imports System.IO.Ports
Imports System.Threading
Module Module1
    Sub Main()
        Dim serialPort = New SerialPort()
        serialPort.PortName = "COM10"
        serialPort.BaudRate = 115200
        serialPort.Open()
        While True
            ' define a single byte array and transmit it
            Dim data() As Byte = {30}
            serialPort.Write(data, 0, 1)  ' transmit 30
            Thread.Sleep(1000)
            data(0) = 40
            serialPort.Write(data, 0, 1)  ' transmit 40
            Thread.Sleep(1000)
        End While
    End Sub
End Module

Robin2:
If he thinks that the VB program is sending the 30 as text (i.e. 2 characters) why is he only reading one character?

He doesn't know that he is reading only one character.
Haven't you seen other code like the OP's when it comes to reading the serial port?

Anyway, the OP has not returned.
If he does, he better explain himself better.
He has a habit of pulling this type of stunt.
Another post of his from a month ago on the same topic.
http://forum.arduino.cc/index.php?topic=537013.msg3659979#msg3659979

.