Arduino will not properly run basic sketches

Have I fried it? After some trouble shooting I have found that my Arduino will not run the Button sketch properly. The led just stays on whether or not voltage is applied to the proper pin. When first I had composed a more complex sketch to try out and I found that some of my leds stayed on and would turn off or become brighter if I pressed the buttons that I had wired in, regardless of what my sketch was supposed to have them do. And as I have already said, I went back to basics and found that my Arduino cannot properly run the basic button sketch off the Arduino website. It does blink just fine though.

I'm pretty perplexed right now, and being new I'm not sure exactly what is going on. Just wondering if it died of natural causes, if I killed it or its something else.

--- Edit to include sketches used

const int bluBut = 2;
const int grnBut = 3;
const int redBut = 4;
const int yelBut = 5;
const int yelLed = 6;
const int redLed = 7;
const int grnLed = 8;
const int bluLed = 9;

int bluState = 0;
int grnState = 0;
int redState = 0;
int yelState = 0;

void setup(){
pinMode(bluBut, INPUT);
pinMode(grnBut, INPUT);
pinMode(redBut, INPUT);
pinMode(yelBut, INPUT);
pinMode(yelLed, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(grnLed, OUTPUT);
pinMode(bluLed, OUTPUT);
}

void loop() {
bluState = digitalRead(bluBut);
grnState = digitalRead(grnBut);
redState = digitalRead(redBut);
yelState = digitalRead(yelBut);

if (bluState == HIGH) {
digitalWrite(bluLed, HIGH);
}
if (bluState == LOW) {
digitalWrite(bluLed, LOW);
}

if (grnState == HIGH) {
digitalWrite(redLed, HIGH);
}
if (grnState == LOW) {
digitalWrite(redLed, LOW);
}

if (redState == HIGH) {
digitalWrite(redLed, HIGH);
}
if (redState == LOW) {
digitalWrite(redLed, LOW);
}

if (yelState == HIGH) {
digitalWrite(yelLed, HIGH);
}
if (yelState == LOW) {
digitalWrite(yelLed, LOW);
}
}

I would have used if, else statements but in an attempt to simplify things so that they may work, I only used if statements for this.

And I also tried to run the sketch from the website by Tom Igoe, again to no avail.

const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin

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

void setup() {
// 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);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}

Hmm… could you post your sketch please? Are you sure you have set the pinMode correctly?

Hello.

Have you pulled up or down these buttons by resister?

If not, you may digitalwrite the input pin high for pullup.

See auduino reference ; /Reference/DigitalWrite

This has nothing to do with your hardware problem.

 if (bluState == HIGH) {
   digitalWrite(bluLed, HIGH);
 }
 if (bluState == LOW) {
   digitalWrite(bluLed, LOW);
 }

If the blue switch was pressed (bluState IS HIGH), you turn the pin on.

Then, with no change in state possible, you check bluState again. bluState, in your code, can only take on HIGH or LOW as possible values, so, if the state is not HIGH, it must be low.

So, this code could simply be:

 if (bluState == HIGH) {
   digitalWrite(bluLed, HIGH);
 }
else {
   digitalWrite(bluLed, LOW);
 }

But, notice that you always set the LED pin state to match the switch pin state, so all you really need to do is:

   digitalWrite(bluLed, bluState);

8 lines of code just became 1 line. Fewer places for the bugs to hide.

If Blink works, that tends to be a good sign. The next thing you might try is adding some Serial.print() statements and see if things are happening that way.

As mentioned, do you have Pull-up resistors on your buttons? Do you have capacitors? You aren't putting any kind of debounce in your code. So it is possible the buttons are bouncing and not giving you reliable results.

Thank you for all of your helpful answers. My problem, as it was again, was that I had not used any pull resistors. As embarrassing as that is, me and a friend still had a laugh when I told him what my mistake had been. I've got a bit of a grudge against pull resistors actually, after burning myself on an especially hot resistor when I accidentally shorted it out.

Oh, and thankyou, thankyou PaulS for the tip on shortening up my code. I had been using if, else statements but had removed them to try and root out errors. That shortcut really saves some space and confusion, so again, thanks.