From the course: Learning Arduino: Foundations

Unlock the full course today

Join today to access over 22,800 courses taught by industry experts or purchase this course individually.

The setup() and loop() functions

The setup() and loop() functions - Arduino Tutorial

From the course: Learning Arduino: Foundations

Start my 1-month free trial

The setup() and loop() functions

- [Instructor] All right. So, as mentioned, that once you open the software, it comes in with a default starting code. The code contains two functions. They are part of every Arduino sketch: setup function and a loop function. The Arduino program calls the setup function as the first thing when the Arduino unit powers up. So any code that you place in the setup function in your sketch runs first, and it only runs one time. The setup function is a great place to initialize input and output pins so they are ready to be used. Then, the program moves to the loop function code. The program calls the code inside the loop function repeatedly until the Arduino board is powered off. Most of the time, we place the main code inside the loop function section. It is the heart of most sketches. This is where we tell the Arduino board what to do in the sketch. Each time the sketch reaches the end of the loop function, it returns to…

Contents