The commands in setup () will be going to run when your program starts. You can use it to declare variable of values, libraries, set the parameters, and etc.

Introduction

After setup () completed, the commands in loop () are run. They will repeat continuously until you break the source of the Arduino board.

Whenever you press the reset button most of the time, your program will return to its state as when the Arduino was powered.

This process can be described as diagram below.

For example

int led = 13;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}

Explain

When you power for the Arduino, the “pinMode (led, OUTPUT);” command will be run once for declaration.

After running, the command at setup (), the loop () command will be run and repeate continuously, create a string: