Micro servo motor problem

Hello everyone!

I'm new at arduino and all stuffs about that.

I got an Otto robot kit with 4 servo motor, Arduino nano, Arduino sensor shield included.

When I'm starting to do some basic programming with these setup. I got some problems with my servo motors.

When I try to run this code for rotating 45 degree one of my servo motor, it rotating forever. I searched almost every article about this issue but nothing could solve.

Note: The arduino nano's power supply coming from usb cable that connected to the PC.

#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(4); // attaches the servo on pin 9 to the servo object

}

void loop()

{

for(pos = 0; pos < 45; pos++) // 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(15); // waits 15ms for the servo to reach the position

}

}

type or paste code here

That’s because loop( ) runs over and over, forever.

Exit from the loop also doesn't work. I tried it...

Wellcome. Read this topic and see what You can add to Your post: How to get the best out of this forum - Using Arduino / Project Guidance - Arduino Forum

This sounds not correct. Learn the difference between a servo motor and a servo. They are very different in what they do.
Don't expect helpers to use that kit. We are newbies to it, know nothing. Think like this: How will You explain the situation for Your grandmother?

That can be not good. USB is not made for supplying motor currents. Some USB only provide 0.5 Amps. Motors should in general not be powered by the controller board.

... immediately calls loop again.

Post code.

This doesn’t describe what you tried.


void loop()
{
static bool Flag;

if(Flag == false)
{
for(pos = 0; pos <= 45; pos++) // goes from 0 degrees to 45 degrees
{ 
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
} //END of   for( )

Flag = true;
} //END of  if( )

} //END of   loop( )

Hi railroader

Thank you for helping.

I will definitely consider your advice.

Understood, I will connect the motors to external PSU and will test it. Thank You!

even this code doesn't solve...

I think it's happen because of power supply, maybe it cannot handle the motors or something

Making sure there's power for the stuff, controller, motors etc is number one. No code on earth can make things run if there's not power enough.

If You can provide links to the datasheets of the motors and sensors it would be good help for us.

This describes a “continuous servo motor” not a regular servo !

This code will execute a loop that will iterate 45 times. The loop variable, pos , is initialized to 0 before the loop starts. On each iteration of the loop, the value of pos will be incremented by 1. The loop will continue to execute until the value of pos is no longer less than 45.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.