Bird
Raised Fist0
Arduinoprogramming~10 mins

Uploading and running a sketch in Arduino - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Concept Flow - Uploading and running a sketch
Write Sketch Code
Connect Arduino to PC
Open Arduino IDE
Select Board and Port
Click Upload Button
IDE Compiles Code
IDE Uploads Code to Arduino
Arduino Runs Uploaded Sketch
Observe Output (e.g., LED Blink)
This flow shows the steps from writing code to seeing it run on the Arduino board.
Execution Sample
Arduino
void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);
}
This sketch makes the built-in LED on pin 13 blink on and off every second.
Execution Table
StepActionIDE/Arduino StatusResult/Output
1Write sketch code in IDECode editor readySketch code is ready to compile
2Connect Arduino to PC via USBArduino connectedBoard is powered and ready
3Select correct board and port in IDEBoard and port selectedIDE knows where to upload
4Click Upload buttonIDE starts compilingCompiling sketch code
5Compilation successfulIDE compiles codeNo errors, ready to upload
6IDE uploads code to ArduinoUploading in progressSketch is sent to Arduino memory
7Upload completeArduino resets and runs sketchLED on pin 13 starts blinking
8Arduino runs loop()LED ON for 1 secondLED lights up
9Arduino runs loop()LED OFF for 1 secondLED turns off
10Repeat loop()LED blinks continuouslyBlinking continues until reset or power off
💡 Sketch runs indefinitely on Arduino until reset or power off
Variable Tracker
VariableStartAfter UploadAfter Loop 1After Loop 2Final
pin 13 stateLOW (default)LOWHIGH (LED ON)LOW (LED OFF)Repeats HIGH/LOW every second
Key Moments - 3 Insights
Why does the LED keep blinking even after the upload finishes?
Because the Arduino runs the loop() function repeatedly forever, as shown in execution_table rows 8-10.
What happens if the wrong board or port is selected before uploading?
The upload will fail or not reach the Arduino, as the IDE won't find the correct device (see execution_table row 3).
Why do we need to compile before uploading?
Compiling turns your human-readable code into machine code the Arduino can run, shown in execution_table rows 4-5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does the Arduino start running the uploaded sketch?
AStep 6
BStep 7
CStep 4
DStep 3
💡 Hint
Check the 'Result/Output' column for when the Arduino resets and runs the sketch (step 7).
According to variable_tracker, what is the state of pin 13 after the first loop iteration?
AHIGH
BUndefined
CLOW
DFlashing rapidly
💡 Hint
Look at 'After Loop 1' column for 'pin 13 state' in variable_tracker.
If you select the wrong port in the IDE, what will most likely happen according to the execution_table?
AThe sketch uploads successfully
BThe Arduino runs the old sketch
CThe upload will fail or not start
DThe LED will blink faster
💡 Hint
Refer to step 3 and the key moments about selecting the correct port.
Concept Snapshot
Uploading and running a sketch:
1. Write code in Arduino IDE
2. Connect Arduino via USB
3. Select correct board and port
4. Click Upload to compile and send code
5. Arduino resets and runs the sketch
6. loop() runs repeatedly until reset
Full Transcript
Uploading and running a sketch on Arduino involves writing code in the Arduino IDE, connecting the board to your computer, selecting the correct board and port, and clicking the upload button. The IDE compiles your code into machine language and uploads it to the Arduino. Once uploaded, the Arduino resets and runs the sketch, executing the loop function repeatedly. For example, a sketch that blinks the built-in LED on pin 13 turns it on and off every second continuously. Selecting the correct board and port is essential for successful upload. The LED blinking continues until the board is reset or powered off.

Practice

(1/5)
1. What happens immediately after you upload a sketch to an Arduino board?
easy
A. The Arduino board sends the sketch back to the computer.
B. You need to press the reset button to start the sketch.
C. The sketch starts running automatically on the board.
D. The sketch is saved but does not run until you power cycle the board.

Solution

  1. Step 1: Understand the upload process

    Uploading sends the program to the Arduino's memory.
  2. Step 2: Recognize sketch behavior after upload

    The Arduino automatically runs the sketch once upload finishes.
  3. Final Answer:

    The sketch starts running automatically on the board. -> Option C
  4. Quick Check:

    Upload triggers automatic run [OK]
Hint: Upload means program runs immediately after transfer [OK]
Common Mistakes:
  • Thinking you must press reset to start sketch
  • Believing sketch waits for manual start
  • Confusing upload with download
2. Which of the following is the correct step to upload a sketch to an Arduino board?
easy
A. Connect the board, then type the sketch in the serial monitor.
B. Write the sketch, then press the reset button before uploading.
C. Select the board, then save the sketch without uploading.
D. Select the board and port, then click the Upload button.

Solution

  1. Step 1: Identify correct upload procedure

    You must select the correct board and port in the IDE.
  2. Step 2: Perform upload action

    Clicking the Upload button sends the sketch to the board.
  3. Final Answer:

    Select the board and port, then click the Upload button. -> Option D
  4. Quick Check:

    Board + port selected, then upload [OK]
Hint: Always pick board and port before uploading [OK]
Common Mistakes:
  • Skipping board or port selection
  • Trying to upload without connecting board
  • Using serial monitor to upload code
3. Consider this Arduino sketch snippet:
void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);
}

What will happen after uploading and running this sketch?
medium
A. The built-in LED on pin 13 will blink on and off every second.
B. The LED will stay on permanently without blinking.
C. The sketch will cause a compilation error due to missing semicolons.
D. Nothing will happen because the loop function is empty.

Solution

  1. Step 1: Analyze setup function

    Pin 13 is set as an output pin.
  2. Step 2: Analyze loop function behavior

    The LED on pin 13 turns HIGH (on), waits 1 second, then LOW (off), waits 1 second, repeating.
  3. Final Answer:

    The built-in LED on pin 13 will blink on and off every second. -> Option A
  4. Quick Check:

    Pin 13 output toggles every 1s [OK]
Hint: Pin 13 blinking means HIGH and LOW with delay [OK]
Common Mistakes:
  • Confusing delay units (milliseconds vs seconds)
  • Assuming LED stays on without blinking
  • Thinking loop is empty
4. You tried uploading a sketch but got an error saying "avrdude: stk500_recv(): programmer is not responding." What is the most likely cause?
medium
A. The sketch code has syntax errors.
B. The wrong board or port is selected in the Arduino IDE.
C. The USB cable is connected properly and working.
D. The Arduino IDE is not installed.

Solution

  1. Step 1: Understand the error message

    This error means the IDE cannot communicate with the board.
  2. Step 2: Identify common communication issues

    Usually caused by wrong board or port selection or bad connection.
  3. Final Answer:

    The wrong board or port is selected in the Arduino IDE. -> Option B
  4. Quick Check:

    Communication error = wrong board/port selected [OK]
Hint: Check board and port if upload communication fails [OK]
Common Mistakes:
  • Assuming syntax errors cause communication errors
  • Ignoring USB cable connection
  • Thinking IDE installation causes this error
5. You want to upload a sketch to an Arduino Uno but your computer shows multiple COM ports. How do you ensure you upload to the correct port?
hard
A. Disconnect the Arduino, check ports, reconnect it, then select the new port shown.
B. Select any COM port randomly; the IDE will find the board automatically.
C. Upload without selecting a port; the sketch will upload anyway.
D. Restart the Arduino IDE and it will select the correct port.

Solution

  1. Step 1: Identify the correct COM port

    Disconnect Arduino and note available ports, then reconnect and see which port appears.
  2. Step 2: Select the newly appeared port in the IDE

    This port corresponds to the Arduino board for uploading.
  3. Final Answer:

    Disconnect the Arduino, check ports, reconnect it, then select the new port shown. -> Option A
  4. Quick Check:

    New port after reconnect = correct port [OK]
Hint: Unplug and replug board to spot correct COM port [OK]
Common Mistakes:
  • Guessing COM port without checking
  • Assuming IDE auto-selects port
  • Uploading without port selection