Example Code for Arduino-Digital IO Control

Last revision 2026/01/24

This article provides step-by-step instructions and example code for controlling digital IO pins on Arduino, including hardware and software setup, and pin level toggling.

Hardware Preparation

Software Preparation

Sample Code

Set D24-D31 as output, cycle to set their levels high and low.

int pin;
void setup() {  // put your setup code here, to run once:
    for(pin=24;pin<32;pin++){
        pinMode(pin,OUTPUT);
    }
}
void loop() {   // put your main code here, to run repeatedly:
    for(pin=24;pin<32;pin++){
        digitalWrite(pin,HIGH);
    }
    delay(500);
    for(pin=24;pin<32;pin++){
        digitalWrite(pin,LOW);
    }
    delay(500);
}

Result

Digital pins D24~D31 will turn on (HIGH) for 500ms and then turn off (LOW) for 500ms repeatedly.

Was this article helpful?

TOP