0Pricing
Arduino & IoT Academy · Lesson

setup() Runs Once

The startup block where you prepare pins and serial.

setup() Runs Once is a free Arduino & IoT Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Arduino & IoT Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Two Blocks, Every Sketch

Every Arduino program is built from two functions. The first one is setup(), and getting it right makes everything else click. 🙂

Runs Exactly Once

The big idea: setup() runs a single time, right after your board powers on or resets. It never repeats on its own.

What setup() Looks Like

It is a function with empty parentheses and curly braces. Everything you write between those braces is your startup code.

void setup() {
  // startup code goes here
}

Why void?

The word void means setup returns no value. You are just running commands, not handing a result back to anyone.

Prepare Your Pins

setup is where you announce how each pin behaves. Use pinMode() once here so the board knows a pin sends or receives signals.

void setup() {
  pinMode(13, OUTPUT);
}

Open the Serial Channel

Talking to your computer also starts here. Serial.begin() opens the USB link once, ready for messages later.

void setup() {
  Serial.begin(9600);
}

One-Time Jobs Only

Put things here that should happen a single time: setting pin modes, starting Serial, or initializing a sensor. Setup is your launch checklist.

It Runs First, Always

No matter what else is in your sketch, setup() always runs before any repeating logic. It is the very first thing the board does.

Reset Triggers It Again

Press the board's reset button or cut and restore power, and setup() fires once more. A fresh start means a fresh setup.

Combine Several Lines

You can stack many one-time tasks inside setup. The board runs them top to bottom, then moves on for good.

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

Empty Is Still Valid

A sketch can have an empty setup() if nothing needs preparing. The braces must still be there, even with nothing inside.

void setup() {
}

Quick Check

Let's test how setup() behaves.

Recap: setup()

You learned that setup() runs once at startup, returns void, and is where you prepare pins and Serial. It is your board's launch checklist. 🎉

Frequently asked questions

Is the “setup() Runs Once” lesson free?

Yes — the full text of “setup() Runs Once” is free to read here on the web, and the Arduino & IoT Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Arduino & IoT Academy course, upgrade to CoddyKit PRO.

What will I learn in “setup() Runs Once”?

The startup block where you prepare pins and serial. You practise Arduino & IoT Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Arduino & IoT Academy?

No prior experience is required. Arduino & IoT Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “setup() Runs Once” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Arduino & IoT Academy lesson?

Yes. Every Arduino & IoT Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. setup() Runs Once
  2. loop() Runs Forever
  3. Comments & Clean Sketches
  4. Compile Errors & How to Read Them
← Back to Arduino & IoT Academy