Skip to content

Create a Test Sketch

Generate Sketch Scaffolding

Create a new test sketch or copy the testSketch.ino file from the following GitHub repository: github.com/chriscummings/remote-arduino-deployment

arduino-cli sketch new testSketch;
cd testSketch;
nano testSketch.ino;

Test Sketch Code

Paste the following into the generate sketch folder.

testSketch.ino
void setup()
{
    Serial.begin(9600);
    pinMode(13, OUTPUT);
}

void loop()
{
    Serial.println("Hello");
    digitalWrite(13, HIGH); // LED on
    delay(500);
    digitalWrite(13, LOW); // LED off
    delay(500);
}

Code Explained

In an Arduino sketch, before any other code executes, the setup() function is called once.

Documentation for setup()

In this example the setup() function:

  1. Sets the baud rate of the serial connection to 9600. Documenation for Serial.begin().
  2. Configures pin 13 to be an output. Documentation for pinMode().

After the setup() function runs, the loop() function is called and continues to repeat until the program is explicitly exited or crashes.

Documentation for loop()

In this example the loop() function repeats the following actions:

  1. Prints Hello to the serial connection. Documentation for Serial.println()
  2. Turns pin 13 "on" applying a 3.3V current. Documentation for digitalWrite()
  3. Waits 500 milliseconds. Documentation for delay()
  4. Turns pin 13 "off" removing current.
  5. Waits 500 milliseconds.

What's special about pin 13?

There is an onboard LED connected to it so that whenever 13 is "on" or "high" that LED lights up. It is commonly used for testing purposes because of this. Thus, every run of the loop() function causes this LED to blink on and off.

Onboard LED for Pin 1What's special about pin 13?3