Go Down

Topic: Servo Motor Random movement after powering it (Read 2029 times) previous topic - next topic

siren215

Hello all,

I am using TowerPro MG996R motor for my testing purposes. Once i make sure that the code is ok, i will buy a better motor. My aim is to move it from 0° to 50° according to analog input 0 to 5 VDC. It moves when i keep it powered on, no problem with that. Now when i power it off and the power it on again, it moves right by say 45 to 50° and then gets its position(in between 0 to 50). This changes the fixed range of the motor to move and a new range of 0 to 50 ° is obtained i.e its initial position when I start it is changed. I want it to start at exact 0 when i power on. I am using a simple knob program to start off with, but this initial position keeps worrying me.

Code: [Select]
#include <Servo.h>

Servo myservo;  // create servo object to control a servo

int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

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

void loop()
{
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 50);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
}


Motor Specifications

Also now i am powering it from UNO itself, how much power supply is needed to power it externally? i tried 5v/1Amp supply, but it loads.


Thank You

MarkT

Always allow an amp per servo minimum, never power a servo from the Arduino's 5V.  Common the grounds.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

siren215

#2
Sep 08, 2015, 05:24 pm Last Edit: Sep 08, 2015, 05:51 pm by siren215
Can you suggest a suitable supply for it? Why my power supply didnt work?

Chagrin

In your setup() you need to write() the initial position before you attach() it. If you skip that step then the servo is written the DEFAULT_PULSE_WIDTH (1500us, defined in Servo.h) for a fraction of a moment before you perform your own write() in main().

MarkT

Can you suggest a suitable supply for it? Why my power supply didnt work?
Ah, read the specs, the stall current is 2.5A.  You'll need a PSU rated for that current or it'll
just reset every time you try to move (servos pull stall current everytime they do a move
or any size - you might get away with slow ramping at 1A, but not a step change)
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

siren215

In your setup() you need to write() the initial position before you attach() it. If you skip that step then the servo is written the DEFAULT_PULSE_WIDTH (1500us, defined in Servo.h) for a fraction of a moment before you perform your own write() in main().
Thx, did that. Hope that issue is resolved.

Ah, read the specs, the stall current is 2.5A.  You'll need a PSU rated for that current or it'll
just reset every time you try to move (servos pull stall current everytime they do a move
or any size - you might get away with slow ramping at 1A, but not a step change)
Exactly the same thing happened. I will try to get a 2.5 Amps supply or 3 Amps supply for it, and lets see how it goes. Thanks again for suggestion guys.

TomGeorge

Hi,

When you use a separate supply for the servo, do you connect the gnd of the arduino and the gnd of the separate supply together?

Tom..... :)
Everything runs on smoke, let the smoke out, it stops running....

Go Up