'…' was not declared in this scope

  • Arduino C++
  • ESP32
  • ESP8266

You may see

error: 'ledPin' was not declared in this scope
error: 'pinmode' was not declared in this scope
error: 'high' was not declared in this scope
error: 'buttonState' was not declared in this scope; did you mean 'button_state'?

Why it happens

  • A spelling or capital-letter mistake: pinmode for pinMode, high for HIGH.
  • The variable was never created, or was created inside another function's { }.
  • The library that defines the word is missing.
  • The code is for a different board or a different library version.

How to fix it

  1. Read the word in quotes. Check it letter by letter, including capitals.
  2. If it's your own variable, create it at the top of the sketch, for example int ledPin = 13;.
  3. If the message says "did you mean", it's usually right.
  4. If it's a command from a library, check the #include line and that the library is installed.

It worked if: Verify passes.

Seen in a real run (some lines are close variants of it). Produced with Arduino CLI 1.5.1 and Arduino AVR core 1.8.8 (the same compiler the Arduino IDE uses).

Didn't help? Search another error or ask us.