pinMode()

Category:Maker

Set the mode of an individual pin.

Pins on the board can be used for either digital output, digital input, or analog input. Setting the pin mode of a pin determines how it will be used in the program.

Examples

Red LED on

Set the pin of the red LED to output and turn it on.

// Red LED is connected to pin 13
pinMode(13, "output");
// Turn pin 13 to on (1)
digitalWrite(13, 1);

Syntax

pinMode(pin, mode);

Parameters

Name Type Required? Description
pin Number The number of the pin you want to change. This is usually printed on your board, but can also be found in your board's documentation.
mode String The mode that this pin will be set to. Must be one of * "input" * "output" * "analog"

Tips

  • Not all pins can be used in every mode. Refer to your board's documentation for details.
  • On prewired boards, such as the Circuit Playground, you may not be able to change the mode of pins that are already defined.

Found a bug in the documentation? Let us know at documentation@code.org