help: Arduino Uno pin voltages don't change states

Hi there,
Just got my Arduino Uno board and running into an issue trying to do some of the examples in the companion tutorial.
I first ran a sketch to set the pin 5 voltage HIGH and it worked fine. However when I try to modify the program to set a different pin (say # 3) to HIGH the changes don't take place. It seems that the board is still running the previous program. I've tried using the reset button and powering off and on but nothing works. I must be missing something really basic. Any help you can provide would be appreciated.

Thanks!

PS here is my code sample

void setup() {
// initialize digital pins 3,4,5 as output
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
}

// A simple loop function
void loop() {
digitalWrite(3, HIGH); // green LED
digitalWrite(4, LOW); // red LED
digitalWrite(5, LOW); // red LED

}

How do you have you LEDs connected?

For pin 3 work you need a R of about 270 ohms and a LED to gnd.

For pins 4 & 5 you need the same but the LED will only be on for an extremely short time as the LEDs will have power on (output HIGH) when reset but immediately is taken LOW by the program.
You can see this by putting a delay (1000); as you first statement of loop().

Weedpharma

Edit correction: default is LOW so will never come on for 4 & 5.

Thanks for getting back to me, Weedpharma :slight_smile:

I actually do switch 4 & 5 to HIGH and set pin 3 to LOW (as shown below) but no changes. Pin 3 stays HIGH and 4 & 5 are LOW. As for the resistors I have a 220 ohms connected between the diode and ground for all 3 LEDs so everything matches. Just to be sure when I connect pin 3 to each LED in turn they light up so I don't think it has to do with the resistance.

I'm starting to think that something is wrong with the board...

void setup() {
// initialize digital pins 3,4,5 as output
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
}

// A simple loop function
void loop() {
digitalWrite(3, HIGH); // green LED
digitalWrite(4, HIGH); // red LED
digitalWrite(5, HIGH); // red LED

}

Are you sure you have the LEDs the right way around? Do you have a multimeter to confirm there is no voltage change on the pin?

Confirm the program has loaded by flashing pin 13 (onboard LED) and add a delay (1000) so you can see it happening.

If this does not light the LEDs on 4 & 5, try reversing the LEDs. Then try reversing the logic and connect LEDs and R between 5v and the output pins. At power up, the LEDs should be lit and taking the pin HIGH should turn the LEDs off.

A clear photo of your connections may assist.

Weedpharma

Andy, first you said this:-

I first ran a sketch to set the pin 5 voltage HIGH and it worked fine. However when I try to modify the program to set a different pin (say # 3) to HIGH the changes don't take place.

Then you said:-

Pin 3 stays HIGH and 4 & 5 are LOW.

And this is the code you posted:-

void loop()
{
      digitalWrite(3, HIGH); // green LED
      digitalWrite(4, LOW); // red LED
      digitalWrite(5, LOW); // red LED
      
}

So the changes did take place at some point.

I don't think there is anything wrong with the board.
All I can think of is that maybe you sometimes click 'Verify' instead of 'Upload', so no changes are actually uploaded to the board.

Thank you guys! I found what the problem was. But first:

-Oldsteve: you caught me stating my pin numbers incorrectly when describing the problem. And even when I set ALL the pins to LOW state I was still having the issue with pin 5 staying on HIGH (not pin 3)

-weedpharma: good call on using flashing on pin 13 as a simple test. I took everything off the board and varied the delay from 100, to 1000, to 100000 but no changes.

Knowing something basic was definitely amiss I went back and installed the software on a different computer and that's when I immediately noticed that the interface looked different. Turns out that I had an older version of the IDE. Once I upgraded to 1.6.5 everything worked like a charm!

Thanks again :slight_smile: