Why does my red led stay on

so its a simple idea 3 leds red blue and green I turn on and off on my computer the issue if I rap my fingers on the board rapidly turning them on and off sometimes the red one gets fixed on ?

its like it does not know red led reads high when I press the button to change it to low so I just get a user output of it turning to high ?

I do not think this is a programming issue I think some weird electrical reason but not sure ?

http://pastebin.com/9uz2iuQz

also will happily accept any correction as to laying out code this was one of the first bits of longer code I made

I do not think this is a programming issue

So, you put your code in the rubbish bin...

Are you looking for help here or on pastebin? If here, post your code HERE.

ok got the code now

char INBYTE;
int  LED1 = 10; // LED on pin 13
int  LED2 = 9; 
int  LED3 = 8;


void setup() {
Serial.begin(9600); 
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
}



// pinMode(ledPin, OUTPUT); 
void loop() {

if (Serial.available()) {
  char data = Serial.read(); // new veriable named data only exists in the scope of the if statement

  switch(data) {
    case '1': // if serial data is 1, toggle LED1
      if (digitalRead(LED1) == HIGH) // check if output pin is high so we can toggle it to the opposit state
         { Serial.println("Green light  off");
           digitalWrite(LED1, LOW); }
      else
         {Serial.println("Green light on");
        digitalWrite(LED1, HIGH);}
        
    break; // end of case '1'

    case '2': // if serial data is 2, toggle LED2
      if (digitalRead(LED2) == HIGH) // check if output pin is high so we can toggle it to the opposit state
         { Serial.println("Blue light off");
           digitalWrite(LED2, LOW); }
      else
         {Serial.println("Blue light on");
        digitalWrite(LED2, HIGH);}
        
    break; // end of case '2'

    case '3': // if serial data is 3, toggle LED3
      if (digitalRead(LED3) == HIGH) // check if output pin is high so we can toggle it to the opposit state
         { Serial.println("Red light off");
           digitalWrite(LED3, LOW); }
      else
         {Serial.println("Red light on");
        digitalWrite(LED3, HIGH);}
        
    break; // end of case '3'


    
    
  }
}
delay(20); //
}

As for the circuit diagram theirs really nothing to it the positive pin of the leds are contented to pins 8 though to 10 then after the led there grounds conect and go back to the ardunio gnd pin.

Aside from not posting the code or any circuit diagram or information, there is not much I can do to help you right now.

I do have one suggestion; are you using a pull up or pull down resistor? If not, there are great tutorials on it online. Google "why do i need a pull up resistor" and pick a tutorial.

Please let us know if this works. If it does not, upload your circuit diagram, AND paste your code in here. You type [ c o d e ] without the spaces to begin, and [ / c o d e ] at the end.

It should look something like this

You need a dropping resistor in series with each led, ~220 ohms.

.

You might want to turn off the LEDs each time a new key is detected, up to you.

BTW you can: digitalWite(led1,!digitalRead(led1)); // toggles led.

|500x367

.

You also don't need the delay at the end of loop() and INBYTE is not used. Other than that the code should work. Maybe removing the delay will help.

int  LED1 = 10; // LED on pin 13
int  LED2 = 9; 
int  LED3 = 8;

void setup() 
{
  Serial.begin(9600);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);  
  pinMode(LED3, OUTPUT);
}

// pinMode(ledPin, OUTPUT); 
void loop() 
{
  if (Serial.available()) 
  {
    char data = Serial.read(); // new variable named data only exists in the scope of the if statement

    switch(data) 
    {
      case '1': // if serial data is 1, toggle LED1
           digitalWrite(LED1, !digitalRead(LED1));
      break; // end of case '1'

      case '2': // if serial data is 2, toggle LED2
           digitalWrite(LED2, !digitalRead(LED2));
      break; // end of case '2'

      case '3': // if serial data is 3, toggle LED3
           digitalWrite(LED3, !digitalRead(LED3));
      break; // end of case '3'  
    }
  }
}

EDIT: I just tested the code above and it works ok for me.