DigitalWrite error | lvalue required as left operand of assignment

Pls help,
Im trying to get a output on my arduino NANO with the digitalwrite.
but it gives my this error, only on output.
lvalue required as left operand of assignment
digitalWrite (3 = LOW);

this should put the output on pin D3 off, right?

what am i doing wrong

please help

btw: the commentary is in dutch...

int motor1 = 2;             //output (links)
int motor2 = 3;            //output  (rechts)
int hoofdschakelaar =12;  //input
int stop1 = 7;           //links stopknop
int stop2 = 8;          //rechts stopknop
int links = 9;         //naar links
int rechts = 10;      //naar rechts
int ledgroen = 4;
int ledrood = 5;
int ledblauw = 6;

void setup() {
  
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(hoofdschakelaar, INPUT);
  pinMode(stop1, INPUT);
  pinMode(stop2, INPUT);
  pinMode(links, INPUT);
  pinMode(rechts, INPUT);
}

void loop() {

  if (hoofdschakelaar = 1) {
      digitalWrite (4, HIGH);    //GROENE LED
      digitalWrite (5, LOW);     //RODE LED
    
      digitalWrite (2 = HIGH); //motor 1 aan
      digitalWrite (3 = LOW); //motor 2 uit
      if (stop1 = 1){
      digitalWrite (2 = LOW);
      digitalWrite (3 = HIGH);
     }
      if (stop2 = 1){
      digitalWrite (2 = HIGH);
      digitalWrite (3 = LOW);
     }
      if (stop2 = 0){
      digitalWrite (2 = LOW);
      digitalWrite (3 = LOW);
      delay(10800000);         //3uur wachten
     }
     digitalWrite (4, LOW);   //GROENE LED
     digitalWrite (5, HIGH);   //RODE LED
     }
 
  
  
  if (links = 1) {
      digitalWrite (4, HIGH);    //GROENE LED
      digitalWrite (5, LOW);     //RODE LED
     
      digitalWrite (2, HIGH);
      digitalWrite (3, LOW);
  if (stop1 = 1){
      digitalWrite (2 = LOW);
      digitalWrite (3 = HIGH);
  }
     if (stop1 = 0){
      digitalWrite (2 = LOW);
      digitalWrite (3 = LOW);
     }
     digitalWrite (4, LOW);   //GROENE LED
     digitalWrite (5, HIGH);   //RODE LED
  }
  

  
  if (rechts = 1) {
      digitalWrite (4, HIGH);    //GROENE LED
      digitalWrite (5, LOW);     //RODE LED
    
      digitalWrite (2, LOW);
      digitalWrite (3, HIGH);
  if (stop2 = 1){
      digitalWrite (2 = HIGH);
      digitalWrite (3 = LOW);
  }
     if (stop2 = 0){
      digitalWrite (2 = LOW);
      digitalWrite (3 = LOW);
     }
    digitalWrite (4, LOW);   //GROENE LED
    digitalWrite (5, HIGH);   //RODE LED
  }
  

  
//  if (links = 1 && rechts = 1) {        // 1 keer cyclus 
//      digitalWrite (4, HIGH);    //GROENE LED
//      digitalWrite (5, LOW);     //RODE LED
//    
//      digitalWrite (2 = HIGH); //motor 1 aan
//      digitalWrite (3 = LOW); //motor 2 uit
//     if (stop1 = 1){
//      digitalWrite (2 = LOW);
//      digitalWrite (3 = HIGH);
//   }
//      if (stop2 = 1){
//      digitalWrite (2 = HIGH);
//      digitalWrite (3 = LOW);
//   }
//     if (stop2 = 0){
//      digitalWrite (2 = LOW);
//      digitalWrite (3 = LOW);
//   }
//    digitalWrite (4, LOW);   //GROENE LED
//    digitalWrite (5, HIGH)   //RODE LED
//  }




}

Welcome to the forum

Wrong

You probably meant

digitalWrite(3, LOW);

thank you soooooo much!!!
I didnt notice,
im sorry ,
thank you sir!

Notice how this does not give an error

but this does

What's the difference between the one that works and the one that does not?

As a reference,

https://www.arduino.cc/reference/en/language/functions/digital-io/digitalwrite/

Not to mention that what the compiler is actually telling is that

3 = LOW

is trying to assign 'LOW' (which equals '0' at the moment by definition) to '3' and you are required to have the left operant (in your case the '3' as what is called an 'lvalue' basically it has to be a variable or a RAM address that is being pointed to.

Two issues here:

  1. '=' is an assignment, '==' is comparison

  2. hoofdschakelaar is an input pin number. Did you intend this?

    if (digitalRead(hoofdschakelaar) == HIGH) {

    You need to correct this for all of your inputs.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.