Arduino Pins - Odt
Arduino Pins - Odt
Digital Pins
The pins on the Arduino can be configured as either inputs or outputs. This document explains
the functioning of the pins in those modes. While the title of this document refers to digital pins, it is
important to note that vast majority of Arduino (Atmega) analog pins, may be configured, and used, in
exactly the same manner as digital pins.
NOTE: Digital pin 13 is harder to use as a digital input than the other digital pins because it has an
LED and resistor attached to it that's soldered to the board on most boards. If you enable its internal
20k pull-up resistor, it will hang at around 1.7V instead of the expected 5V because the onboard LED
and series resistor pull the voltage level down, meaning it always returns LOW. If you must use pin 13
as a digital input, set its pinMode() to INPUT and use an external pull down resistor.
A/D converter
The Atmega controllers used for the Arduino contain an onboard 6 channel analog-to-digital
(A/D) converter. The converter has 10 bit resolution, returning integers from 0 to 1023. While the main
function of the analog pins for most Arduino users is to read analog sensors, the analog pins also have
all the functionality of general purpose input/output (GPIO) pins (the same as digital pins 0 - 13).
Consequently, if a user needs more general purpose input output pins, and all the analog
pins are not in use, the analog pins may be used for GPIO.
Pin mapping
The analog pins can be used identically to the digital pins, using the aliases A0 (for analog input
0), A1, etc. For example, the code would look like this to set analog pin 0 to an output, and to set it
HIGH:
pinMode(A0, OUTPUT);
digitalWrite(A0, HIGH);
Pullup resistors
The analog pins also have pullup resistors, which work identically to pullup resistors on
the digital pins. They are enabled by issuing a command such as
digitalWrite(A0, HIGH); // set pullup on analog pin 0