The setup() and loop() Functions in Arduino Programming

As we have seen in Basic Structure for Arduino that there are 2 basic functions in an Arduino Program.

arduino infinity official logo

setup()

The setup() function is called once when your program starts. Use it to initialize pin modes, or begin serial. It must be included in a program even if there are no statements to run.

void setup()
{
pinMode(pin, OUTPUT);      // sets the ‘pin’ as output
}

 loop()

After calling the setup() function, the loop() function does precisely what its name suggests, and loops consecutively, allowing the program to change, respond, and control the Arduino board.

void loop()
{
digitalWrite(pin, HIGH);   // turns ‘pin’ on
delay(1000);               // pauses for one second
digitalWrite(pin, LOW);    // turns ‘pin’ off
delay(1000);               // pauses for one second
}

By using these 2 functions you can create any Arduino Program.

Leave a Reply

Your email address will not be published. Required fields are marked *