# Push button and motor

**URL:** <https://discourse.processing.org/t/push-button-and-motor/11680>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [May 29, 2019, 2:07pm UTC](https://discourse.processing.org/t/push-button-and-motor/11680 "2019-05-29T14:07:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![S.L.C.S](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@S.L.C.S](https://discourse.processing.org/u/S.L.C.S)\
**Post date:** [May 29, 2019, 2:07pm UTC](https://discourse.processing.org/t/push-button-and-motor/11680/1 "2019-05-29T14:07:22Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [May 29, 2019, 3:35pm UTC](https://discourse.processing.org/t/push-button-and-motor/11680/2 "2019-05-29T15:35:08Z")

</div>

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.

> **[Arduino Forum](https://forum.arduino.cc/)**

* * *

> [@S.L.C.S](#):
>
> I was asked to create an Arduino program

add  
?who asked you to write arduino programs?

---

<div class="post-metadata">

**Author:** ![S.L.C.S](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@S.L.C.S](https://discourse.processing.org/u/S.L.C.S)\
**Post date:** [May 29, 2019, 3:37pm UTC](https://discourse.processing.org/t/push-button-and-motor/11680/3 "2019-05-29T15:37:53Z")

</div>

Sorry for that. I won’t next time.

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [May 30, 2019, 11:56am UTC](https://discourse.processing.org/t/push-button-and-motor/11680/4 "2019-05-30T11:56:20Z")

</div>

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 !
