Go Down

### Topic: SERVO HACKING FOR CONTINUOUS ROTATION PROGRAM CODE (Read 6494 times)previous topic - next topic

#### Jnixetra

##### Nov 13, 2011, 11:30 am
HELLO EVERYONE!!!

I believe this is not a new topic but recently i just came across to hack my servo so it can continuously turn 360 degree in clockwise and anticlockwise..

So this is how i hack my servo: http://todbot.com/blog/2009/04/11/tiny-servos-as-continuous-rotation-gearmotors/comment-page-1/#comments

After i hack my servo, i would like to write a program so it can turn in clockwise and anticlockwise when received signal from my transmitter. What i want is exactly from this video: http://www.youtube.com/watch?NR=1&v=ofMfJyc-xbs

Hope anyone whoever try this before can help me with the program!!! I really need it very very much!!! Thank you!!!

#### Grumpy_Mike

#1
##### Nov 13, 2011, 05:32 pm
Please don't use capitals it is like shouting.

Quote
can help me with the program

By help do yo mean, by any chance, do it all for you, or do you actually mean help?

#### hellonearthis

#2
##### Nov 13, 2011, 05:58 pm
So you have hacked the servo by Taking out the pot and replacing it with a couple of resistors (and a trimpot to balance the two).

Coding would seem simple,  setting the servo position a value of plus degrees moves it forward (the more degrees the faster I guess) and to stop to set the position back to zero.
Reversing would me setting negative values.

ie: start +5, then faster +10 and stop -15.

That's my guess anyway.

#### Jnixetra

#3
##### Nov 13, 2011, 06:16 pm
Ya i replaced the potentiometer with resistor..

I try to write my program like this:

void clockwise (){
deg += 1;
if (deg >180) { deg = 180; }
Serial.println(deg);
};
void anticlockwise (){
deg -= 1;
if (deg <0) { deg =0; }
Serial.println(deg);
};

but it does not work...

I jus need someone who can tell me what to write in my loop program so i can control the servo direction... i will very appreciate it... thanks

#### Grumpy_Mike

#4
##### Nov 13, 2011, 06:22 pm
Two points:-
1) It is now a continuous rotation so it doesn't matter what degrees it is.
2) You don't appear to be giving any servo control commands in that code.

You need to find what angle corresponds to off. Then just set the motor for an angle greater than this for clockwise or less than this for anti clockwise. The larger the difference between zero angle and the angle you give will determine the speed.

#### Jnixetra

#5
##### Nov 13, 2011, 06:26 pm
so u means i must use the servo.write() to determine the angle?

#### hellonearthis

#6
##### Nov 13, 2011, 06:32 pm
So you have read http://www.arduino.cc/en/Reference/Servo and looked at this http://arduino.cc/en/Tutorial/Sweep

I'm guessing if you set pos to a positive number it will spin forward
ie
Code: [Select]
`pos=45;myservo.write(pos);  // start forward movementdelay(2000); // wait a couple of secondspos=0;myservo.write(pos);  // stop forward movement  I think?delay(2000); // wait a couple of seconds`

#### Grumpy_Mike

#7
##### Nov 13, 2011, 07:02 pm
Quote
so u means i must use the servo.write() to determine the angle?

Yes.

#### Jnixetra

#8
##### Nov 13, 2011, 07:13 pm
Ok i gt it edi...

Really thank you for both of you... Appreciate it very much

#### kf2qd

#9
##### Jan 10, 2012, 12:13 am

so u means i must use the servo.write() to determine the angle?

No - servo.write is going to be more of a speed control (within limits). You removed the position feedback inside the servo to make it a continuous rotation. Ideally your dead spot should be at 90 and numbers less than 90 will rotate in one direction and numbers greater than 90 will rotate in the other direction. You could write some code that starts at 0 and goes to 180 and then back to 0 with a pause at each setting, write the current output value to the serial and then you can see where the servo starts and stops each direction and use an nuber in the mddle of where it stops from each direction as you zero speed number.

Go Up