I am trying to rotate a top on a specific angle after every 1 second. For example: 1 degree/second. I have two question:
Can I achieve this with servo motors?
If not, what motor should I use?
I know this question has very little description. I am mainly a programming guy. I don't much about arduino stuff. It's actually a hobby project for me.
Quite easy to do as long as you buy a conventional servo and not a "continuous rotation servo" which is not really a servo at all and cannot be commanded to go to a specific angle
Things to look out for :
1 - make sure that the servo can actually move through the range of angles that you require. Not all servos can even move through 180 degrees
2 - use an external power supply for the servo, not the 5V output from the Arduino voltage regulator as it can only safely provide a limited amount of current.
You can get finer control of a servo by using the servo.writeMicroseconds() function instead of servo.write(). 1000 steps for 180 degrees versus 180 steps for 180 degrees.
A_o:
I am trying to rotate a top on a specific angle after every 1 second. For example: 1 degree/second.
O.k. one critical bit of information you need to add. How long must it do this for? If it is forever so in total you may have turned a lot more than 360 degrees then you will need to use a completely different method than if it only has to turn say 90 degrees or 180 degrees in total. The second a normal servo can fairly easily do. The first a servo cannot do but maybe a stepper motor would work better.
slipstick:
The first a servo cannot do but maybe a stepper motor would work better.
As far as I have read, stepper motor does not have any potentiometer, which means it won't move to it's initial position/or know how to move to it's initial position. I would be needing a 360 rotation in future, but right now, I think 180 will suffice. I just want to see if I can do it.
A_o:
As far as I have read, stepper motor does not have any potentiometer, which means it won't move to it's initial position/or know how to move to it's initial position. I would be needing a 360 rotation in future, but right now, I think 180 will suffice. I just want to see if I can do it.
If you will need continuous 360 rotation then don't start with a 180-degree hobby servo. You would not learn much of anything useful to the final project while working on the prototype.
A stepper and a "home" switch like a QRE1113 would be a better place to start form.
Microseconds has AFAIK a step/resolution of 4 microseconds, so it could be 250 steps instead of 180.
Leo..
micros() and millis() are based on a timer prescaler setting of 64. The Servo library uses 8. So you could even do half-microsecond steps on a 16MHz Arduino without totally overhauling the library.
I'm a novice, both on Arduino and servos, so I'm reading most 'beginner' posts I can find about servo operation. I'm not sure to whom you were replying?
I was asking the OP whether he had any code in response to his post but not optimistic about an answer as it was over 4 months old. But from his question
"I am trying to rotate a top on a specific angle after every 1 second. For example: 1 degree/second."...
... I understood he wanted to rotate through 1 deg every second. I pasted your code into the servo.ino sketch, hopefully correctly:
/* Sweep
Original sweep.ino by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.
modified 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Sweep
My edit by pasting code from @JCA34F and modifying object to 'myservo'.
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(9,544,1500); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(int pos = 0; pos <= 464; pos++)
{
myservo.writeMicroseconds(pos * 4 + 544);
delay(5);
}
}
On my SG90 Micro Servo that results in a sweep of about 0.1 s and an immediate reverse sweep of about 1.9 s. IOW, ten full cycles took about 20 s.
Is that what you intended?
I'd much appreciate your explaining how it works please. So far I've used only degrees, not microseconds, and I'm confused about how sometimes the IDE manages to interpret a mixture of both, Such as in the basic sweep.ino sketch, in which the setup uses micoseconds and the loop uses degrees.
Those are indeed microseconds...but that is NOT the standard Sweep sketch. That simply contains myservo.attach(9). So someone has been messing with it.
I've discovered the source of that 'edited' version of sweep.ino. It was associated with my Elegoo Arduino Starter Kit. Somehow seems to have usurped as my 'default' starting sketch for servos.