Due to high demand, expect some shipping delays at this time - orders may not ship for up to 2-3 business days.
0

Arduino RC car
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Arduino RC car

by johndavid400 on Sun May 17, 2009 4:00 pm

I just finished a small project I have been working on and thought I would share my progress in case anyone else is interested.
The idea is to control any small RC car, boat, robot, whatever... with an Arduino, a Motorshield, and just about any RC Transmitter/Receiver. I am using a $2 thrift store RC car that came with no remote.

Using only 1 channel from a 6 channel RC transmitter/receiever pair, the signal is connected to the Arduino which translates the value into a motor speed in the appropriate direction (forward/reverse/stop). I know that an electronic speed controller from a hobby shop can do this, but they are expensive and typically only work with specified motors... plus, you can't change the code to make it do anything else or add up to 4 motors like you can with the Arduino and a motorshield. In addition, I attached a small servo motor to replace the cheap steering mechanism in the rc car, and hooked it up directly to the RC receiver, as not to slow down the Arduino while processing the other motor signals.

When the transmitter stick is in center position, motor is off. Pushing the stick in either direction on the RC transmitter will set the motor speed proportionally in that direction. The only thing that needs to be done to calibrate the PPM values from your RC receiver, is to connect your RC receiver to Arduino, upload the sketch, and watch the Serial monitor... push the stick up to see the max value and push stick down to see the min value. If these are different than the mapped values in the sketch, you would need to change them to your observed values.

Here is the sketch:

Code: Select all | TOGGLE FULL SIZE
#include <AFMotor.h>  // include motorshield library

AF_DCMotor motor1(3);  // name motor and tell it to use motorshield M3

int PPMin1 = 14;  // connect the desired channel (PPM signal) from your RC receiver to analog pin 0 (pin 14) on Arduino. 

int RCval1;  // store RC signal pulse length
int adj_val1;  // map that value to be between 0-255

void setup()
{
  Serial.begin(9600); //serial library start
 
  pinMode(PPMin1, INPUT); //Pin 14 as input

  // turn on motor
  motor1.setSpeed(250); 
  motor1.run(RELEASE);

}


void loop()

    RCval1 = pulseIn(PPMin1, HIGH, 20000);      //read RC channel 1
    adj_val1 = map(RCval1, 630, 1125, 0, 255);  // my observed RC values are between 630-1125.. these might need to be changed, depending on your RC system.

   
    //motor1
    if (adj_val1 > 136) {             
    motor1.run(BACKWARD);
    motor1.setSpeed(adj_val1 - 36);
  }
    else if (adj_val1 < 120) {             
    motor1.run(FORWARD);
    motor1.setSpeed(220 - adj_val1);
  }
    else{
    motor1.run(RELEASE);
  }
   
 
  Serial.print ("val1: ");
  Serial.print (RCval1);  // if you turn on your serial monitor you can see the readings.
  Serial.print ("       ");
  Serial.print ("adjusted:  ");
  Serial.print (adj_val1);
  Serial.println ("  ");
 
}
johndavid400
 
Posts: 7
Joined: Wed Feb 25, 2009 1:16 pm

Re: Arduino RC car

by rj44319 on Wed Jan 20, 2010 12:33 pm

Hi, My name is Richard Johnson. I am from the University of Akron's Combat Bot team. I saw your code, It works perfectly. It is better and more reliable that any thing I saw on the web. We are using it to control our weapon on the bot (modified it to control co2 valves). Thanks for posting this up in the blog.
rj44319
 
Posts: 130
Joined: Wed Feb 25, 2009 10:27 pm

Re: Arduino RC car

by wjwelshbot on Fri Dec 12, 2014 4:59 pm

Hello, this is exactly what i was looking for - Thanks! I am a beginner so please forgive me if this is a rookie mistake, But when I verify the sketch i get some errors:

sketch_dec12a.ino:1:57: warning: AFMotor.h: No such file or directory
sketch_dec12a:3: error: 'AF_DCMotor' does not name a type
sketch_dec12a.ino: In function 'void setup()':
sketch_dec12a:17: error: 'motor1' was not declared in this scope
sketch_dec12a:18: error: 'RELEASE' was not declared in this scope
sketch_dec12a.ino: In function 'void loop()':
sketch_dec12a:31: error: 'motor1' was not declared in this scope
sketch_dec12a:31: error: 'BACKWARD' was not declared in this scope
sketch_dec12a:35: error: 'motor1' was not declared in this scope
sketch_dec12a:35: error: 'FORWARD' was not declared in this scope
sketch_dec12a:39: error: 'motor1' was not declared in this scope
sketch_dec12a:39: error: 'RELEASE' was not declared in this scope

What do I need to do to make this work? Thank you so much.

wjwelshbot
 
Posts: 3
Joined: Fri Dec 12, 2014 4:55 pm

Re: Arduino RC car

by franklin97355 on Fri Dec 12, 2014 6:53 pm

Looks like you don't have the correct libraries installed in the correct place. Check out this library install tutorial Also which version of the motor shield are you using?

franklin97355
 
Posts: 22588
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Arduino RC car

by tman2001 on Tue Jun 13, 2017 1:59 am

Thanks a lot for the amazing code! really appreciated it.

I would also be even more thankful if someone could help me with the new code I'm trying to write.
it's like midnight so you'll have to excuse me being bland (and sadly ....I'm kinda a noob sry).


the code itself seems to work fine, however, after setting it all up, it just won't turn the darn motor. Everything seems to be set up fine and the values in the Serial monitor seem good, but the board won't sends the current to the motor whatsoever.
I have a 12v 60rpm motor that I'm trying to turn and simply control the throttle with a joystick.
I've messed with the code some (probably screwed it up) but everything seems to be going according to plan,,,,,,, except the motor won't turn.
I don't think the board or the shield is malfunctioning, but Idk. I'm open to any suggestions.
THX FOR THE HELP
-------------------------------------------------------------------------------------------------------------------------------------------------------------------

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_MotorShield.h>

Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *motor1 = AFMS.getMotor(2);

void setup()
{
  Serial.begin(9600); //serial library start
 


  // turn on motor
  motor1->setSpeed(250); 
  motor1->run(RELEASE);
delay(3000);
}


void loop()

   int RCval1 = analogRead(8);
   int  adj_val1 = map(RCval1, 510, 1023, 0, 255);  // my observed RC values are between 630-1125.. these might need to be changed, depending on your RC system.

    delay (20);
    //motor1
    if (adj_val1 > 136) {             
    motor1->run(BACKWARD);
    motor1->setSpeed(255);    //motor1->setSpeed(adj_val1 - 36);
    Serial.print ("   GOING BACK  ");
  }
    else if (adj_val1 < 120) {             
    motor1->run(FORWARD);
    motor1->setSpeed(adj_val1+adj_val1*2);;    //    motor1.setSpeed(220 - adj_val1);
    Serial.print ("  FORWARD  ");
  }
    else{
    motor1->run(RELEASE);
    Serial.print ("  STOP  ");
  }
   
 
  Serial.print ("val1: ");
  Serial.print (RCval1);  // if you turn on your serial monitor you can see the readings.
  Serial.print ("       ");
  Serial.print ("adjusted:  ");
  Serial.print (adj_val1);
  Serial.println ("  ");
    Serial.print (adj_val1 - 36);
      Serial.print (220 - adj_val1);
}
Last edited by adafruit_support_bill on Tue Jun 13, 2017 6:04 am, edited 1 time in total.
Reason: Please use [code] tags when submitting code to the forums

tman2001
 
Posts: 5
Joined: Tue Jun 13, 2017 1:41 am

Re: Arduino RC car

by adafruit_support_bill on Tue Jun 13, 2017 6:07 am

@tman2001 - The code you posted is using a completely different library than the OP.

Please start a new thread for your question - and post photos showing your soldering and connections to your shield.

adafruit_support_bill
 
Posts: 83774
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.