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.