Problem with nano(328) analogInputs

Hi all,
i have read in the documentation that it is possible to use the analog inputs as digital inputs/outputs.
As i understand it in my case (nano with 328) this would mean analog input 0-7 maps to digital input/output 14-21.
I have tried to the following:

pinMode(14, OUTPUT);
digitalWrite(14, HIGH);

Now, when i connect a led to analog input 0 it wont light up.
Can anyone tell me why / what im doing wrong?

Thanks in advance

micha

Can anyone tell me why / what im doing wrong?

Nothing wrong with that code fragment. Perhaps something else in your code is changing it back to an analog input or perhaps how you are wiring the LED up? Would need more info to help.

Lefty

Well, basically i just connected the led to analog input 0 and to gnd.
I know there should be a resitor but it works with the digital outputs so i thought it should work with the analog inputs as well.
I know i should add the resistor to save the nano from damage but it should work right?

Thanks for the quick reply :wink:

basedow

You definitely should add a resistor in series with the led. About 220 ohms should work with normal leds. You may have already destroyed either the led or Arduino's pin, or both. However, if you place the led in right way, i.e., the long leg in analog 0 and the short in gnd, you should probably have seen light at least some time before the led or Arduino fails.

If you just want to check if the analog 0 works as digital out HIGH, why don't you check the voltage with multimeter? If you don't own a multimeter, put a wire between analog 0 and some other digital/analog pin and read the value from Arduino.

I know there should be a resitor but it works with the digital outputs so i thought it should work with the analog inputs as well.
I know i should add the resistor to save the nano from damage but it should work right?

It is not safe to wire an LED to any digital or analog pin while it's in the an output mode and high state, and until that is corrected no further troubleshooting should be attempted. This is especially true in the case of a Arduino Nano as it's very difficult to unsolder and replace a damaged SMD packaged processor chip.

Lefty

Is it espacially dangerous on analog pins? Because it works fine with the digital pins.

micha

Because it works fine with the digital pins.

Equally dangerous with either type pins. Because your LED works on digital output pins, does not mean it is fine. Please research the topic and get some resistors, you have been cautioned and it's your board that is at risk.

Lefty

Right. Ill do.
Thanks for the help so far - ill get back here if needed :wink:

micha

Ok - so i just checked with a multimeter.
The digital outputs all give me 3.3V.
Two analog outputs give me 0.1V.
The rest of the analog outputs give me 0V.
With all pins set to HIGH.

Does that mean the 0V pins are broken?
Why did the led not light on the two 0.1V pins?

micha

Could you post your sketch code you are using to test the pins?

Lefty

void setup() {
  for (int i = 1; i < 22; i++) {
    pinMode(i, OUTPUT);
    digitalWrite(i, HIGH);
  }
}

void loop() {
}

Thats it :wink:

BTW:
It is sufficient to have one resistor for multiple leds right?

It is sufficient to have one resistor for multiple leds right?

Generally No, but I would have to see a drawing of how you are wiring them up in a drawing.

Your code looks fine. If the pins don't measure high voltage value with just a meter, with no LEDs wired up, then you must have damaged pins.

Lefty

I dont have no drawing :frowning:
But i mean if you connect a 1k resistor to the grd pin and then connect all the leds to that resistor on the one side(short one) and the other side(long side) to the output pin it should work - right?

What do you mean by High voltage? 3V? 5V? Or is 0.1V sufficient to say that the pin is not broken?

micha

Don't let Grumpy Mike in here, he'll be foaming at the mouth.... :smiley:

Don't let Grumpy Mike in here, he'll be foaming at the mouth.... Cheesy

Is it wrong so badly? :-/
Seems i have to learn a little more about the basics - any tipps where to start?
What kind of resistor do i have to use insted?
Why isnt it the same to put a resistor between every led and gnd or to put just one between them all and gnd?

If Grumpy Mike shows up - im not here ok? :wink:

What do you mean by High voltage? 3V? 5V? Or is 0.1V sufficient to say that the pin is not broken?

I'm not that familiar with the Nano board on if it's available in a 3.3volt version or just a 5 volt version, the Arduino home page/hardware section just shows a 5 volt version.

A high should measure very close to whatever voltage is powering the board, 5 or 3.3vdc. A reading of .1vdc when commanded high on a output pin is a damaged pin.

Using just one resistor as you discribe will cause the LEDs to dim as more and more are turned on as the one resistor will cause the fixed current to divide between those LEDs that have a high digital output.

Lefty

Too bad - seems i destroyed my analog inputs...

Anyway - thanks for your patience lefty

micha

If Grumpy Mike shows up - im not here ok?

OK.

If you just want indicator LEDs, I find 1k resistors work well. If you want maximum brightness its a little more involved. You won't damage anything with 1k resistors on 5 volts.

I think its too late already because i connected the leds without any resistor and if what lefty says is true i fragged the analog inputs of my nano.
The only thing that bothers me is - why didnt the digital pins frag either?
They are all still functional allthough i also connected leds to them without resistors.

micha

Tadaaaaaa :smiley:

I did not frag them. I have just tested the analog inputs of my nano and they are all functional. I tested them with the analogInput example and changed the pin in the code. I can control the frequency of the blinking led with every single analog pin. So I think they are ok.

Although this is very nice for me, my question from the beginning remains:

Why do my analog inputs not act as a digital output as stated in the documentation?

By the way: I got myself some 220R resistors to make sure I wont frag my pins in the future by connecting a led ::slight_smile:

Do you guys have any idea why this is not working?

Regards

micha