Push button and motor

I was asked to create an Arduino program which uses a push button to start and stop a DC motor.

int buttonPin1 = 2; //Start button
int buttonPin2 = 3; //Stop button 
int buttonStatus1 = 0; 
int buttonStatus2 = 0; 
int motorPin = 9;

void setup() { 
pinMode(motorPin, 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 


if (buttonStatus1 == LOW && buttonStatus2 == HIGH) { // if stop button is pressed (AND the start off) 
digitalWrite(motorPin, LOW); // turn the motor OFF 

}
}
}
              

The above is currently what i have so far. I need help checking if it works.

if that works with your connected hardware you have to test,

but you not even report any result or even any problem.


and again, this forum is the wrong place.


add
?who asked you to write arduino programs?

1 Like

Sorry for that. I won’t next time.

Hey there!

Assuming that you got your wiring correct seems like tour digitalWrite is the wrong as you want to turn off the motor when it’s on but your not doing that no state is being changed just flip your digitalWrite to Low in high and to high where it is low !

1 Like