RC Car Controlled with H bridge and Radio link controller

Hi,

I'm a beginner at this stuff so please go easy on me.
I have a project I'm working on to help me learn more.

the idea is fairly basic I want to control an RC car with a radio link controller (T8S)
these controller inputs are read in and remapped to a value between 0-255
also depending on the direction I update 2 variables to change my outputs to the H bridge (forwards and backwards pins)

H bridge model: SN754410 Quad Half H-Bridge Motor Driver 1A (L293D compatible)

I have a 6V battery pack I am using to control the motors through the H bridge

I am using these motors

LP Motor FF-180SH-3340 Motor DC 1.5-5V

my setup looks very similar to this. but I also have 2 channels from the controller hooked up to A0 and A1 (and being powered and grounded by the Arduino)

Here is my code. It's not finished yet I want to test forwards and backwards.

I have tested all connections with an LED for what I expect to happen when I move the controller joysticks and everything seems ok.

but instead of getting motor movement, I get a faint buzzing from what sounds like the motors.

any suggestions on where to go from here would be great the 2 guides I have been using are

and

const int CH1_receiver_pin = A1;
const int CH2_receiver_pin = A0;
int CH_Min = 994;
int CH_Max = 1988;
unsigned long pulse_duration1;
unsigned long pulse_duration2;
unsigned int mid_duration_lower = 1400;
unsigned int mid_duration_higher = 1600;
const int forwardpinFL = 13;
const int backwardpinFL = 12;
const int speedpinFL = 11;
const int forwardpinFR = 7;
const int backwardpinFR = 5;
const int speedpinFR = 6;
int changespeed = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(CH1_receiver_pin,INPUT);
  pinMode(forwardpinFL,OUTPUT);
  pinMode(backwardpinFL,OUTPUT);
  pinMode(speedpinFL,OUTPUT);
  pinMode(CH2_receiver_pin,INPUT);
  pinMode(forwardpinFR,OUTPUT);
  pinMode(backwardpinFR,OUTPUT);
  pinMode(speedpinFR,OUTPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  pulse_duration1 = pulseIn(CH1_receiver_pin,HIGH);
  pulse_duration2 = pulseIn(CH2_receiver_pin,HIGH);
  Serial.println("");
  Serial.print("CH1 ");
  Serial.println(pulse_duration1);
  Serial.print("CH2 ");
  Serial.println(pulse_duration2);
  Serial.print("Change speed value ");
  Serial.println(changespeed);
  //Stop
  if (mid_duration_lower < pulse_duration1 && pulse_duration1 < mid_duration_higher && mid_duration_lower < pulse_duration2 && pulse_duration1 < mid_duration_higher){
    digitalWrite(forwardpinFL,LOW);
    digitalWrite(backwardpinFL,LOW);
    analogWrite(speedpinFL,0);
    digitalWrite(forwardpinFR,LOW);
    digitalWrite(backwardpinFR,LOW);
    analogWrite(speedpinFR,0);
    changespeed = 0;
    Serial.println("STOP");
  }

 //direction and speed forwards 
  if (pulse_duration1 < mid_duration_lower && mid_duration_lower < pulse_duration2 && pulse_duration2 < mid_duration_higher){
    changespeed = map(pulse_duration1,mid_duration_lower,CH_Min,0,255);
    digitalWrite(forwardpinFL,HIGH);
    digitalWrite(backwardpinFL,LOW);
    digitalWrite(forwardpinFR,HIGH);
    digitalWrite(backwardpinFR,LOW);
    analogWrite(speedpinFL,changespeed);
    analogWrite(speedpinFR,changespeed);
    Serial.println("Forwards");
  }
  //direction and speed backwards
  if (pulse_duration1 > mid_duration_higher && mid_duration_lower < pulse_duration2 && pulse_duration2 < mid_duration_higher){
    changespeed = map(pulse_duration1,0,CH_Max,0,255);
    digitalWrite(forwardpinFL,LOW);
    digitalWrite(backwardpinFL,HIGH);
    analogWrite(speedpinFL,changespeed);
    digitalWrite(forwardpinFR,LOW);
    digitalWrite(backwardpinFR,HIGH);
    analogWrite(speedpinFR,changespeed);
    Serial.println("Backwards");
  }

  //direction and speed Turn Left
  if (pulse_duration2 < mid_duration_lower && mid_duration_lower < pulse_duration1 && pulse_duration1 < mid_duration_higher){
    
    changespeed = map(pulse_duration2,0,CH_Max,0,255);
    digitalWrite(forwardpinFL,LOW);
    digitalWrite(backwardpinFL,HIGH);
    analogWrite(speedpinFL,changespeed);
    digitalWrite(forwardpinFR,HIGH);
    digitalWrite(backwardpinFR,LOW);
    analogWrite(speedpinFR,changespeed);
    Serial.println("Left");
  }

  //direction and speed Turn Right
  if (pulse_duration2 > mid_duration_higher && mid_duration_lower < pulse_duration1 && pulse_duration1 < mid_duration_higher){
    changespeed = map(pulse_duration2,mid_duration_lower,CH_Min,0,255);
    digitalWrite(forwardpinFL,HIGH);
    digitalWrite(backwardpinFL,LOW);
    analogWrite(speedpinFL,changespeed);
    digitalWrite(forwardpinFR,LOW);
    digitalWrite(backwardpinFR,HIGH);
    analogWrite(speedpinFR,changespeed);
    Serial.println("Right");
  }
}

Thanks :slight_smile:

Your code does not match your diagram. Either the code is wrong or the diagram.

1 Like

Thanks for for quick reply Jim,

I am currently just trying to get the front 2 motors to work so the diagram shows a lot more.

And i also have 2 radio link receiver chanells going to A0 and A1

The rest should match.

Are you sure the batteries are good and not half dead?

Brand new batteries. When i take the motor off and test against the batteries directly they work

reduce project to 1 potentiometer, 1 bridge and 1 motor

It may be bad breadboard connections. Sometimes with higher currents, the connections can be intermittent or just bad with the cheaper breadbords.
Is you program printing out valid pulse durations?
1000u to 2000usec

And I'd like to know the value of changespeed when you write it

    analogWrite(speedpinFR,changespeed);

Are your analog write pins PWM capable on the board you are using?

a7

Use small sketches to test each device...

Hi All, Thanks for the advice. the cause of the problem was the bolts I was using to secure the Arduino to the car. not really sure why but taking them out seemed to fix the issue.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.