Arduino RC car

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Arduino RC car

Postby johndavid400 » Sun May 17, 2009 3: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
#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 12:16 pm

Re: Arduino RC car

Postby rj44319 » Wed Jan 20, 2010 11:33 am

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 9:27 pm


Return to Arduino

Who is online

Users browsing this forum: lemming and 11 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [100]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[108]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[69]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]