Driving a servo using brushed ESC

It is a regular RC servo, came with my Futaba 6EXP radio system, an S3001 servo. http://www3.towerhobbies.com/cgi-bin/WTI0001P?I=LXH286&P=8

It's not big, but I think it would be dangerous to drain the power to run it from Arduino.

I also have the Arduino Duemilanove.

A few brushed ESCs....what else would you need, I think that's it?

You don't need an ESC, just make sure you use a separate supply (join the grounds) and drive the signal (white, usually) wire using one of the Arduino pins, with an appropriate servo library.
have a look in the libraries section for example code.

I did but did not understand how to do what I need to do. They have examples on how to drive the servo using a potentiometer, that is completely different from what I need. I need arduino to tell the servo to move 30 degress, wait 9 seconds, move back 30 degrees, wait for 9 sec, and repeat.

The example simply took the input from a pot (0..1023), mapped that range to an angle (0..180) and wrote that angle to a servo object.
Cut out the pot, substitute some angle constants, add a few "delay" calls, and your program is written.

Could I ask you to please write that code for me? Like I said, I do not know this stuff and it's seriously confusing for me. You explain it to me as if it is very simple, and it probably is, I just don't know the basics. ;D

I don't normally, but it is the season of goodwill
[uncompiled, untested)

void loop ()
{
  myservo.write (30); // move servo 30 degrees
  delay (1000 * 9); // wait nine seconds
  myservo.write (0); //moves servo back 30 degrees
  delay (1000 * 30); // wait 30 seconds.
}

Thank you for this. How do you assign the pin for the servo signal though in the code? And does it have to be a digital or analog pin? I thank you once again. If you do not wish to answer, I guess I'll just have to spend some more time analyzing the tutorials. :wink:

Will this code work? I mean is it complete. Thanks

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
 
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 ()
{
  myservo.write (30);   // move servo 30 degrees
  delay (1000 * 9);     // wait 9 seconds
  myservo.write (0);    //moves servo back 30 degrees
  delay (1000 * 9);     // wait 9 seconds.
}

Only one way to find out. Plug in the servo, upload the code, and watch the servo.

It should, though.

Awesome, absolutely awesome, thank you guys so much. It works :slight_smile: :slight_smile: :slight_smile:

Alright, so to develop on this, my next question :slight_smile: >>> Is there a way to make the servo move through the 30 degrees smoothly or more slowly?
Here's the complete code that I am using.

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
 
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 ()
{
  myservo.write (30);   // move servo 30 degrees
  delay (1000 * 9);     // wait 9 seconds
  myservo.write (0);    //moves servo back 30 degrees
  delay (1000 * 9);     // wait 9 seconds.
}

Thanks to all

what if I add more statements, such as 2 or 3 more saying to increase by 10 degrees, wait for 100ms and then increase again, and same for when decreasing. Hmmm, will try now, any other ideas welcome :slight_smile:

That is the correct way to do. Move the servo in small increments, as is done in one of the sample sketches provided with the servo library.

Thanks for confirming, this is what I am now using, it's awesome.

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
 
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 ()
{
  myservo.write (5);   // move servo 30 degrees
  delay (75);     // wait 9 seconds
  myservo.write (10);   // move servo 30 degrees
  delay (75);     // wait 9 seconds
  myservo.write (15);   // move servo 30 degrees
  delay (75);     // wait 9 seconds
  myservo.write (20);   // move servo 30 degrees
  delay (1000 * 9);     // wait 9 seconds
  myservo.write (15);    //moves servo back 30 degrees
  delay (75);     // wait 9 seconds.
  myservo.write (10);    //moves servo back 30 degrees
  delay (75);     // wait 9 seconds.
  myservo.write (5);    //moves servo back 30 degrees
  delay (75);     // wait 9 seconds.
  myservo.write (0);    //moves servo back 30 degrees
  delay (1000 * 9);     // wait 9 seconds.
}

Now it's time to learn about for loops, and proper commenting.

Thanks, I just changed the comments in my code ;D . Looping, I guess I'll have to learn it as well, expect more questions if I get another funny idea for arduino :wink:

In case someone else is interested in recreating this here, here's the complete code and diagram.

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
 
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 ()
{
  myservo.write (5);     // move servo to 5 degrees
  delay (75);            // wait 75ms
  myservo.write (10);    // move servo to 10 degrees
  delay (75);            // wait 75ms 
  myservo.write (15);    // move servo to 15 degrees
  delay (75);            // wait 75ms
  myservo.write (20);    // move servo to 20 degrees
  delay (1000 * 9);      // wait 9 seconds
  myservo.write (15);    // move servo back to 15 degrees
  delay (75);            // wait 9 seconds.
  myservo.write (10);    // move servo back to 10 degrees
  delay (75);            // wait 9 seconds.
  myservo.write (5);     // move servo back to 5 degrees
  delay (75);            // wait 9 seconds.
  myservo.write (0);     // move servo back to 0 degrees
  delay (1000 * 9);      // wait 9 seconds
}

One way of doing what you want is to use a "for" loop containing the "servo.write" and a "delay".

BTW, congratulations - feels good when it works through your own efforts, doesn't it?

Now that one I do not understand, maybe yet, but if you wish to expand on that, you are welcome. On the other hand, yes, it does feel good, but you did give me those 4 lines on which I expanded on. Thanks.

Well, a "for" loop has four parts to it:

  1. The initialisation (performed just once)
  2. the condition for continuing the loop (performed at the start of every loop)
  3. an action or actions to be performed at the end of the loop
  4. the body of the loop

So, to print the numbers 1..10

//    initialise      condition       end of loop action      
for (int number = 1; number <= 10; number = number + 1) {
  // body of loop
  Serial.println (number);
}
// rest of sketch

a) So, declare a variable "number" and set it to 1.
b) Test if "number" is less than or equal to 10. if not, go to f)
c) if it is, print its value
d) add one to "number" (there are shorter ways of doing this)
e) goto b)
f) rest of sketch

Now, imagine counting from 0 to 30, with a delay.