### Author Topic: Turn Motor 1080° forth and 1080 ° back at low speed  (Read 1187 times)

0 Members and 1 Guest are viewing this topic.

#### Confugere

• Beginner
• Posts: 5
##### Turn Motor 1080° forth and 1080 ° back at low speed
« on: October 17, 2012, 01:58:30 PM »
Hello Guys,
I'm constructing a little mobile for my baby son and I want it to turn 3 times forth and 3 times back.
When I apply other angles to the arduino sweep example, it doesn't work.
Can anyone help me?
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// a maximum of eight servo objects can be created

int pos = 0;    // variable to store the servo position

void setup()
{
myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop()
{
for(pos = 0; pos < 1080; pos += 1)  // goes from 0 degrees to 180 degrees
{                                  // in steps of 1 degree
myservo.write(pos);              // tell servo to go to position in variable 'pos'
delay(100);                       // waits 15ms for the servo to reach the position
}
for(pos = 1080; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
{
myservo.write(pos);              // tell servo to go to position in variable 'pos'
delay(100);                       // waits 15ms for the servo to reach the position
}
}

#### Pogertt

• Full Member
• Posts: 60
• Pogertt
##### Re: Turn Motor 1080° forth and 1080 ° back at low speed
« Reply #1 on: October 17, 2012, 06:48:06 PM »

http://www.servocity.com/html/how_do_servos_work_.html

It will explain what signal the servo requires.

Servos typically travel from 0 to 180 degrees.
If you are trying to get one to rotate 1080 degrees,  you may need a "Continuous Rotation Servo"

#### Soeren

• Supreme Robot
• Posts: 4,672
• Mind Reading: 0.0
##### Re: Turn Motor 1080° forth and 1080 ° back at low speed
« Reply #2 on: October 17, 2012, 08:57:24 PM »
Hi,

I'm constructing a little mobile for my baby son and I want it to turn 3 times forth and 3 times back.
When I apply other angles to the arduino sweep example, it doesn't work.
Can anyone help me?
You've got a regular servo and that won't work. What you need is a Sail Winch Servo, one like this, but there's a fair number of different makes and models.
If you go that route and need to stop at eg. 450°, you'll need to translate the servos entire travel to numbers in the range 0..180° (for a common servo), as they're all built for the servo standard (although almost none actually comply with the 1ms to 2ms standard - it's 0.9ms to 2.1ms for Hitec).
Calculating the time to tell your program:
T = Tmin + (Tmax-Tmin)*wp/Dmax
Where:
Tmin = minimum servo pulse accepted by a given servo
Tmax = maximum etc.
wp = wanted position in degrees
Dmax = maximum rotation of servo in degrees

Assuming the Hitech servo I linked above with a travel of 1260° and 0.9--2-1ms pulse duration, 450° would be:
0.9ms+(2.1ms-0.9ms)*450/1260 = 1.33ms

Even better for your project, may well be a gear-head DC motor. You can get a gearing that gives you "low speed", whatever that may be to you and controlling it with a PWM signal, you can slow it even further from the nominal.
To slow a servo OTOH, you move it in small increments, as the servo electronics go as fast as possible when you command it a large displacement, while it goes slower when making small displacements (to up the precision).
Further, servos are noisy little buggers, while a good quality gear-head can be almost inaudible (depends a lot on quality of course).

It's crucial for finding the right motor that you quantify your needs
So...
What is "low speed" in RPM?
How much torque is needed?

If the torque escapes you, try to describe what it's going to rotate (weight and dimensions) and how it will be held in place (bushings/bearings/whatever), and we should be able to come up with an approximate number.

(Please save the source code for the Software forum, this is the Electronics forum).
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Engineering is based on numbers - not adjectives

#### Confugere

• Beginner
• Posts: 5
##### Re: Turn Motor 1080° forth and 1080 ° back at low speed
« Reply #3 on: October 18, 2012, 01:56:22 AM »
Thanks for your sophisticated and long reply, I will just buy a gear-head DC motor, but I need one that turns at around 5 RPM. Do you have an idea? It should move a mobile that weighs around 1kg and is about 40 cm in diameter. The mobile will be attached via a string, so there will be a delay in action.
Thanks alot
Con

#### Soeren

• Supreme Robot
• Posts: 4,672
• Mind Reading: 0.0
##### Re: Turn Motor 1080° forth and 1080 ° back at low speed
« Reply #4 on: October 19, 2012, 07:22:49 PM »
Hi,

[...] I need one that turns at around 5 RPM. Do you have an idea?
My immediate thought was a mirror ball (MB) motor. They're built for a very similar purpose, will run long hours and, if mounted correctly) won't crash down on your prodigy.
Mains driven MB motors only rotates in one diretion, but a battery driven device like this one shouldn't be hard to tap into the wires and control from the outside (bidirectionally).

You can get almost the speed DC gear head motor you like (just not 5RPM) from this site.
Choosing a slightly faster motor than you need and using PWM will get you the speed you like.

For comparison, MB motors rotate around 1RPM for the slowest, as large MBs need a slower rotation than the smaller ones, to keep the apparent speed of the reflections the same. The smallest ones are somewhere around the 6RPM of the battery motor I linked.

To make a setup yourself, the motor shouldn't carry the weight. Use a conical bearing and an axle with a gear wheel (and a mating gear on the motor of course).

With 5RPM and a diameter of 40cm, the outside of the mobile will move ~10.5cm/s - far too fast for a mobile for a baby or a toddler IMO, especially up to around 18 month, their "focus speed" ain't all that developed and a constant "fast" moving mobile may stress their brain rather than giving them a soothing experience.

Hanging it from a string, I hope you plan on eg. carbon fiber string (or an aramid fiber/Kevlar/whatever) or perhaps piano wire of a sufficient gauge (plus some, as the repeated overspinning will take its toll as well).

If you want it spinning to a slow stop before changing direction, one of the above mentioned strings/fibers will be best and you'll need a pause at each "end".
(This could be simulated in software if you used something rigid like piano wire).

If made for it, the motor would only need to add a little power in each direction, if the mobile is allowed to twist the string.

No matter how well you craft it, don't hang it directly over the little one - 1kg from just 1m above will cost you some cries at the very least - 1kg? Does it carry bricks or what?

For the purpose, I'd give serious consideration to the battery driven motor I linked, as you don't have to worry over getting the mechanical bits strong enough (besides a hook to hang it from).

It should move a mobile that weighs around 1kg and is about 40 cm in diameter. The mobile will be attached via a string, so there will be a delay in action.
You'll have to trim the pause (before reversing) to the weight etc of the total mobile, or you may get uncontrolable oscillations of a long period.

Totally off topic for this site, but I recently spotted an awesome mobile in a shop that carries wood furniture and toys - a ring of 20..30cm in diameter with strings of descending length along the circumference, each with a small (plastic) plane (different colors), arranged so it gave the impression that the planes spiral'd upwards (or v.v.) when it rotated - an easy DIY, so I'm gonna snap some photos of it soon. There was a girly version as well, so I'm gonna make one for each of my grand children
(Yeah, I could just buy them, but where's the fun in that - and then I'd have to go with what others choose, i.e. planes and the girly stuff which I didn't quite catch as I passed by).
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Engineering is based on numbers - not adjectives

#### Confugere

• Beginner
• Posts: 5
##### Re: Turn Motor 1080° forth and 1080 ° back at low speed
« Reply #5 on: October 24, 2012, 01:40:11 AM »
Oh, I would be very interrested to see some pictures of that mobile. No, the baby ist not lying directly under the mobile and it doesnt weigh 1 kg, but at some time he might grab something spinning, so I wanted to give you a kind of maximum weight. I'm a german and in germany the limits always exceed 10 times reality
Right at the moment im using a stepper motor from an old printer and I'm trying to program a speed control using a rotary controler, which only eventually works. I'm pretty new to this microcontroller, arduino business.
Maybe you have an idea regarding my code and eventually how to add a speed reduction before going the other way. (see below)
But I also looked at your MB motor which is quite a good alternative, which I will include in my next orders, but so far I would like to work on my stepper program.

Greetings Andreas

Here is my programm so far:
#include <Stepper.h>

const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int dirA = 12;
const int dirB = 13;

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, dirA, dirB);

int stepCount = 0;         // number of steps the motor has taken

int pos = 0;    // variable to store the stepper position
int vspeed = 100;
int ispeed = 10;
const int pin_A = A8;
const int pin_B = A9;
unsigned char encoder_A;
unsigned char encoder_B;
unsigned char encoder_A_prev = 0;

void setup() {
// initialize the serial port:
pinMode(pwmA, OUTPUT);
digitalWrite(pwmA, HIGH);
pinMode(pwmB, OUTPUT);
digitalWrite(pwmB, HIGH);

// Turn off the brakes
pinMode(brakeA, OUTPUT);
digitalWrite(brakeA, LOW);
pinMode(brakeB, OUTPUT);
digitalWrite(brakeB, LOW);

// Log some shit
Serial.begin(9600);
pinMode(pin_A, INPUT);
pinMode(pin_B, INPUT);
}

void loop()
{
for(pos = 0; pos < 500; pos += 1)  // goes from 0 degrees to 180 degrees
{
// step one step:
myStepper.step(1);
stepCount++;
//Serial.print("Position:" );
//Serial.println(pos);
//Serial.print("Schritte:" );
//Serial.println(stepCount);
if((!encoder_A) && (encoder_A_prev)){
// A has gone from high to low
if(encoder_B) {
// B is high so clockwise
// increase the speed via delay, dont go over 255
if(vspeed + ispeed <= 255) vspeed += ispeed;
}
else {
// B is low so counter-clockwise
// decrease the speed, dont go below 0
if(vspeed - ispeed >= 0) vspeed -= ispeed;
}
encoder_A_prev = encoder_A;
delay(vspeed);
Serial.print(vspeed);
}
}
for(pos = 500; pos >= 1; pos -= 1)  // goes from 0 degrees to 180 degrees
{
// step one step:
myStepper.step(-1);
stepCount++;
//Serial.print("Position:" );
//Serial.println(pos);
//Serial.print("Schritte:" );
//Serial.println(stepCount);
if((!encoder_A) && (encoder_A_prev)){
// A has gone from high to low
if(encoder_B) {
// B is high so clockwise
// increase the speed via delay, dont go over 255
if(vspeed + ispeed <= 255) vspeed += ispeed;
}
else {
// B is low so counter-clockwise
// decrease the speed, dont go below 0
if(vspeed - ispeed >= 0) vspeed -= ispeed;
}
}
encoder_A_prev = encoder_A;
delay(vspeed);
Serial.println(vspeed);
}
}

#### Soeren

• Supreme Robot
• Posts: 4,672
• Mind Reading: 0.0
##### Re: Turn Motor 1080° forth and 1080 ° back at low speed
« Reply #6 on: October 29, 2012, 03:23:54 PM »
Hi Andreas,

Sorry for the late reply - I've been real busy closing up a project last week and the weekend was spent on a family birthday

Oh, I would be very interrested to see some pictures of that mobile.
I'll post some when I get time to visit the shop

No, the baby ist not lying directly under the mobile and it doesnt weigh 1 kg, but at some time he might grab something spinning, so I wanted to give you a kind of maximum weight. I'm a german and in germany the limits always exceed 10 times reality
OK, then you should check Conrad.de for most of what you need. It's a marvellous shop and I envy you their low prices, even on small orders - like eg. presensitized PCB material (for photo transfer), which is under €2 at Conrad, while the exact same is around €4 at the local shop in Copenhagen (I'm a Dane) and you need to order above €100 to get is send here from Conrad at all - good thing that my sister in law is living near Kiel though

Right at the moment im using a stepper motor from an old printer and I'm trying to program a speed control using a rotary controler, which only eventually works. I'm pretty new to this microcontroller, arduino business.
Maybe you have an idea regarding my code and eventually how to add a speed reduction before going the other way. (see below)
Software in the Software forum please!

To make it easier on yourself, use sub-procedures (and test each individually), then your main loop will be clean and easy to play around with - putting it all in one loop is asking for obfuscation
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?