Unused PINS go to Ground?

Hi!
Today I connected an 3X3 LED Matrix to my Arduino UNO. Fot the shake of understanding and simplicity, I named the Anode Rows 1, 2, 3 and Cathode Columns A, B, C:

[A] B

                 |                 |                  |                        
                 |                 |                  |
[1]----------O1------------O2-------------O3                                  
                 |                 |                  |                    <-------------- LIKE THIS
                 |                 |                  |
[2]----------O4------------O5-------------O6
                 |                 |                  |
                 |                 |                  |
[3]----------O7------------O8-------------O9

Then I set:

1 as pin 0        A as pin 3
2 as pin 1        B as pin 4
3 as pin 2        C as pin 5

And then I tried it. I wanted to turn on LED 1, so I set pin 0 --> HIGH and pin A --> LOW, but I ended up lighting up LEDs 2 and 3. I immediately thought that there was a problem in the wiring of my LEDs, but there wasn't. Next, I tried not to give the LOW command and I only set pin 0 --> HIGH. Guess what..., the same thing hapened; LEDs 2 and 3 were also on. What I think is that when I give no commands to the pins, they are set by themselves to LOW (Ground) state. Taking this into account, I then set pin 0 --> HIGH, pin B --> HIGH and pin C --> HIGH and... SUCCESS! Only LED 1 was on! 

So, my question is:
If no commands are given to the pins, are they set to LOW (Ground) state??? If not, is my Arduino UNO R3 faulty????

SotosAle:
If no commands are given to the pins, are they set to LOW (Ground) state???

If you did not do anything with digital pins in your code, they are inputs with a high impendance state. That means that they are isolated from the circuit, and are "floating". They are not connected to ground.

I don't know how matrixes work. Maybe someone else can help with that.

If they are "floating", how do you explain the fact that I am only giving positive voltage to a pin and a whole row lights up???

I think it comes down to how you have configured the 'unused' pins i.e. the ones you are not using right now to turn an LED on. If you have them configured as outputs then they will be either HIGH or LOW all the time, so any LED with one leg connected to a LOW output pin which has the other leg connected to a HIGH output pin will light. If you have a pin that you don't want to drive an LED high or low, you need to isolate it by setting the pin mode to input.

Thanks! I got it now, but the problem is that those pins which will be configure as inputs can't be used to light a LED later, right? It seems that I have to set the pins that I don't want to function as grounds to HIGH every time...

You don't include code, and your description doesn't tell all it can. I see some ambiguity in your description of your pins, so I'll avoid using those descriptions. I'm guessing here to a degree, but this is what I think you're doing:

  • Your LEDs are all connected with anodes on row pins, and cathodes on column pins.
  • Somewhere in your initialization you configure all the pins as outputs, and you set them to digital zero, or LOW.

That works in terms of keeping all the LEDs dark. With all the pins outputting low voltage, there's no voltage across any LED, so no current flows, and none of them light up.

It won't work in terms of letting you selectively illuminate one LED. Here's why: when a row pin goes high, all the anodes in the row go high; with all the cathodes in the array at 0V, all the LEDs in the row will be forward-biased - anode high, cathode low - and they'll light up.

One way to describe what's wrong with the array is that all of the column pins are always in the active state - that is, they're in the state that allows the LED to illuminate if the row pin goes high. For the matrix to work, their default has to be inactive; otherwise, activating a row will make all the LEDs in the row light up, no matter what you intended. For the column pins, that inactive state could be either high, or high-impedance.

The same thing is true of the row pins: they have to default to an inactive state, too. That inactive state could be low, or high-impedance. From what you say, the default state for the rows is low, and that's inactive. So, the rows are already configured in a way that works.

Here are a couple of ways top fix it:

  • Initialize all the row pins to low, and the column pins to high. Light an LED by driving its row high, and column low. The LED at the intersection lights, but all the rest are either reverse-biased or have the same voltage on both pins.
  • Initialize all the pins to be inputs, and set them low to turn off their pullup resistors. Light an LED by reconfiguring its row and column pins as outputs, and driving the row pin high. The LED at the intersection lights, but all the rest see at least one pin that's an input, and can't conduct any current.

I don't see any current-limiting resistors in your ASCII diagram. You may have omitted them for clarity. If you don't have them, I'd recommend them. Without them, you're asking the output pin to give you all the current that it possibly can. Intuitively, I'd expect that to dramatically reduce the life of the microcontroller's output circuits.

SotosAle:
Thanks! I got it now, bFut the problem is that those pins which will be configure as inputs can't be used to light a LED later, right?

You can change a pin from input to output (and reverse) at any time.

However, you really don't need to in your case. Unused rows / columns need to be set to High.

Ok! Thanks to everybody! I have resistors connected to the matrix! I'll try some of your advice and inform you later...

I see it differently. Setting all the unused pins high will give unexpected results similar to those that that show up when all the unused pins are set low - all the LEDs in the column will light, instead of just one at the intersection. If all the row pins are set high, then driving any column pin low will make all the LEDs in the column light up. Their anodes will be high, and their cathodes low.

If all the pins are outputs, then unused pins connected to anodes have to be low, and unused pins connected to cathodes have to be high. That way, LEDs connected to two unused pins are reverse-biased, and LEDs connected to one unused pin and one active pin won't have any voltage across them, and both types will stay dark.

Yeah, I went back at and looked my matrix code. I did set unused rows/columns to INPUT.