Arduino + speed controler

Hi guys

and thanks for looking at my post,

My question is…

can I use servo.h to run a electronic speed control out of a RC car ?

and if yes how?

serial.read would be my input speed.

any help or pointers would be great !!

cheers

skip :slight_smile:

Just use the regular motor controls. Don’t forget the correct circuits to help protect the arduino. You shouldn’t run any motors directly from the arduino.

Using the AFMotor.h library you can easily adjust the speed.

#include <AFMotor.h>

AF_DCMotor motor(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");
  
  motor.setSpeed(200);     // set the speed to 200/255
}

void loop() {
  Serial.print("tick");
  
  motor.run(FORWARD);      // turn it on going forward
  delay(1000);

  Serial.print("tock");
  motor.run(BACKWARD);     // the other way
  delay(1000);
  
  Serial.print("tack");
  motor.run(RELEASE);      // stopped
  delay(1000);
}

http://www.ladyada.net/make/mshield/use.html

As you can see in the example. this library has a command for setting the motor speed.

motor.setSpeed(200);

Using the AFMotor.h library you can easily adjust the speed

Digimike - he said he's using the speed controller from an R/C car. They use standard 50Hz PPM signals, so yes, use the servo libraries.

ok
so I tryed this on a servo

// Sweep
// by BARRAGAN <http://barraganstudio.com> 

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 
 
 
void loop() 
{ 
  for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
}

and it works.

so I turn it all of and change wires over to speed controler,
power back up and nothing happens lol
i dont get it :-/

Well, what happens now is that you post the details of the speed controller.

oh ok (blush) lol

It is a

http://www.traxxas.com/products/accessories/trx_accessories_xl5.htm

and thanks again :)

Looks like a fairly standard controller.

The sweep program starts from (say) full reverse, goes through neutral after about 1.3 seconds, then on to full speed (or full reverse) after another 1.3 or 1.4 seconds. Then goes back the other way.

Modify the sweep program to go from around 90 degrees up to 180 degrees, with a delay of around 30 millisecond per step.

so…

i run this code

// Sweep
// by BARRAGAN <http://barraganstudio.com> 

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 
 
 
void loop() 
{ 
  for(pos = 90; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(25);                       // waits 15ms for the servo to reach the position 
  } 
  for(pos = 180; pos>=90; pos-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(25);                       // waits 15ms for the servo to reach the position 
  } 
}

and the red light on the speed controller flashes green for about 30ms about every 750 ms

and the motor does nothing :frowning:

any clue ??

The ESC is trying to tell you something, have a read of the manual for the ESC, most likely the trouble shooting section.

Hi all, in my experience alot of "modern" Speedo's need to be in neutal before they will initialise, this stops the R/C car doing a runner without you, this is usually the case when going from forward to reverse, the speedo needs to brake first. Using the servo command is fine but i think the problem is that to need to initialise the speedo in neutral stick position, in case of a servo that would be 90 degrees so myservo.write(90); I have found thats some servos centralise as low as 82 though, so you could try a sweep of 80 to 100 and see how that goes. The red light is telling you that the Virtual control stick (Arduino) is not in neutral, the goal would be to get the light to stay green