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 (" ");
}

