Controlling servo motor with arduino

I am trying to control my servo motor with an arduino uno r3. I would like to define a frequency of about 4Hz and an angle of rotation of +/-30 degrees. Are there any available codes that I can easily modify to fulfill those requirements?
I tried looking on google, but I am new to coding and the arduino, so I have little experience and knowledge with what is needed.

Not sure if your aware of the Servo library or not but, under your Arduino examples, there is one for servos. Give it a try. Make sure you are using an external power supply for the servos, and the grounds (Arduino GND and extrn supply GND) are tied together.

HazardsMind:
Not sure if your aware of the Servo library or not but, under your Arduino examples, there is one for servos. Give it a try. Make sure you are using an external power supply for the servos, and the grounds (Arduino GND and extrn supply GND) are tied together.

Thanks. I did take a look at them, but I am not sure how to adjust the code to change the frequency and angle of rotation. Why do we need an external PS for the servo? I was reading one of the pages on arduino.cc about servos and it stated to connect the power pin on the servo to the power pin on the arduino.

Using the arduinos power supply will work but only for a micro servo under small loads. Its not good for large servos/numbers of servos/large loads.

Note - the term is servo and NOT "servo motor".

adjust the code to change the frequency and angle of rotation

What do you think this means and why would you want to do it. You tell the servo the possition you want to be in and it goes there - simples.

Mark

holmes4:
Using the arduinos power supply will work but only for a micro servo under small loads. Its not good for large servos/numbers of servos/large loads.

Note - the term is servo and NOT "servo motor".

adjust the code to change the frequency and angle of rotation

What do you think this means and why would you want to do it. You tell the servo the possition you want to be in and it goes there - simples.

Mark

You can't specify how fast it takes to get to that position?
I'm working on a project where the servo oscillates between +/- 30 degrees continuously. I would like one cycle (30 to -30 then to 30 degrees) to take a certain amount of time.

You can't specify how fast it takes to get to that position?

Sure you can, but just by saying servo.Write(0); and then have servo.Write(90); it will go however fast it is designed for. However, you can use a for loop to adjust the time it increments to a set point.

You will need to think a little, but with a simple for loop, you can do what you want. Now if you want to go reverse then you will need to add some logic to decide which for loop to use. You can make it a function and just add the value you want the servo to go to.

void ServoMove(int position) 
{
  if(position > lastPosition)
  {
   // servo rotate left so many degrees
  }
 
 else 
  {
   // rotate right so many degrees
  }
 lastPosition = position;
}

I'm working on a project where the servo oscillates between +/- 30 degrees continuously. I would like one cycle (30 to -30 then to 30 degrees) to take a certain amount of time.

Try the "sweep" example code provided in the arduino IDE example code.

Thanks for all the replies :)! I will give this a try.