I need to be create rotation of my servo within smaller variable angle. I currently have a servo connected to the arduino that rotates between 0 and 180 degrees in a sweep function continuously.
My aim is to use if possible some potentiometers to reduce or increase the angle of rotation so while sweeping it can be limited to between 30 and 90 degree rotation or increased to 50 and 150 degrees. ( any angle combination of rotation)
Any help will be appreciated. Thanks
you can rotate servo at whatever angle you want, maybe i didn't understand what you mean by reducing or increasing angle.
you just select angle position and it's send to the servo.
except for loop you just choose pos variable whatever angle you want and that's it, but i think servo isn't so precise.
Thanks that makes sense and the sweep function works. It continuously sweeps between 0 and 180 degrees but the plan is not only making it rotate to a certain angle but also changing the angle it starts from (say 50 and 150 degrees).
Is it possible if i use a pot for the start point and a pot for the end point telling the servo what angle to start and stop? Thanks
Some pot/servo test code. Possibly pots could be used to generate values which would then be used to limit the max/min control value sent to the servo.
//zoomkat dual pot/servo test 12-29-12
//view output using the serial monitor
#include <Servo.h>
Servo myservo1;
Servo myservo2;
int potpin1 = 0; //analog input pin A0
int potpin2 = 1;
int newval1, oldval1;
int newval2, oldval2;
void setup()
{
Serial.begin(9600);
myservo1.attach(2);
myservo2.attach(3);
Serial.println("testing dual pot servo");
}
void loop()
{
newval1 = analogRead(potpin1);
newval1 = map(newval1, 0, 1023, 0, 179);
if (newval1 < (oldval1-2) || newval1 > (oldval1+2)){
myservo1.write(newval1);
Serial.print("1- ");
Serial.println(newval1);
oldval1=newval1;
}
newval2 = analogRead(potpin2);
newval2 = map(newval2, 0, 1023, 0, 179);
if (newval2 < (oldval2-2) || newval2 > (oldval2+2)){
myservo2.write(newval2);
Serial.print("2- ");
Serial.println(newval2);
oldval2=newval2;
}
delay(50);
}
Thanks that's what i meant. Using two pots to determine the maximum and minimum level of rotation of the servo. Is it possible to integrate that code with the sweep function. So when a switch starts the sweep function, the pots are used to increase or decrease the maximum and minimum level of rotation. For example: instead of 0-180 degrees, it rotates from 50-120 while doing the sweep function. Thanks
Yes, it is perfectly possible.
Is it possible to get a generated code for that? Thanks
What do you mean by "a generated code"?
Sorry I mean what will the code look like. Thanks
It'll look a bit like the code in reply #3
You'll incorporate that code from reply 3 into your code, and for the servo sweep function, you remove the 0 and the 180 from the for loop, and change them to newval1 and newval2(newvals both being set by the potentiometers).
Thanks a lot. That should work fine