3 leds do not work simultaneously on Arduino Nano

Hello!

Sorry, stupid questions and considerations ahead.

I have 3 leds hooked to Arduino nano.

But the leds are misbehaving - 2 out of 3 are on.

I tried to simplify the sketch to the bone, but still the leds do not power up at the same time.
What's strange, there is no power on one of the Arduino pins.

How I measure:
I set DMM to 20 V mode, put negative terminal on Arduino GND, and positive terminal to the pin I'm interested in.
Is it the correct way?

(Leds' cathodes are grounded, and anodes connected to respective pins through 220 Ohm resistors)

Sketch:

int leds[3] = {9, 5, 3};

void setup() {
  Serial.begin(9600);
  for (int i = 0; i < 3; i++) {
    pinMode(leds[i], OUTPUT);
    digitalWrite(leds[i], HIGH);
    Serial.println("led" + String(leds[i]));
  }
}

void loop() {
  // put your main code here, to run repeatedly:

}

Check your wiring (use your multimeter to check for continuity) & make sure the LEDs are connected the correct way around.

wvmarle:
Check your wiring (use your multimeter to check for continuity) & make sure the LEDs are connected the correct way around.

Thank you. I did all of that, checked all the wires, checked all the leds with DMM, tried swapping their pins etc.

Hi,
Do you have the LEDs the correct way around?

Can you post a picture of your project please, so we can see your component layout?
Are you using protoboard?

Thanks... Tom... :slight_smile:

int leds[] = {9, 5, 3}; // let the Arduino decide

or

int leds[2] = {9, 5, 3}; // [ 0] [1] [2]

Not sure what "int leds[3] = {9, 5, 3};" will do.
Leo..

Hi,
From the Arduino Reference page;

in an array with ten elements, index nine is the last element. Hence:
int myArray[10]={9, 3, 2, 4, 3, 2, 7, 8, 9, 11};

So array with 3 elements index 2 is the last element.
So;

int leds[3] = {9, 5, 3};

for (int i = 0; i < 3; i++) {
    pinMode(leds[i], OUTPUT);
    digitalWrite(leds[i], HIGH);
    Serial.println("led" + String(leds[i]));
  }

index 0,1,2 are assigned. 9 , 5 , 3

Tom.. :slight_smile:

Wawa:
int leds[2] = {9, 5, 3}; // [ 0] [1] [2]

That'll give you a compiler error for trying to squeeze three elements in an array of 2 elements long.

Not sure what "int leds[3] = {9, 5, 3};" will do.

That'll compile fine, at least.

Didn't have your morning coffee yet?

wvmarle:
Didn't have your morning coffee yet?

Almost midnight here.
Maybe time for some shut-eye.
Leo..

OP should start using bytes instead of ints for small values >= 0.

It's a habit to work on so that if you write something big for your board it can fit.

Also --- stop using String variables in small RAM environments. Learn to use C strings for your own good.

Serial.print( F( "led " )); // the F() macro keeps the text in flash, saves 5 bytes
Serial.print( i );
Serial.print( F( " = " ));
Serial.println( leds );
This generates less code than a one-liner using formatting functions.

beshur:
What's strange, there is no power on one of the Arduino pins.

How I measure:
I set DMM to 20 V mode, put negative terminal on Arduino GND, and positive terminal to the pin I'm interested in.
Is it the correct way?

You have to set the pin as OUTPUT and HIGH, default is INPUT LOW.

Is you target board set as Nano?

You might have smoked a pin and not knew it.

Hi,
What pin is not powering up to light the LED?

Tom.... :slight_smile:

Hi,
try this code, it should flash the LEDs ON and OFF, and print the result in IDE monitor.

int leds[3] = {9, 5, 3};


void setup()
{
  Serial.begin(9600);
  /*  for (int i = 0; i < 3; i++) {
      pinMode(leds[i], OUTPUT);
      digitalWrite(leds[i], HIGH);
      Serial.println("led" + String(leds[i]));
    }
  */
  pinMode(9, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(3, OUTPUT);
}


void loop()
{
  digitalWrite(9, HIGH);
  Serial.println("LED PIN 9 HIGH");
  digitalWrite(5, HIGH);
  Serial.println("LED PIN 5 HIGH");
  digitalWrite(3, HIGH);
  Serial.println("LED PIN 3 HIGH");
  delay(1000);
  digitalWrite(9, LOW);
  Serial.println("LED PIN 9 LOW");
  digitalWrite(5, LOW);
  Serial.println("LED PIN 5 LOW");
  digitalWrite(3, LOW);
  Serial.println("LED PIN 3 LOW");
  delay(1000);
}

Tom... :slight_smile:

Thank you for all the replies, guys!

@TomGeorge, thank you for the code, but it didn't help, only the yellow (5) is flashing.

You might have smoked a pin and not knew it.

Maybe, but I tried three more (pins 6, 7, 8), and even another Nano board.

Hi,
How about you solder the pins to the Nano board.....

Tom... :slight_smile:

Oh, riiight!

Nothing was actually connected! :astonished:

First lesson in electricity. You must make electrical connections to have things work! :sunglasses:

You might have smoked a pin and not knew it.

beshur:
Maybe, but I tried three more (pins 6, 7, 8), and even another Nano board.

Fer cryin out loud, CHECK THE PIN! Do NOT assume anything, CHECK and SEE!

REDUCE the number of UNKNOWNS, what you do just makes your case more and more unsure.

Who knows? You might find out what is wrong other than by accident.

TomGeorge:
Hi,
How about you solder the pins to the Nano board.....
Tom... :slight_smile:

Valid point!

It used to work like this on other projects.

I'll solder and get back to you later, guys, if needed.
Thanks!

Female end jumpers are good for making contact on pins even without soldering.

If I'm not sure that a breadboard contact is made I check continuity with my meter. I can do that as often as need be.