1. Digital WriteΒΆ

Digital Write is to output or write a digital signal to a digital pin. The digital signal has only two states, 0 or 1, 0V or 5V, so it allows some components, such as the LED and buzzer, to be on or off.

On the Arduino R3 board, there are 14 digital I/0 pins from 0 to 13, now use the pinMode() and digitalWrite() functions to write a high or low level to these digital pins.

  • pinMode(pin, mode): Configure the specific pin as INPUT or OUTPUT, here it needs to be set as OUTPUT.


    pinMode(pin, mode)

    • pin: the Arduino pin number to set the mode of.


  • digitalWrite(pin, value): Write a high level (5V) or a low level (0V) to a digital pin to change the operating state of the component. If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW.


    digitalWrite(pin, value)

    • pin: the Arduino pin number.

    • value: HIGH or LOW.

Example of Digital Write:

const int pin = 13;

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

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

Notes and Warnings

  • The pins 0~13 are all digital pins.

  • Do not use pins 0 and 1, as they are used to communicate with the computer. Connecting anything to these pins will interfere with communication, including causing the upload board to fail.

  • If the digital pins are used up, the analog pins (A0-A5) can also be used as digital pins.

Related Components

Below are the related components, you can click in to learn how to use them.