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?
#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
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?
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.
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.