Ignore direction of the motors(for now).
This is my connection diagram. Any and all improvements to the connections are welcome.
PS: I really cant change any of the components present here, due to material, financial and time constraints.
Bottom left motor seems to run at 210-224 rpm
Bottom right motor runs at 160-180 rpm
Top right motor runs at 210-224 rpm
Top left motor runs at 160-180 rpm
Code:
// Motor A connections
int enA = 7;
int in1 = 4;
int in2 = 5;
// Motor B connections
int enB = 6;
int in3 = 3;
int in4 = 2;
//Motor c
int enC = 9;
int in5 = 12;
int in6 = 13;
// Motor d connections
int enD = 8;
int in7 = 10;
int in8 = 11;
void setup() {
// Set all the motor control pins to outputs
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(enC, OUTPUT);
pinMode(enD, OUTPUT);
pinMode(in5, OUTPUT);
pinMode(in6, OUTPUT);
pinMode(in7, OUTPUT);
pinMode(in8, OUTPUT);
// Turn off motors - Initial state
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
digitalWrite(in5, LOW);
digitalWrite(in6, LOW);
digitalWrite(in7, LOW);
digitalWrite(in8, LOW);
}
void loop() {
moveForward();
delay(3000);
motorOff();
delay(1000);
}
void moveForward(){
analogWrite(enA, 200);
analogWrite(enB, 200);
analogWrite(enC, 200);
analogWrite(enD, 200);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
digitalWrite(in5, HIGH);
digitalWrite(in6, LOW);
digitalWrite(in7, HIGH);
digitalWrite(in8, LOW);
}
void motorOff(){
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
digitalWrite(in5, LOW);
digitalWrite(in6, LOW);
digitalWrite(in7, LOW);
digitalWrite(in8, LOW);
}
Any changes to the code are also welcome
type or paste code here
EDIT: Tried this simulation in the real world, with a raspberry pi model 4B, and the corresponding python code, Worked almost successfully(3 motors worked, i suspect the 4th one didnt receive as much current to start), and in return fried my raspberry pi.
