Professional Documents
Culture Documents
int in1 = 2;
int in2 = 3;
int Enable = 4;
int Switch = 5;
void setup()
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(Enable, OUTPUT);
pinMode(Switch, INPUT_PULLUP);
void loop()
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
int a;
a = digitalRead(Switch);
if(a == 0)
digitalWrite(Enable, HIGH);
}
else
digitalWrite(Enable, LOW);
}
DC motor forward reverse
const int pwm = 2 ; //initializing pin 2 as pwm
void setup()
pinMode(in_2,OUTPUT) ;
void loop()
digitalWrite(in_1,HIGH) ;
digitalWrite(in_2,LOW) ;
analogWrite(pwm,255) ;
delay(3000) ;
//For brake
digitalWrite(in_1,HIGH) ;
digitalWrite(in_2,HIGH) ;
delay(1000) ;
digitalWrite(in_1,LOW) ;
digitalWrite(in_2,HIGH) ;
delay(3000) ;
//For brake
digitalWrite(in_1,HIGH) ;
digitalWrite(in_2,HIGH) ;
delay(1000) ;
}
Setup
6. Connect the Arduino using Arduino USB cable and upload the program to the
Arduino using Arduino IDE software.
7. Provide power to the Arduino board using power supply, battery or USB cable.