I decide that I will need to use 2 DC motors and on the page ( link above ) I find H-bridge and I think that it is good idea for my purpuse . I hope that I will find shop in my city with H-bridge
. Anyway, I want to show you my idea ( I am not sure about it , can I use 4,5V battery or for 2 motors are better 9V )
And what about code ? Is there everything OK ?
const int motor1Pin = 3; // H-bridge leg 1 (pin 2, 1A)
const int motor2Pin = 4; // H-bridge leg 2 (pin 7, 2A)
const int enable1Pin = 8; // H-bridge enable pin (1DC)
const int motor3Pin = 5; // H-bridge leg 3 (pin 15, 3A)
const int motor4Pin = 6; // H-bridge leg 4 (pin 10, 4A)
const int enable2Pin = 9; // H-bridge enable pin (2DC)
int incomingByte;
void setup() {
Serial.begin(9600);
// set all the other pins you're using as outputs:
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(enable1Pin, OUTPUT);
pinMode(motor3Pin, OUTPUT);
pinMode(motor4Pin, OUTPUT);
pinMode(enable2Pin, OUTPUT);
// set enablePin high so that motor can turn on:
digitalWrite(enablePin, HIGH);
digitalWrite(enaglePin, HIGH);
}
void loop() {
if (Serial.available() > 0) {
incomingByte = Serial.read();
// if the switch is high, motor will turn on one direction:
if (incomingByte == "W") { // One direction for both motors
digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low
digitalWrite(motor2Pin, HIGH); // set leg 2 of the H-bridge high
digitalWrite(motor3Pin, LOW); // set leg 3 of the H-bridge low
digitalWrite(motor4Pin, HIGH); // set leg 4 of the H-bridge high
}
else if (incomingByte == "A") { // on the left , one stop , other run
digitalWrite(motor1Pin, HIGH);
digitalWrite(motor2Pin, HIGH);
digitalWrite(motor3Pin, LOW);
digitalWrite(motor4Pin, HIGH);
}
else if (incomingByte == "D") { // on the right , one run , other stop
digitalWrite(motor1Pin, LOW);
digitalWrite(motor2Pin, HIGH);
digitalWrite(motor3Pin, HIGH);
digitalWrite(motor4Pin, HIGH);
}
}
else { // both motors stop
digitalWrite(motor1Pin, LOW);
digitalWrite(motor2Pin, LOW);
digitalWrite(motor3Pin, LOW);
digitalWrite(motor4Pin, LOW);
}
}
I hope that there is no mistake , but for the peace of mind
I'd rather show it to you 