Driving a servo using brushed ESC

Hi guys, this is my first time on this forum and I don't really know how all this works. I just wanted to know if anyone here can help me out. What I am trying to get is a code which will control a servo through a brushed ESC through the arduino. Or perhaps it is doable without the ESC. I need it to be automatic though, so it spins the servo for about 30 degrees, waits 9 seconds, and spins it back to original position. Since I do not know any coding past that of blinking a few LEDs on the arduino using different patterns, I am asking for help from anyone that can do this. Thanks in advance for any responses :sunglasses:

Is this an R/C servo or an industrial one?
Do you have the spec?

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?