Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.
Compile error · syntax

Fix “expected unqualified-id before '{' token”

Code is sitting outside any function — usually a semicolon after void setup() or a stray brace. Remove the ; after the function header and check braces.

All boardsUpdated 3 Nov 2026

Community draft — report a mistake

What you see

OutputOutput
Blink.ino:2:1: error: expected unqualified-id before '{' token
 {
 ^
exit status 1

Compilation error: expected unqualified-id before '{' token

The top level of a sketch can only contain declarations. “Expected unqualified-id” means the compiler, outside of any function, met something that can’t start a declaration — most often a { left behind by a stray semicolon.

void setup();      // WRONG: the ; ends the line, the block below is orphaned
{
  pinMode(13, OUTPUT);
}

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

Quick fix — try in order

  1. 1

    Remove the semicolon after the function header

    void setup(); followed by { declares the function and leaves the { … } block floating. Write void setup() {.

  2. 2

    Look for code outside setup() and loop()

    Only declarations (variables, objects, functions, #include, #define) may sit at the top level. A digitalWrite() or if between functions gives this error.

  3. 3

    Count the braces

    An extra } earlier closes a function too soon, so the next lines are “outside” it. Ctrl+T (Auto Format) makes the mismatch visible.

  4. 4

    Check the quoted token

    before 'if', before 'for' or before 'return' means a statement at the top level; before numeric constant often means a #define name clashing with a variable.

Why it happens

What is an unqualified-id?

A plain name, like a variable or function name. At the top level the compiler expects a declaration to start with a type and a name — and found { or a statement instead.

Variant: “expected unqualified-id before numeric constant”

#define LED 13 and later int LED = 13; becomes int 13 = 13;. Use const int LED = 13; instead of #define, or rename one.

Pasted code from a website

Snippets often show only the body of loop(). Paste them inside the braces of an existing function.

Board-specific notes

Related: An extra brace gives expected declaration before '}' token; a missing one gives expected '}' at end of input.

↑↓ to move · Enter to open