“Each of the 14 digital pins on the Uno can be used as an input or output, using pinMode()
, digitalWrite()
, and digitalRead()
functions. They operate at 5 volts. Each pin can provide or receive a maximum of 40 mA and has an internal pull-up resistor (disconnected by default) of 20-50 kOhms. In addition, some pins have specialized functions:
“The Uno has 6 analog inputs, labeled A0
through A5
, each of which provide 10 bits of resolution (i.e. 1024 different values). By default they measure from ground to 5 volts, though is it possible to change the upper end of their range using the AREF pin and the analogReference()
function. Additionally, some pins have specialized functionality:
“There are a couple of other pins on the board:
Special functions are consumed by:
This leaves:
Note that pin 13 also has a pullup resistor on it for the internal LED, meaning it's a poor choice for use as an input even if you're not using SPI.
const int LED_PIN = 13; setup() { pinMode(LED_PIN, OUTPUT); } loop() { digitalWrite(LED_PIN, HIGH); digitalWrite(LED_PIN, LOW); }
pinMode(A0, OUTPUT); digitalWrite(A0, HIGH);
const int LED_PIN = 11; /* 3,5,6,9,10,11 on Uno. */ loop() { analogWrite(LED_PIN, 127); /* 0 to 255. */ }
const int BUTTON = 7; int btnState; setup() { pinMode(BUTTON, INPUT); } loop() { btnState = digitalRead(BUTTON); }
pinMode(A0, INPUT); btnState = digitalRead(A0);
“There are … pullup resistors built into the Atmega chip that can be accessed from software. … This effectively inverts the behavior of the INPUT mode, where HIGH means the sensor is off, and LOW means the sensor is on.
“The value of this pullup depends on the microcontroller used. On most AVR-based boards, the value is guaranteed to be between 20kΩ and 50kΩ. On the Arduino Due, it is between 50kΩ and 150kΩ.
“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 must use pin 13 as a digital input, set its pinMode() to INPUT and use an external pull down resistor.” 9)
pinMode(theInputPin, INPUT_PULLUP);
analogReference();
.int ANALOG_PIN = 3; // Maps to A3 we think. int val = 0; void loop() { val = analogRead(ANALOG_PIN); // read the input pin }
Simple reporting:
void setup() { Serial.begin(9600); // init serial communication at 9600 bps } void loop() { Serial.write(65); // write a byte (interpreted as ASCII) Serial.print(42); // print a number Serial.println("Yo."); // print a string as a line Serial.print(78, HEX); // print "4E" Serial.println(1.23456, 4); // print "1.2346" Serial.end(); // release pins 0 and 1 for general use }
Later.