FIX: Arduino was not declared in this scope error

Vlad Turiceanu
by Vlad Turiceanu
Passionate about technology, Windows, and everything that has a power button, he spent most of his time developing new skills and learning more about the tech world. Coming from a solid background in PC... Read more
Affiliate Disclosure
  • Several Arduino users get the error was not declared in this scope. Do you face the same when trying to compile your code?
  • The program can't find the definition of your variable. Declare it before using it elsewhere.
  • To make sure that you're always prepared, don't hesitate to bookmark our Arduino errors section.
  • Visit our Developer Tools Hub for more development & IT-related software solutions.
Arduino error was not declared in this scope
To fix various PC problems, we recommend DriverFix:
This software will keep your drivers up and running, thus keeping you safe from common computer errors and hardware failure. Check all your drivers now in 3 easy steps:

  1. Download DriverFix (verified download file).
  2. Click Start Scan to find all problematic drivers.
  3. Click Update Drivers to get new versions and avoid system malfunctionings.
  • DriverFix has been downloaded by 0 readers this month.

Arduino users often face the same error – was not declared in this scope – when trying a code they’ve made.

Let us help you out if you happen to be new to Arduino coding as well. When you get this annoying error while compiling your code, there are a few quick fixes to apply.

How can I fix Arduino error was not declared in this scope?

1. Always declare a variable before assigning a value to it

remember to declare a variable

Are you seeing the number was not declared in this scope error? Then, the problem most likely resides in not declaring the number variable to begin with.

A variable in Arduino is a place to store a piece of data, with a name, a value, and a type. Most people tend to use the variable number in their loop function.

However, they need to define a variable before they use it elsewhere.

2. Make sure the loop is not missing its closing brace

was not declared in this scope

If the same error keeps coming up even after creating a variable and giving it a value, pay more attention to the little things.

Even without a simple accolade, the compiler gets mixed signals since the loop is not closed and may give you these errors in return.

Things are no different for extra semicolons or functions that are not defined properly.

3. Comment the Serial1 if you use Arduino Uno

using Arduino Uno

In case of getting the Serial1 was not declared in this scope error, chances are your Arduino has no Serial1.

Assuming that you use Arduino Uno, you need to comment the Serial1 and un-comment the SoftwareSerial part in order to solve the problem.

Have you tried to apply the above tricks? Let us know if they proved to be helpful in solving the Arduino error was not declared in this scope.

If you know any other working solutions, feel free to share them by using the comments area below.

Frequently Asked Questions

  • The Arduino language is best described as a set of C/C++ functions.

  • The open-source Arduino Software is often used to write code in Arduino. The environment is based on Processing and runs on both Windows and Mac OS.

  • The Arduino error that you are getting is most likely a sign that you need to define the variable before assigning a value to it. The steps from this quick guide will help you out.

This article covers:Topics: