thumbstick button control for 360 degree servo(robotic arm project)

Hi everyone

I have an issue with 360 degree servo. when I pressed the button on my thumbstick shield I want the 360 degree servo to come back its origin point. as you might know center point is set by a screw on the servo. I found this code and it works perfectly but it doesnt include a button function. I appreciate for any help.

#include <Servo.h>
int t=10;
Servo SR04; // Full rotational
int PinReading=0;
int potentiometer=0;
void setup() {
// put your setup code here, to run once:
SR04.attach(9);// servo connected to D9
pinMode(A0,INPUT);
}

void loop() {
// put your main code here, to run repeatedly:
PinReading=analogRead(A0);
delay(t);
potentiometer=map(PinReading,0,1023,0,180);
potentiometer=constrain(potentiometer,0,180);
SR04.write(potentiometer);
delay(50);

}

hacknmake:
Hi everyone

I have an issue with 360 degree servo. when I pressed the button on my thumbstick shield I want the 360 degree servo to come back its origin point. as you might know center point is set by a screw on the servo. I found this code and it works perfectly but it doesnt include a button function. I appreciate for any help.

#include <Servo.h>

int t = 10;
Servo SR04;  // Full rotational
int PinReading = 0;
int potentiometer = 0;
void setup()
{
   // put your setup code here, to run once:
   SR04.attach(9);// servo connected to D9
   pinMode(A0, INPUT);
}

void loop()
{
   // put your main code here, to run repeatedly:
   PinReading = analogRead(A0);
   delay(t);
   potentiometer = map(PinReading, 0, 1023, 0, 180);
   potentiometer = constrain(potentiometer, 0, 180);
   SR04.write(potentiometer);
   delay(50);
}

Most, if not all, 360° servos are continuous rotation, not limited to just 360° of travel. (Mine are.) Does your servo spin continuously in one direction when you write a value >90, spin continuously in the other direction when you write a value <90, and stop turning when you write 90 to it?

If so, there is no centre point. 90 would be the centre point on a std servo, but it’s just ‘stop’ on a CR servo, so you won’t be able to do what you want. 90 is ‘stop’ as mentioned, and values further above and below 90 just increase the speed in each direction.
On a CR servo, the trim screw is used to trim the servo so that it stays still at 90.

And another point, when posting code on these forums, you’re expected to place it between code tags, “</>” at the top-left corner of the ‘Post’ window.
It should also be formatted correctly, with indentations where necessary. The best/easiest way to format it is to click on >Tools >Auto Format before copying and pasting into your post. Note how I’ve done it in the quote above.
These steps make code much more readable for people who might want to help you, and also allows them to easily copy the code for testing in their IDE.

I am using continous rotation servo. You got me right. Can you suggest a servo(brand,model) suitable for this application? and thanks for the advice since this is my first post I didnt know the code tag.

hacknmake: I am using continous rotation servo. You got me right. Can you suggest a servo(brand,model) suitable for this application? and thanks for the advice since this is my first post I didnt know the code tag.

As far as I know, 180 degrees is the best you'll do with off-the-shelf servos.

You could add gearing to achieve a longer swing. ie 2:1 gearing with a 180 degree servo would have 360 degree swing, at a cost of 50% of it's torque. Centring resolution might suffer a little, too.

I've read of people modifying a servo internally, but don't know much about it, or how well it works. I guess some resistor values would need changing, plus the end-stops would need to be removed.

If you really need more than 180 degrees, or more than 360 degrees, a stepper motor is probably the best option. Not as much torque as a servo, but you could buy a geared stepper motor for improved torque, or add your own gearing.

I suppose the final option would be to stick with the continuous-rotation servo, then incorporate position sensing or some type of limit-switch.

Check out the servos here
https://www.servocity.com/html/servos___accessories.html
and also the info on how servos work here
https://www.servocity.com/html/general_product_information.html#.VjYzXberQgs

If you want it to come back to a known point, then perhaps a microswitch that is closed when the control reaches a certain position, or an optical sensor, can be set up.

CrossRoads: Check out the servos here https://www.servocity.com/html/servos___accessories.html

Wow, they have a nice range of stuff. Wish we had a place like that here in Oz. I bookmarked them anyway, for future reference, but I think the postage cost would kill me.

As you may have learned by now, the screw on your servo sets the zero speed point not the center.

There are lots of options for making a 360 type servo. ServoCity's stuff is an easy way to get this sort of job done but ServoCity's stuff isn't cheap (not that I think it's overpriced).

By adding quadrature encoders to your CR servo, you could use the "servo" to find a position (you'll need a way of know the start position).

You can also move the feedback potentiometer from inside the servo to an external point where it's geared down. There are 5 turn pots available. It shouldn't be too hard to switch out the normal pot for a 5 turn pot. You probably want to use a large servo if you're going to try this. I think this is the way "winch servos" are made.

You can stack two 180 degree servos on top of one another for a poor man's DIY 360 servo.

|450x500

In hindsight, I should have joined the two bottom servos at their bases. By controlling the two servos with a single I/O pin, they both move together. I was pleasantly surprised how easy the two servos joined this way were to control.

Dynamixel makes servos which have position feedback over 300 degrees. They have one with full 360 degree feedback but I believe it's one of their more expensive models. The AX-12A is the entry level "servo" from Dynamixel.

Another obvious option is to use a stepper motor. But even stepper motors benefit from position feedback since it's not uncommon for steps to be missed.

A sail-winch servo can rotate up to 6 revolutions (3 is more usual) with position control.

...R

Below is a sail winch that might be close to what you need. Sail winches may not have the resolution that normal servos have.

http://www.hobbyking.com/hobbyking/store/__42638__Turnigy_8482_TGY_4805_1_5PA_Sail_Winch_Servo_Drum_Type_.html