Arduino projects book project 6

Hi! I'm new to arduino and i'm testing all the projects that comes on the arduino book delivered with the starterkit. i have a question.

Inside the code the book page 74 line 4 make reference to ledPin=13; so i asumed that i would connect a cable to this pin (13) on the arduine board, nevertheless the cable is connected to pin 8 .

and the project works fine , so my question is which is the real number of the pins on the board and wich is the correct way to call each pin number?

Thanks in advance

What Arduino board do you have?

icarrasquedo: so my question is which is the real number of the pins on the board and wich is the correct way to call each pin number?

The only number of the digital pins is the one printed on the board, ie 0-13 on an Uno.

Analog pins are slightly more complicated: they're numbered A0-A5 on an Uno, and that's how you call them for use as digital pins. If you call them as analog pins, they're just 0-5 since the "A" is redundant. I think but never used this way, the analog pins can also just be numbered above 13.

These are all the same pin:
digitalRead(A3); //without the A, it would be digital pin 3
analogRead(3);  //can only mean A3
digitalRead(17); //not sure

That said, you can call pins by variable names as you've seen:

int ledPin=13;

digitalWrite(ledPin, HIGH);

I don't have a starter kit so I can't check, but I'm guessing that in that sketch, both pins 13 and 8 are used. 13 probably used as above, and 8 just with a simple

digitalWrite(8, HIGH);

Both ways are correct. Giving a pin a name aids readability of the code. Also makes it easy if you change your mind and move from say pin 4 to 10: just one line to change, not every line where it's used.

JimboZA:

analogRead(3);  //can only mean A4

Well, I’m glad that’s clear. :wink:

3, 4 whatever... close enough...

Fixed, thanks.