Published on

Arduino Errors - A Guide

Authors
  • avatar
    Name
    Tinker Assist
    Twitter

The Arduino Integrated Development Environment is where Arduino programmers go to compile and upload code. The output terminal is where code compile and upload will come to a hault and your cryptic error will be presented in bright red text. Let's list some of the most common and talk about why they keep coming up.

Failed uploading: no upload port provided

You likely do not have your arduino plugged in, or you have not selected a COM port!

To check, navigate here in your arduino IDE

image 1

If you don't have any devices plugged in, the "Select Other Board and Port" will look like this

image 2

Compilation error: 'x' was not declared in this scope

You are setting the value for a variable that does not exist, or trying to call a function that does not exist. Here are some examples

Example 1

The code below produces this exact error. This is because we are setting the value of variable 'x' to equal 1, but we need a variable declaration before setting the value like this. At present, there is no data type specified!

void setup() {
  // put your setup code here, to run once:
  x = 1;
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(100);
}

We can fix it by adding 'int x;' to the top of the file, or adding 'int' before x to declare the variable in the setup function.

Example 2

With the below code we will get the error "Compilation error: 'Delay' was not declared in this scope"

void setup() {
  // put your setup code here, to run once:
  int x = 1;
}

void loop() {
  // put your main code here, to run repeatedly:
  Delay(100);
}

This is because 'Delay' is an undefined function (we are really looking for 'delay' here, which is a predefined arduino function).

undefined reference to `setup'

(This also includes undefined reference to 'loop')

void setup() and void loop() are two functions that MUST be defined in Arduino code! If not, we'll get this error. If you are not sure why these functions are important, I suggest checking out Arduino introductory material on their website as it covers this.

expected ;

Make sure to add a semicolon to the end of each line of code! Arduino is based on the C++ language, which follows this same strict syntax.

expected } or expected {

You have mismatched curly braces. Often stemming from a function definition, a for loop, while loop, or if statement. The best solution is to add the bracket wherever the error suggests one should be and try to recompile.

Question mark symbols, squares, and other special characters printed to serial monitor

This is a more unique error than those listed above, but is incredibly common amongst those using Arduino IDE's integrated serial monitor. This is commonly due to a mismatched baud rate between the 'Serial.begin' call and the serial monitor.

Example

imagee

Above, we are expecting to see "Hello, World!" periodically printed in the serial monitor, but instead we get all kinds of special characters printed on the screen. This is caused by Serial.begin setting the output baud rate to 9600 and the serial monitor sampling the input at 4800 baud.

See how this code works when the baud rates match:

imagee