Servomotor spinning wild

Hi there!
I was following a tutorial that was about a potentiometer that controls a servomotor.
I checked all the connections and the code, and all was fine. But there are several things that I don't understand in the failure and I wasn't able to find looking for the solution.

At the beginning it worked right, but when the potentiometer(pot), was fully open, the servo began to move weird going ahead and backwards for a "microseconds", and the servo began to spin out of control, giving several 360 turns. I disconnected.
If I connected with the pot fully open, it directly spin out of control.
If I try to reset the case, it keeps repeating the failure, at certain point it loses the control.

Possible mistakes:
In the tutorial they say that you should power the servo with an external output, an power adapter for 7 to 9 V I think. I don't have one, so I used the 9v battery that comes with the kit with the jack cable. I also connected the Arduino with the USB cable tu upload the sketch. I'm a newbie, and I let both cables connected. But when I disconnected the USB from PC cable, the Arduino was still with lights, but the servo didn't move anything.
The other day I did the pot with led project, and the light didn't turn off completely when the pot was closed. So I guess that the pot maybe is broken.
Doubts
My servo has turned 360 degrees about 20 times, I read that it goes only from 0 to 180. Do I messed up?it still turns.
How do you give power to the board with the jack cable and give the signal with the USB cable?

Code:

#include <Servo.h>

Servo servo1;

int PINSERVO=2;
int PULSOMIN=1000;
int PULSOMAX=2000;
int VALORPOT;
int ANGULO;
int POT=0;

void setup(){
  servo1.attach(PINSERVO, PULSOMIN, PULSOMAX);
  
}

void loop(){
  VALORPOT=analogRead(POT);
  ANGULO=map(VALORPOT,0,1023,0,180);
  servo1.write(ANGULO);
  delay(20);
}

The image and the code are owned from Bitwise Ar at the following link

Thanks a lot

If that is a PP3 then it cannot supply enough current at the required voltage for very long

You have a continuous rotation "servo" and can only control its speed and direction, not its position

It's a pp3 but it didn't move the pot-servo, it was a new one and it was connected about 2 hours.

I looked for the motor an it says that it's 0-180°, it's the servomotor sg90. But you are right, and I don't understand nothing T_T

And thanks a lot

So either that is not the servo you have or you broke it.

Yes that is enough time to totally flatten a little battery like that

Look around for a power supply - most households end up with a collection of small transformers such as those used to charge mobile phones.

Is there a way to know o check if it's broked? I had thought to try to:

servo1.write(try different degrees);

Also I want to try the potenciometer, I watched a video to test it with a multimeter.
What do you do if something fails in a project?

Interesting, I thought that it'll take several days to discharge the battery.

And thanks a lot

I haven't thought about that. I'll look for it. Thanks a lot

I also have SG90 servos like this. The internal stops seem to break easily, and then the servo can 'spin' if controlled with an incorrect pulse length.

We need to see a diagram of exactly how you connected the 9V to this circuit. It looks like you did not do this correctly and maybe damaged the Arduino. The fact that the light is on just tells you power is being applied to the Arduino. It in no way tells you it is working.

Can you load a blink sketch? If so your Arduino is OK.
Can you dim an LED with the pot? If so your pot is working.
Can you dim it the full range? If not then use the serial print to show what values you are getting from your pot in the monitor.

Hi MicroBahner, I'm considering to buy another servo, the MG996R, because of your comment.

The last thing: when we talk about setting the pulse width, to enter the min and max values, we are modifying the duty cycle and the degrees that the servo spins. I put at the beginning 1000 and 2000, and later 50 and 3500. The servo keeps spinning at the same way. Why?

Thanks a lot

I don't know what I've just did, but it works perfectly. I cheked the pot with the multimeter, and I looked for an external power source. But it worked with the pp3 battery, the usb cable and the external source, I guess because the servo is too small.

I don't know. WIth min/max of 1000/2000 my servos didn't behave that strange, only with too short or too long. But 50 and 3500 is definitely out of range.

1 Like

My guess is that you had a loose connector that was not making electrical contact. Using when using solderless bread board this almost always happens. It is a big waste of time.

1 Like

Thanks a lot

Thanks a lot

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