Circuit 28 00.00.01
By Charlescsj123Arduino DC Motor controller using H- Bridge
// 00.00.02
const int buttonPin = 2; // Forward button
const int buttonPin1 = 4; // Rev Motor
const int ledPin = 13; // Forward Motor on
const int ledPin1 = 12; // Rev Motor
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int buttonState1= 0;
void setup() {
// initialize the Motor pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
// initialize the pushbutton pins as an inputs
pinMode(buttonPin, INPUT);
pinMode(buttonPin1,INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
buttonState1 = digitalRead(buttonPin1);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn Motor on:
digitalWrite(ledPin, HIGH);
if (buttonState1 == HIGH)
digitalWrite(ledPin1, HIGH);
}
else {
// turn Motor off:
digitalWrite(ledPin, LOW);
digitalWrite (ledPin1, LOW);
}
}