Arduino build error

error: void value not ignored as it ought to be

A function declared void gives nothing back. The code tried to store or test what it returned.

  • Build error
  • 2 common causes
  • Seen 487 times in failed builds on Mokxi in the 30 days to November 16, 2026.
The message

What the Arduino IDE prints

Output window
sketch.ino: In function 'void setup()':
sketch.ino:6:15: error: void value not ignored as it ought to be
    6 |   int total = work();
exit status 1

Either change the function to return a value, or stop using its result.

Mokxi's compiler, clang, words it as initializing int with an expression of incompatible type void.

Causes

The 2 usual causes with the fix

1The result of a void function is stored

Declare the function with the type it returns, and add a return line.

Broken
void work() {
  Serial.println("working");
}

void setup() {
  Serial.begin(9600);
  int total = work();
}

void loop() {
}
Fixed
int work() {
  Serial.println("working");
  return 3;
}

void setup() {
  Serial.begin(9600);
  int total = work();
  Serial.println(total);
}

void loop() {
}

Try this fix in Mokxi

2A void call is used as a condition

Serial.begin() returns nothing, so it cannot be tested. Check the thing you actually care about, such as the port being ready.

Broken
void setup() {
  Serial.begin(9600);
  if (Serial.begin(9600)) {
    Serial.println("open");
  }
}

void loop() {
}
Fixed
void setup() {
  Serial.begin(9600);
  if (Serial) {
    Serial.println("open");
  }
}

void loop() {
}

Try this fix in Mokxi

FAQ

Questions and answers

What does void mean?

It means returns nothing. A void function does its work and gives no value back.

How do I return a value?

Put the type before the name, such as int work(), and end the function with return value;.

Which Arduino calls return nothing?

Many do: pinMode, digitalWrite, delay and Serial.begin. Their effect is the point, not a value.