Topics
Arduino Programming

Arduino Programming

Arduino programs are referred to as Sketches in the Arduino ecosystem.

Sketches use many of the usual programming constructs found in all high-level languages but may not support some advanced constructs since they are used on Arduino boards whose processing capability is much lesser than typical computers.

The first thing to understand about a Sketch is its structure. Every Arduino Sketch contains two specific functions, such as setup() and loop().

The setup() function is called once when the sketch starts, and it is used to write initialization instructions, which must be executed only once.

The loop() function is called continuously as long as the board is powered on, where instructions for all the functionality expected from the board are written. You need to include both functions in your sketch, even if you don't need them for anything.

When you start a new sketch in the IDE, it opens with the code below:

/*
 * This is the structure of an Arduino sketch. 
 * The instructions in the setup block run only once, 
 * right after the sketch is loaded onto the board.
 * After that the instructions in the loop block run continuously
 * as long as the board is powered on.
 */
 
void setup() {
  // Runs once 
}
 
void loop() {
	// Runs repeatedly
}