Open a New sketch

Under File select New, as shown in the figure.

This will open a new, blank sketch, looking like the below.



A new window opens up with the following simple sketch. This is the absolute minimum sketch.


void setup() {

  // put your setup code here, to run once:




void loop() {

  // put your main code here, to run repeatedly:




Remember the first step after opening a sketch, perform a save as.

My own preference is to always add my initials, elb, to the beginning of a sketch. This clearly identifies it is my sketch.

In addition, as a good habit, its important to never use spaces in a file name. Use either camel case, which means inside words start with a capital, like “CamelCase,” or with an underscore, like elb_FileName.

This new sketch has the two elements common to every sketch. There is a void setup() and a void loop().

All the code in the void setup() section, between the { curly brackets } is executed at the beginning and runs only once.

All the code in the void loop() section, between the { curly brackets } is executed next and runs over and over again, forever. 

Once the sketch (the code) is uploaded (transferred to the microcontroller), it stays there in non-volatile RAM, even after the power is turned off. When power is restored, the sketch will run from the beginning. The Arduino does not have to be connected to the computer to run a sketch, just powered on.

A blank sketch is useful to test the connection to the Arduino and to erase any previous sketch uploaded to the Arduino.

Now we are ready to connect to the Arduino.