Could someone helping me understanding my code?

i am trying to do a automatic door using a arduino and i have made the code. i am new to arduino and this is my first code so i dont know if it well written but i would like to know what does the error message " assignment of read-only variable ‘MotorPin1’ ". if someone could help me understand the error and help me fix it i would be very thankfull. i attached my code but if that doesnt work here it is.

const int SensorPin = 2;
const int EndCourse1Pin = 3;
const int EndCourse2Pin = 4;
const int Motor1Pin = 8;
const int Motor2Pin = 9;

int SensorReading = 0;
int EndCourse1Read = 0;
int EndCourse2Read = 0;

void setup() {
// put your setup code here, to run once:
pinMode (SensorPin, INPUT);
pinMode (EndCourse1Pin, INPUT);
pinMode (EndCourse2Pin, INPUT);
pinMode (Motor1Pin, OUTPUT);
pinMode (Motor2Pin, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
SensorReading = digitalRead(SensorPin);

if (SensorReading == 1);
digitalWrite(Motor1Pin = HIGH);
digitalWrite(Motor2Pin = HIGH);

EndCourse1Read = digitalRead(EndCourse1Pin);
EndCourse2Read = digitalRead(EndCourse2Pin);

if (EndCourse1Read == 1);
digitalWrite(Motor1Pin = LOW);
if (EndCourse2Read == 1);
digitalWrite(Motor2 = LOW);

delay(3000);

digitalWrite(Motor1Pin = HIGH);
digitalWrite(Motor2Pin = HIGH);
}

Automatic_Door.ino (881 Bytes)

Where you have:

digitalWrite(Motor1Pin = HIGH);

You probably want:

digitalWrite(Motor1Pin, HIGH);

This is wrong

digitalWrite(Motor1Pin = HIGH);

it should be

digitalWrite(Motor1Pin, HIGH);

…R

PS … To make it easy for people to help you please use the code button </>

so your code looks like this

and is easy to copy to a text editor. See How to use the Forum

it worked thanks its my first time.

But once you fix that, you will have problems with lines like this:

if (EndCourse1Read == 1);

They won't give compile errors, but won't do what you expect. You need to lose the ; on the end, which prematurely terminate the command so the next line isn't carried out even when the "if" works.

You want them to look like this:

if (EndCourse1Read == 1)  // no ; here
  digitalWrite(Motor1Pin, LOW);

I in fact always use { and } even if there is only 1 line:

if (EndCourse1Read == 1)  // no ; here
  {
  digitalWrite(Motor1Pin, LOW);
  }