RC Car DC Motor Controller

Hello!

I'm gonna rebuild my old RC Car with Arduino and for controlling it's direction I will use Bluetooth controller with my Android phone. Generally I'm not very familliar with electronics, because my Arduino was in "sleep mode" for a good year and now I need to create some project with Android, because I would like to learn how to program apps for it. I was reading some tutorials and I got to point where it was mentioned that I need a DC Motor Controller. I didn't start with project yet and I've never work on some serious project with motors, but I think that now is the last time to do it. I will buy L9910 module, but when I look at it, I don't know why there are two inputs for each motor if DC motor has only + and -. Here I'm also asking myself what would be some example code for motor to go forward, back and to stop.

That's little description of my new project and a question what I don't know. I am pleasing you to help me, because my main activity on the project would be Android app and controlling RC Car with Bluetooth.

Thank you for all informations and your time! :slight_smile:

That motor controller is fairly straight forward. A-1A and A-1B control motor A, and same for motor B. If A-1A is made HIGH and A-1B is made LOW, then the motor should rotate in one direction, and if 1A and 1B are reversed, then the motor will reverse too. I have done exactly what you want to do, I have successfully made my own Android App that controls my robot via Bluetooth. The robot itself was simple, but the App was quite difficult. Look up "College Seminar Project" on YouTube by HazardOfExistance.

What type of connection is required - Digital or Analog? Depending on your reply it seems that digital, but it would be possible then to control car's speed?

Nice project and yes, my main reason for rebuilding RC Car is Bluetooth controlling with Andoid app :slight_smile:

Hi,
You can use either digital or PWM (analog) output to the motor controller. If you want to control the speed,
then yes, you will need to use PWM (analogWrite()) functions on the HIGH pin. Without knowing more about the RC car and what you are trying to do, I can't tell you how many PWM outputs you'll need. A minimum of 1, possibly as many as 4. Check the information on your arduino to see which pins support PWM and how many there are.

Depending on what kind of RC car it is, you might be able to get away without a motor controller by using the circuits already inside the car. I have done with with simple RC vehicles by identifying the inputs to the h-bridge that drives the motors, and tapping into them from the arduino. That allowed me to use either the arduino or the remote to drive the vehicle. In one case I also intercepted the remote outputs so I could use the remote as input to the arduino.

Have fun,

jsusnik7:
What type of connection is required - Digital or Analog? Depending on your reply it seems that digital, but it would be possible then to control car's speed?

Nice project and yes, my main reason for rebuilding RC Car is Bluetooth controlling with Andoid app :slight_smile:

Thank you.

It can be connected using an analog signal "analogWrite(PIN, 0 - 255)" this will give you speed control. Or you can have one constant speed in which a simple digital HIGH or LOW will work too.
If your using an Arduino UNO, then your PWM pins are shown by the ~ symbol on the board. If you are not using a UNO, then your PWM pins are 3,5,6,9,10,11.

This was the second code I made for my robot, a revision adding in different speeds. This should give you an Idea as to what you can do. But its better to send a string of bytes and not simple characters. I have code for that too, but for now try this.

/*
simple control test
 */
volatile int gear = 150; //default speed First Gear

volatile char val;         // variable to receive data from the serial port
byte M1L = 3;              // PWM left drive motor 
byte M2L = 5;              // PWM left drive motor
byte M1R = 9;              // PWM right drive motor
byte M2R = 6;              // PWM right drive motor
byte ledpin = 13;          // LED connected to pin 2 (on-board LED)

          /*IMPORTANT*/
//M1 => High & M2 => Low: forward movement
//M1 => Low & M2 => High: Backward movement

void setup()
{
  pinMode(ledpin, OUTPUT);  // pin 13 (on-board LED) as OUTPUT
  pinMode(M1L, OUTPUT);                                
  pinMode(M1R, OUTPUT);
  pinMode(M2L, OUTPUT);                                
  pinMode(M2R, OUTPUT);
  Serial.begin(9600);       // start serial communication at 115200bps
  Help();
}

void loop() {
  if( Serial.available() > 0)       // if data is available to read
  { 
    digitalWrite(ledpin, HIGH); // this will turn on the LED if you receive a command
    
    val = Serial.read();
    volatile int skewGear = gear/2;
    if(val == '1')
     {
      Serial.println("First Gear ");
      gear = 150;
     }
     if (val == '2')
     { 
       Serial.println("Second Gear ");
       gear = 200;
     }
    if (val == '3')
     { 
       Serial.println("Third Gear ");
       gear = 255;
     }
    
    
    if( val == 'W' || val == 'w' )//forwards               
    {
      Serial.println("Moving Forwards"); 
     //      Left Motor     :     Right Motor
      analogWrite(M1L, gear); analogWrite(M1R, gear);
      digitalWrite(M2L, LOW); digitalWrite(M2R, LOW);                 
    }
    else if( val == 'S' || val == 's' )//backwards              
    {
      Serial.println("Moving Backwards");
      digitalWrite(M1L, LOW); digitalWrite(M1R, LOW);
      analogWrite(M2L, gear); analogWrite(M2R, gear);                   
    }
    else if( val == 'A' || val == 'a' )//Left         
    {
      Serial.println("LEFT");
      digitalWrite(M1L, LOW); analogWrite(M1R, gear);
      analogWrite(M2L, gear); digitalWrite(M2R, LOW);                      
    }
   else if( val == 'D' || val == 'd' )              
    {
      Serial.println("RIGHT");   
      analogWrite(M1L, gear);digitalWrite(M1R, LOW);
      digitalWrite(M2L, LOW); analogWrite(M2R, gear);                 
    }
    else if( val == 'T' || val == 't' )              
    {
      Serial.println("Skew Left Forward");   
      analogWrite(M1L, skewGear); analogWrite(M1R, gear);
      digitalWrite(M2L, LOW); digitalWrite(M2R, LOW);                  
    }
    else if( val == 'Y' || val == 'y' )              
    {
      Serial.println("Skew Right Forward");  
      analogWrite(M1L, gear); analogWrite(M1R, skewGear); 
      digitalWrite(M2L, LOW); digitalWrite(M2R, LOW);                  
    }
    else if( val == 'G' || val == 'g' )              
    {
      Serial.println("Skew Left Backward");   
      digitalWrite(M1L, LOW); digitalWrite(M1R, LOW);
      analogWrite(M2L, skewGear); analogWrite(M2R, gear);                  
    }
    else if( val == 'H' || val == 'h' )              
    {
      Serial.println("Skew Right Backward");   
      digitalWrite(M1L, LOW); digitalWrite(M1R, LOW);
      analogWrite(M2L, gear); analogWrite(M2R, skewGear);                  
    }
    else if(val == ' ' || val == 'x' || val == 'X')  // motors will stop if space bar is hit or x|X
    {
      digitalWrite(M1L, LOW); digitalWrite(M1R, LOW); 
      digitalWrite(M2L, LOW); digitalWrite(M2R, LOW);
    }
    else if(val == '*') {
      Help();
    }
    else{}    
  }
  else{
    digitalWrite(ledpin, LOW);
  }
}

void Help() {
  Serial.println("Commands, Press * to bring up help menu");
  Serial.println("W = Forward");
  Serial.println("S = Backward");
  Serial.println("A = Left");
  Serial.println("D = Right");
  Serial.println("T = Skew Forward Left");
  Serial.println("Y = Skew Forward Right");
  Serial.println("G = Skew Backward Left");
  Serial.println("H = Skew Backward Right");
  Serial.println("Space Bar = All stop");
  return; 
}

Thank you both for detailed answers! The only thing that remians now is to get components for the project :slight_smile: