Arduino Programming Language: PinMode

Name

pinMode()

Description

The pinMode() sets the specified digital I/O pin as INPUT, OUTPUT or INPUT_PULLUP. 
It is possible to set or read the value of a digital I/O pin by using the digitalWrite() and digitalRead() methods. 
In this example it is defined the digital pin 3 as pinIN and the digital pin 4 as pinOUT. 
It is set with the method pinMode the pinIN as INPUT and the pinOUT as OUTPUT. 
In the loop it is read the value of the pinIN with digitalRead, if it is HIGH (the value is 1) the pinOUT is set HIGH else LOW. 
it is possible to enable the internal pullup resistors with the mode INPUT_PULLUP. Additionally, the INPUT mode explicitly disables the internal pullups. For more information on how to set the internal pull up resistors see Digital Pins.

Syntax

pinMode(pin,value)

Parameters

  • pin: pin number used
  • value: INPUT, OUTPUT or INPUT_PULLUP

Returns

none 

Usage

Application

Examples

int pinIN = 3;
int pinOUT = 4;
int value = 0;

void setup() {
pinMode(pinIN, INPUT);
pinMode(pinOUT, OUTPUT);
}

void loop() {
value = digitalRead(pinIN);
if (value == HIGH)
{
digitalWrite(pinOUT, HIGH);
} else {
digitalWrite(pinOUT, LOW);
}
}

Related Functions


Based on the reference originally written by Arduino Community,  wiring.org.co and  arduino.cc