Question about pins

Hello friends:

I don't have a problem with my Arduino board, so therefore, I am not 100% certain that I am posting in the correct forum. My apologies if this is the case.

I had a question about the pins on the board. I'm given to understand that the pins are the little holes that wires fill up.......that being said, I've looked and looked and looked, but cannot seem to find any resource on the internet or in this "Getting Started..." book by Signore Banzi on what the actual function of each of these pins is. I've figured out that some are digital, some are analog, some provide power, some are ground, and then some just have a number next to each of them. An in-depth description of the function of each pin (or group of pins with a like function) would be much appreciated, for instance explaining the abbreviations, symbols, and so on. Thanks.

FigNeutron

The headers are connected direct to the ATMega pins.
Read the datasheet as to what the Analog and Digital pins can do.

Summary datasheet

Complete datasheet

Don't confuse the physical pin with its function. For the function see:-

0 through 13 are digital I/O pins. Use pinMode() to set them as INPUT or OUTPUT. Use digitalRead() for INPUT and digitalWrite() for OUTPUT.

A0 through A5 (also known as 14 through 19) are analog input pins. Use analogRead() to get a number from 0 to 1023 representing a voltage from 0V to 5V. They can also be used as digital pins (pinMode, digitalRead, digitalWrite).

Some pins have specialized uses:
0,1 is for serial I/O. That's how Serial.print() gets to your PC via the USB-to-Serial converter.
10, 11, 12, and 13 double as the SPI interface, used to communicate with some chips.
A4 and A5 double as the I2C/TWI interface, used to communicate with other chips.

The GND (ground) pins are all connected. They provide the 0V reference from which other voltages are measured.

The Vin pin connects to the power input jack. It can be used to put power (7-12V) into the Arduino or tap off power provided through the power jack.

The 5V pin connects to the regulated 5V power line. You can put regulated 5V in through that pin to power the Arduino or, if the Arduino is powered from USB, the power jack, or Vin, you can get 5V from the pin for your other chips. Limit that to about 400 mA.

The 3.3V pin is for getting a small quantity (50 mA?) of 3.3V power for other chips.

The RESET pin, when connected to Ground, will force your Arduino to reset.

The Aref pin can provide a reference voltage for the analog inputs. Leave it unconnected.

This relates pins on the board to pins on the chip:

Now I suggest you download the Atmega328P datasheet:

http://atmel.com/dyn/resources/prod_documents/8271S.pdf

johnwasser:
0 through 13 are digital I/O pins. Use pinMode() to set them as INPUT or OUTPUT. Use digitalRead() for INPUT and digitalWrite() for OUTPUT.

Okay, excellent. Now, in my book, on page 41, he shows a figure of the LED plugged straight into pin 13 and the ground pin. He has a pushbutton, which his sketch has to turn the LED on when it is pressed (not a toggle).

He has one jumper wire connecting the 5V pin to the pushbutton negative end, and on the positive end, he has a jumper wire connecting this positive end to pin 7 (input pin). On that same column (but different hole) of the positive, he has the positive end connected to a 10 kilohm resistor and thence to a ground pin.

Why does he have the pushbutton configured in this way? Would the 3.3V pin have sufficed, or is that not enough current? And why is the current reduced before it is grounded, but not when connected to the input pin (7)? Thanks for the answers.

FigNeutron

"Now, in my book, on page 41, he shows a figure of the LED plugged straight into pin 13 and the ground pin."
I haven't seen that book.
However:
That will work with much older Arduino's. Newer ones, since at least 2009, do not have a resistor in series with pin 13, so an external current limit resistor is needed.

On the switch, that can connect from a pin to ground. The internal pullup is used to hold the pin High when the switch is open, and the switch connects the pin to ground when closed. No other resistors are needed.

Simple program to read switch and make led on Pin 13 light up when switch is pressed.
Uses on board LED, and switch from pin 7 to ground.

byte ledpin = 13;  // define the pins used
byte switchpin = 7;
void setup(){
pinMode (ledpin, OUTPUT); // define the pins as inputs/outputs
pinMode (switchpin, INPUT);
digitalwrite (switchpin, HIGH); // enables internal pullup resistor
}
void loop(){
if (digitalRead (switchpin) == LOW){
digitalWrite (ledpin, HIGH);
}
else
{
digitalWrite (ledpin, LOW);
}
}

CrossRoads:
On the switch, that can connect from a pin to ground. The internal pullup is used to hold the pin High when the switch is open, and the switch connects the pin to ground when closed. No other resistors are needed.

Many people writing examples seem to think it's wrong for an input pin to go from HIGH to LOW when you push a button. They insist on adding a pull-down resistor (to make the pin LOW when the switch is open) and a switch between the pin and +5V (to make the pin HIGH when the button is pressed). As CrossRoads says you can avoid the external pull-down resistor buy reversing the action of the button and using the internal pull-up resistor.

In answer to another question: Yes, you could use 3.3V instead of 5V for the switch. The voltage is high enough to register as HIGH on a 5V input. The only advantage is that the external pull-down resistor will use 0.33 milliwatts instead of 0.5 milliwatts while the button is pressed. Not a significant advantage.

The book, as I mentioned earlier, was written by Massimo Banzi on Sept. 2011 (although this is the second edition, the first edition was published in 2008; perhaps this was overlooked).

Thanks for the tips!

FigNeutron

the first edition was published in 2008;

When it was published is not when it was written though. That changed I believe in 2006

The book is just over 100 pages, written in easily understood English (or translated from easily understood Italian if he so preferred) and has a diagram on almost every other page......I doubt that he started even right before a relevant change in the product took place and finished two years later.

Better things to do, holes to dig. :slight_smile: