Programming Servo Oscillator

Hi there,

Totally new to Arduino, the platform and the forum. I have a project and this is what I want to be able to do. But have no real clue how to code it correctly. Hopefully some folks around here can help. There will be 3 analog inputs from 3 potentiometers. One will control the maxima of the sine wave one will control the minimum and the final I want to control the frequency. The digital output will be to a servo. The frequencies will be low enough that the servo can respond. I guess the way to start would be with a void loop. Setting the min and max will be easy, just use the pot 1 and pot 2 readings. Having pot 3 control control the frequency of the sign wave is where I get stuck. I know that there is a sin function but don't really know how it works in the arduino program. I think just putting the wave equation into the code would work but I just don't know how to code that well in the arduino software. I also would like to try out triangle waves as well if anyone has any ideas there.

Thanks in advance.

Sincerely,
Rich

Hi Rich,
Welcome to the board.
A note - you cross posted the same question on two different forums. This will earn you the ire of the forum members. Better to only ask the same question on one forum.

Have looked through this tutorial: http://www.arduino.cc/en/Tutorial/Sweep
Are you able to read the values of your pots?

This will help us focus on what you need to do next.

Yeah sorry about that. I realized that perhaps I'd picked the wrong posting category. I'll try and get rid of the other. Yes the pots will have the wiper going to an analog pin with 5 volts across the pot. They can be any sized pot but I have a bunch of 10k pots on hand I was planning on using with a 3k trim pot I was thinking of adding in line as well for fine tuning. I have seen that post you mention and that library file. What I want to do I think will be a little more advanced. Timing is the key. I suppose I could mess with the delay to try and 'fake' it.

Thanks and sorry for the double post. I just managed to remove it.

I have been giving this some thought.

I guess that I should ask if this is a standard hobby servo, with an arm that rotates. These typically have a range of less than 180 degrees, with the center being 90 degrees. How much less depends on which servo you have. But for ease of discussion, I will use 0-180 as the range.

How will the servo represent the sine wave? With its sweep?
If so, then the servo sweep tutorial is representing a triangle wave. You would just have to add logic to modify the min, max and period.
The period can be modified by changing the number of steps in the loop.
The min and max can be handled by some simple math. Multiply the wave value by the difference between the min and max to set the amplitude, and add the min.

To get a sine wave rather than a triangle wave, you will need to put in a sine function.

Thanks for giving it some though. I will experiment with some of these variables you mentioned and see where it leads me. The 180 degree hobby servos which drives a gear. I'll see what comes of it and post back here.

Sincerely,
Rich