#define Enable1 9 // PWM pin connects to Enable 3,4 driver pin #define IN1 4 // digital pin connects to input 3 #define IN2 2 // digital pin connects to input 4 #define CW_BT 6 // connect to first button #define CCW_BT 7 // connect to second button int Forward; // define a variable to save first button state int Revers; // define a variable to save sec button state void setup() { pinMode(Enable1,OUTPUT); //define Enable pin as output pin pinMode(IN1,OUTPUT); //define input3 pin as output pin pinMode(IN2,OUTPUT); //define input4 pin as output pin pinMode(CW_BT,INPUT); //define Button 1 pin as input pin pinMode(CCW_BT,INPUT); //define Button 2 pin as input pin analogWrite(Enable1, 255); // Moves motor at maximum speed } void loop() { Forward = digitalRead(CW_BT); //Read button1 status Revers = digitalRead(CCW_BT); //Read button2 status if(Forward ==1){ //If Button 1 pressed moves motor clockwise digitalWrite(IN1,LOW); // input3 is 1 and input 4 is 0 to move CW digitalWrite(IN2,HIGH); // delay(2000); //moves for 2 second then leave the loop } if(Revers ==1){ //If Button2 pressed moves motor counterclockwise digitalWrite(IN1,HIGH); // input4 is 1 and input 3 is 0 to move CCW digitalWrite(IN2,LOW); delay(2000); //moves for 2 second then leave the loop } else{ //if no buttons pressed the motor will not moves digitalWrite(IN1,LOW); digitalWrite(IN2,LOW); }}