Write a HIGH or a LOW value to a digital pin.

If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the corresponding value: 3V for HIGH, 0V (ground) for LOW.

If the pin is configured as an INPUT, writing a HIGH value with digitalWrite() will enable an internal pullup resistor (see the tutorial on digital pins). Writing LOW will disable the pullup. The pullup resistor is enough to light an LED dimly, so ifLEDs appear to work, but very dimly, this is a likely cause. The remedy is to set the pin to an output with the pinMode() function.

NOTE: Digital pin 14 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 pull-up resistor, it will hang at around 1.7 V instead of the expected 3V because the onboard LED and series resistor pull the voltage level down, meaning it always returns LOW. If you must use pin 14 as a digital input, use an external pull down resistor.



digitalWrite(pin, value)



pin: the pin number

value: HIGH or LOW






int ledPin = 14;                 // LED connected to digital pin 14

void setup()
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output

void loop()
  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(1000);                  // waits for a second
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(1000);                  // waits for a second

Sets pin 14 to HIGH, makes a one-second-long delay, and sets the pin back to LOW.



The analog input pins can be used as digital pins.


See also


Reference Home