pinMode()
Description
Configures the specified pin to behave either as an
INPUT
or an OUTPUT
.See the Digital Pins page for details on the functionality of the pins.
It is possible to enable the internal pull-up resistors with the mode
INPUT_PULLUP
. Additionally, the INPUT
mode explicitly disables the internal pull-up.Syntax
Use the following function to set the behavior of a pin:
pinMode(pin, mode)
Parameters
The function admits the following parameters:
: the Arduino pin number to set the mode of.pin
:mode
,INPUT
, orOUTPUT
. See the Digital Pins page for a more complete description of the functionality.INPUT_PULLUP
Returns
The function returns nothing.
Example Code
Set the Arduino digital pin 13 (built-in LED) as an
OUTPUT
and toggles it by alternating between HIGH
and LOW
at one second pace.1void setup() {2 pinMode(13, OUTPUT); // sets the digital pin 13 as output3}4
5void loop() {6 digitalWrite(13, HIGH); // sets the digital pin 13 on7 delay(1000); // waits for a second8 digitalWrite(13, LOW); // sets the digital pin 13 off9 delay(1000); // waits for a second10}
Notes and Warnings
The analog input pins can be used as digital pins, referred to as A0, A1, etc. The exception are the Arduino Nano, Arduino Pro Mini, and Arduino Mini’s A6 and A7 pins, which can only be used as analog inputs.
See also
Suggest changes
The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.
License
The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.