Turn a light on with serairead

Hi,

I made this code to turn on/off the build in led(13) on the arduino.

String value;

void setup()
{
pinMode(13,OUTPUT);
digitalWrite(13,LOW);
Serial.begin(9600);
}

void loop()
{

if(Serial.available() > 0)
{
value = Serial.read();
delay(1);
if(value == 'W')
{
digitalWrite(13,HIGH);
Serial.print("On");
}
else if(value == 's')
{
digitalWrite(13,LOW);
Serial.print("Off");
}
}
delay(1);
}

But it dont work.
Can anyone help me.

 char value = Serial.read();

Try now

Please remember to use code tags when posting code

Serial.read() returns an 'int'. That's so it can return -1 if no characters are available. When you store an 'int' in a 'String' the number is converted to ASCII digits. The ASCII value of 'W' is 87 so your String would be "87", not "W".

...which is why it is easier not to use a String, when a char will do the job.