2

Ignore direction of the motors(for now).

This is my connection diagram. Any and all improvements to this are welcome.

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 enter image description here

Code for running the below setup:

 
// 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 change to the code is also welcome.

1 Answers1

2

Pins 7 and 8 aren't PWM pins on the UNO. So when you call analogWrite on them with a value greater than 127 it defaults to digitalWrite and just writes those pins HIGH. Pins 6 and 9 are PWM pins, so they are responding as expected to the analogWrite. Since they are outputting PWM and the signal to the other motors is constantly high, they run slower.

You should change your wiring so that all of the enable pins are connected to PWM capable pins. On the Arduino UNO those are pins 3, 5, 6, 9, 10, and 11.

Delta_G
  • 3,391
  • 2
  • 13
  • 24