dont understand how to fix this

Hi, im trying to make a simple push button on/off motor. so when i push 1 button the motor and a green led turn on, when i push the other button the motor and green led turn of, and a red led turns on. im using just a small dc motor. the error i keep getting is that the "motorPin was not declared in this scope" please help i have been trying to figure this out and nothing i've done has fixed it. here's the code.

int buttonPin1 = 2; //Start button
int buttonPin2 = 3; //Stop button
int greenLedPin = 6;//green led start status int
int redLedPin = 7; //red led stop status int motorPin = 9; // the motor's pin
int buttonStatus1 = 0;
int buttonStatus2 = 0;

void setup() {
pinMode(motorPin, OUTPUT);
pinMode(greenLedPin, OUTPUT); pinMode(redLedPin, OUTPUT);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
}
void loop() {
buttonStatus1 = digitalRead(buttonPin1);
buttonStatus2 = digitalRead(buttonPin2);

if (buttonStatus1 == HIGH && buttonStatus2 == LOW) { // if the start button is pressed (AND stop button not) digitalWrite(motorPin, HIGH);// turn the motor ON
digitalWrite(greenLedPin, HIGH); //turn the green led indicator ON
digitalWrite(redLedPin, LOW); //turn the red led indicator OFF }

if (buttonStatus1 == LOW && buttonStatus2 == HIGH) { // if stop button is pressed (AND the start off)
digitalWrite(motorPin, LOW); // turn the motor OFF
digitalWrite(greenLedPin, LOW); //turn the green led indicator OFF
digitalWrite(redLedPin, HIGH); //turn the red led indicator ON
}
}

one starts with CTRL-T in the IDE to autoindent the code for readability

Then one post it on the forum with code tags so people on the forum can read it

you need to check this line

int redLedPin = 7; //red led stop status int motorPin = 9; // the motor's pin

your problem is here:

IcyBlade:
int redLedPin = 7; //red led stop status int motorPin = 9; // the motor's pin

by writing it this way you inadvertedly commented out you motorPin declaration. instead you should have written it in 2 lines ie.:

int redLedPin = 7; //red led stop status
int motorPin = 9; // the motor's pin

sherzaad:
by writing it this way you inadvertedly commented out you motorPin declaration

I doubt he wrote anything.. A cut'n paste from the web which went wrong! :wink:

"motorPin was not declared in this scope"

Compiler errors are not always clear.

Variables are "declared" then "defined".
This error is telling you that and more.
Variable "motorPin" was not declared is the part of the error message.
The second part - which may look superficial and /or misleading, is additionally telling you where the variable usage is and is missing.

Compiler errors are part of the troubleshooting process and it is up to programmer to use the error messages to identify the actual problem.

But asking for "more eyes" to find the problem is OK, however, when doing so you should use all the help compiler can give you - activate "verbose" compiler output , outputting ALL - errors and warnings messages, adding "line numbers " to you code, and , mainly - post all the compiler output - memory is cheap!.

No matter how this happened, you have just experienced ONE common challenge in programming - typo error - by having line of code accidentally misplaced AFTER the // comment.

"stuff" happens in real world.