Arduino Serial

I am trying to use serial communications to do something as simple as turning on and off LEDs because i have a larger more complex project planned of the future using serial. I am using the following code

int b=4;
int c=5;
int d=6;
int valin=Serial.read();
void setup() {
    Serial.begin(9600);
}

void loop() {
    switch(valin){
      case('b'):{
        digitalWrite(b,!digitalRead(b));
        Serial.println("LED B Turned On");
      }
      case('c'):{
        digitalWrite(c,!digitalRead(c));
        Serial.println("LED C Turned On");
      }
      case('d'):{
        digitalWrite(d,!digitalRead(d));
        Serial.println("LED D Turned On");
      }
    }
}

This code compiles fine but when I send one of the letters through the serial monitor none of the LEDs will light and it prints the "LED turned on" message but for more than one LED so it looks like:

LED B Turned ON
LED C Turned ON
LED D Turned ON
LED C Turned ON
LED D Turned ON

int valin=Serial.read();
void setup() {
    Serial.begin(9600);
}

Shouldn't the serial port be setup before you read it?
If you move the read to loop you still need to know that data is available before reading.
See this post for how to read from the serial port.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

@groundFungus, your link in Reply #1 is broken

...R

Thanks, Robin2. I fixed it. Having a bit of trouble with the forum today.

Your switch cases are missing break statements.