Let's Make Robots!

Control RC car with Arduino and L293d.

I'm back after a really long break. I have a RC car that I ripped all the electronics out. I'm only using an Arduino and a L293D. I don't have no issue controlling the back motor to make it go forward or back. My issue is trying to get it to steer. If I would just tell it to turn left if will barely move. Now if I tell it to turn left wait 1 second then turn right and wait 1 second, it will start to make full turns on the second loop. Why isn't it turning all the way without me making it go left then right twice? Also I am using guibot motor driver setup.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Alright, I think I have this figured out. You are using a L293D, but with 1/2 of it controlling the drive motor and 1/2 of it controlling the steering motor.

I think jscottb is correct, this is a bang-bang steering system --all the way left, all the way right or spring back to center.

Your code's subroutines look fine, assuming you have your pins correct etc.

Your code now does not include a "command" to tell your robot to go forward however. As I read this code, it should sweep your steering to the left for one second, then to the right for one second and repeat. If this is what is happening, then your code is correct.

I would try adding a "go forward" comand in there:

loop()
{
   turn_right();
   straight();
   delay(a while);
   stop();
   delay(a while);
   turn_left();
   straight();
  delay(a while);
  stop(); 

The psuedo-code above will turn the steering motor on (and leave it on) then start the drive motor. When turn_left() is used, the steering motor will reverse and stay "the other way".

To center your steering, simply turn the steering motor off (LOW,LOW).

 

Back motor to one side of l293d and the steering motor to the other side.

I have a "dog chaser" I did that was built on a $7 New Bright mini RC truck. The steering is done with a DC motor and a spring to keep it true. I played around with it and send 255 to it and set the direction flag (using a 754410 home brew) It's a hard left or right only. Running the motors seperate from the uC board power wise.

 

Your steering is a DC motor, not a servo, huh? That makes a difference. First off, how are you powering this motor --A second L293D? 

To get to the meat of your question, you are probably looking for a position feedback sensor of some kind. Probably a round PCB with exposed traces and a copper "wiper" that goes along the traces. The other would be a pot. Either of these would be connected to something that moves when the car turns.

Do you have anything like this? --BTW, you will probably need one (of some kind) otherwise you will never know where "center" is on your steering. --Just on-->delay-->off is not going to cut it.


int motor_steer[] = {5, 6};
int motor_back[] = {11, 12};

void setup() {
Serial.begin(9600);

int i;
for(i = 0; i < 2; i++){
pinMode(motor_back[i], OUTPUT);
pinMode(motor_steer[i], OUTPUT);
}

}

void loop()
{
  turn_right();
  delay(1000);
  turn_left();
  delay(1000);
}


void drive_backward(){
analogWrite(motor_back[0], 150); // slow speed
analogWrite(motor_back[1], LOW);
}

void drive_forward(){
analogWrite(motor_back[0], LOW);
analogWrite(motor_back[1], 150); // slow speed
}

void turn_right()
{
  digitalWrite(motor_steer[0], 255);
  digitalWrite(motor_steer[1], LOW);
  Serial.println("right");
}

void turn_left()
{
  digitalWrite(motor_steer[0], LOW);
  digitalWrite(motor_steer[1], 255);
  Serial.println("left");
}

void straight()
{
  digitalWrite(motor_steer[0], LOW);
  digitalWrite(motor_steer[1], LOW);
  Serial.println("straight");
}

void stop()
{
  digitalWrite(motor_back[0], LOW);
  digitalWrite(motor_back[1], LOW);
  Serial.println("Stop");
}

This feels like code to me. Can we see the code you are using?

More info would be helpful. There are countless varieties of RC car and even more ways of setting it up. At least a picture of what you've got so far will give us a starting place. Otherwise it's like going to the doctor and saying "One of my things hurts, but I don't know what to call it and I can't point to it. Make it better."