Arduino “expected ‘;’ before” and “expected ‘}’ at end of input”

The compiler reports the line where it noticed the problem, which is often one line after the mistake. Look at the line above the one it names.

What the message means

A missing semicolon or brace is only noticed when the next token appears. So “expected ‘;’ before X” points at X, but the missing mark is just before it.

Fix it in this order

  1. Open the line named in the message, then read the line above it for a missing semicolon.
  2. Count braces. Every opening brace needs a closing one. The IDE highlights the partner when you click next to a brace.
  3. Use Tools > Auto Format. Odd indentation shows where a brace is missing.
  4. Check that every statement inside a function ends in a semicolon and that a class or struct ends with }; .
  5. Look for a stray character pasted from a web page, such as a curly quote.
  6. Comment out code in halves until the error disappears, to find the block that causes it.

Why it happens

C and C++ end a statement at a semicolon and end a block at a closing brace. When the compiler finds a token it cannot accept, it reports an error at that token. The missing semicolon or brace is almost always earlier, because the parser only recognises the problem on reaching the next token. That is why the reported line can be the line after the real mistake.

Struct and class definitions need a semicolon after their closing brace, which is a frequent cause of this message. A #define is plain text substitution, so a trailing semicolon can break the expression that uses it. Code pasted from a web page may contain curly quotes or other characters the compiler does not accept. Brace matching in the editor helps locate the gap quickly.

If you see this, do this

You seeDo this
Error at the last lineA closing brace is missing somewhere above.
Error after a #defineDo not end a #define with a semicolon unless you need one.
Error after pasting codeReplace curly quotes with straight quotes.

Confirm the fix

  1. Go to the reported line, then move up one line and confirm the statement above ends with a semicolon.
  2. Place the cursor beside each brace in the editor and confirm every opening brace has a matching closing brace.
  3. Comment out half the sketch, compile, and keep narrowing; the half whose removal clears the error holds the fault.

Common mistake: Assuming the line the compiler names is the one to edit, when the missing semicolon or brace is usually on the line above.

was not declared in this scope, Arduino IDE setup.

Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.