RC+Arduino+Tank/skid Steering/Differential Steering

Howdy folks !

First time poster and really only doing this to help out anyone in a similar situation.
Basically i am building a RC dozer ( scratch build 50kg ) and after going down the Sabertooth dual motor controller route decided that a PWM setup (Arduino) would be better for the low speed operation without having to gear down the motors any further. So i purchased all the Elegoo starter kit , went through a load of basic programming tutorials, but couldn’t for the life of me find a suitable code for my setup. After countless searches i have put together the following code. basically i only want the Arduino running the drive motors and maybe later the lights and sound when i get around to it. all the servos for the hydraulics can go direct to the RX receiver.

My setup is as follows:

Open TX TX16s transmitter (2 channels for drive motors)
10ch receiver
Arduino Uno (Elegoo starter kit)
Cytron MDD10A Dual Motor Driver (PWM input)
2x24v brushed DC motors with 1:72 planetary gearboxes
7s LiPo at 24 v

Code:

int dir1 = 7;
int dir2 = 4;
//the following are all ~PWM capable ports
int pwm1 = 6;
int rc_channel4 = A0;
int pwm2 = 5;
int rc_channel2 = A1;
void setup() {

TCCR0B = TCCR0B & B11111000 | B00000010; // for PWM frequency of 7812.50 Hz (Output pins 5,6)
pinMode(rc_channel4, INPUT);
pinMode(dir1, OUTPUT);
pinMode(pwm1, OUTPUT);
pinMode(rc_channel2, INPUT);
pinMode(dir2, OUTPUT);
pinMode(pwm2, OUTPUT);
Serial.begin(9600);
}

void loop() {

int pwmA = 0;
int rc4 = pulseIn(rc_channel4, HIGH, 35000);
int pwmB = 0;
int rc2 = pulseIn(rc_channel2, HIGH, 35000);

Serial.print(" raw channel4: “);
Serial.print(rc4);
Serial.print(” raw channel2: ");
Serial.print(rc2);
delay(100);

if (rc4<1450 && rc4>1400) {
Serial.println(" stick centered");
analogWrite(pwm1, 0);

}
if (rc2<1450 && rc2>1400) {
Serial.println(" stick centered");
analogWrite(pwm2, 0);
}
if(rc4 > 1450){ //right stick
pwmA = map(rc4, 1450, 1910, 0, 255); //map our speed to 0-255 range
digitalWrite(dir1, LOW);
analogWrite(pwm1, pwmA);
pwmA = constrain(pwmA,0,255);
Serial.print(" right stick speed: “);
Serial.println(pwmA);
}
if(rc2 > 1450){ //left stick
pwmB = map(rc2, 1450, 1910, 0, 255); //map our speed to 0-255 range
digitalWrite(dir2, HIGH);
analogWrite(pwm2, pwmB);
pwmB = constrain(pwmB,0,255);
Serial.print(” left stick speed: ");
Serial.println(pwmB);
}
if(rc4 < 1400){
pwmA = map(rc4, 1400, 920, 0, 255); //map our speed to 0-255 range

digitalWrite(dir1, HIGH);
analogWrite(pwm1, pwmA);
pwmA = constrain(pwmA,0,255);
Serial.print(" right stick speed: ");
Serial.println(pwmA);
}
if(rc2 < 1400){
pwmB = map(rc2, 1400, 920, 0, 255); //map our speed to 0-255 range

digitalWrite(dir2, LOW);
analogWrite(pwm2, pwmB);
pwmB = constrain(pwmB,0,255);
Serial.print(" left stick speed: ");
Serial.println(pwmB);
}

delay(10);
}

I raised the frequency of the PWM to remove the high pitch whine and increase driver efficiency but not necessary. I have this working on my desktop (image) and its working as i would want. once its installed i may have to tweak the steering inputs but generally its a good starting point.

hope it helps !

Rob

@originalrob

Could you also take a few moments to Learn How To Use The Forum.

Then you will at least know how to post code and avoid the wrath of other users. ;D

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.