Arduino build error

error: lvalue required as left operand of assignment

An assignment needs a place to store the value on its left: a variable. The left side was something else, such as a number, a constant or a calculation.

  • 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:5:11: error: lvalue required as left operand of assignment
    5 |   LED_PIN = 8;
exit status 1

A single = also sets a value, while == compares, so a mix-up between them can cause it.

Mokxi's compiler, clang, words it as expression is not assignable.

Causes

The 2 usual causes with the fix

1The left side is a #define

A name made with #define is replaced by its text before compiling, so LED_PIN = 8 becomes 13 = 8. Use a variable to change it.

Broken
#define LED_PIN 13

void setup() {
  Serial.begin(9600);
  LED_PIN = 8;
  Serial.println(LED_PIN);
}

void loop() {
}
Fixed
int ledPin = 13;

void setup() {
  Serial.begin(9600);
  ledPin = 8;
  Serial.println(ledPin);
}

void loop() {
}

Mokxi’s build tab says: The left side of = has to be a variable that can change.

Try this fix in Mokxi

2The left side is a calculation

count + 1 is a value, not a place. Assign to the variable itself.

Broken
int count = 1;

void setup() {
  Serial.begin(9600);
  count + 1 = 5;
  Serial.println(count);
}

void loop() {
}
Fixed
int count = 1;

void setup() {
  Serial.begin(9600);
  count = count + 1;
  Serial.println(count);
}

void loop() {
}

Mokxi’s build tab says: The left side of = has to be a variable that can change.

Try this fix in Mokxi

FAQ

Questions and answers

What is an lvalue?

Something that has a place in memory and can sit on the left of =, such as a variable. A number or a calculation is not one.

Is this the same as using = in an if?

No. if (x = 5) compiles and always sets x. This error is for an assignment whose left side cannot be stored to.

How do I change a #define value?

You cannot at run time. Use a variable for anything that changes, and keep #define or const for fixed settings.