Go Down

Topic: 05/Mood cue - servo tries to turn more (Read 6163 times) previous topic - next topic

gapan

Feb 06, 2013, 11:35 pm Last Edit: Feb 06, 2013, 11:40 pm by gapan Reason: 1
I'm a complete newbie at electronics, but I got myself a starter kit yesterday and so far I'm loving it. I've gone through the mood cue project and I have noticed that if I map the angle as is suggested:
Code: [Select]
angle = map(potVal, 0, 1023, 0, 179);
then when I turn the potentiometer all the way to max and the angle reaches 179, the servo is still trying to turn. Of course it cannot turn, it's all the way to the end, but I can hear the motor struggling, it's even moving the servo on my desk due to the vibration and it won't stop unless I turn it back down a bit. Same thing if I map the max to anything >=175.

If I map the angle to 0-170 degrees though, it doesn't do that. It just stops working as I expected it to do anyway.

Since I have never used a servo before in my life, my questions are: why is it doing that? Is that normal for a servo? Or for the servo bundled in the kit for that matter? Or am I probably doing something wrong?

I even changed the layout a bit, removed the potentiometer and added two buttons, one to increase the angle, the other to decrease it and an LED to show if I've reached the limits. And it still does that if I use anything from 175 to 179 as the max limit, so I think I've ruled out the potentiometer as the cause. Here's the code I'm using for this layout, though I don't think it really matters:
Code: [Select]
#include <Servo.h>

Servo myServo;

const int ledPin = 8;
const int servoPin = 11;
const int sw1 = 4;
const int sw2 = 7;
int sw1State = LOW;
int sw2State = LOW;
int servoDeg = 0;

void setup() {
 myServo.attach(servoPin);
 Serial.begin(9600);
 pinMode(ledPin, OUTPUT);
 myServo.write(servoDeg);
 pinMode(sw1, INPUT);
 pinMode(sw2, INPUT);
}

void loop() {
 sw1State = digitalRead(sw1);
 sw2State = digitalRead(sw2);
 if (sw1State == HIGH && sw2State == HIGH) {
 }
 else if (sw1State == HIGH) {
   if (servoDeg < 170) {
     digitalWrite(ledPin, LOW);
     servoDeg = servoDeg + 1;
   }
   else {
     digitalWrite(ledPin, HIGH);
   }
 }
 else if (sw2State == HIGH) {
   if (servoDeg > 0) {
     digitalWrite(ledPin, LOW);
     servoDeg = servoDeg - 1;
   }
   else {
     digitalWrite(ledPin, HIGH);
   }
 }
 Serial.println(servoDeg);
 digitalWrite(ledPin, LOW);
 myServo.write(servoDeg);
 delay(10);
}

I face the same problem on my starter kit. Until servo angle < 169 everything is fine. I also noticed that the poti is "shaking" at max level between 1015 up to 1023 Ohm. Here is an example for this:

Code: [Select]

otVal: 1023, angle: 179
potVal: 1015, angle: 177
potVal: 1023, angle: 179
potVal: 1023, angle: 179
potVal: 1016, angle: 177
potVal: 1023, angle: 179
potVal: 1023, angle: 179
potVal: 1016, angle: 177
potVal: 1023, angle: 179
potVal: 1015, angle: 177
potVal: 1016, angle: 177
potVal: 1023, angle: 179
potVal: 1015, angle: 177


Could this be the reason for this?



blfuentes

Yesterday I tried this example with my starter kit and I noticed the same issue. Over 170 the servo starts shaking ...

A223D

Dude, I had the same problem too. And I found the solution. The problem is not in your code or servo. The problem is in your potentiometer. It's not fixed correctly. Try pressing the pot meter down into the breadboard when you turn the knob or look for a more permanent solution to the press the pot meter into the breadboard.




Hope it helps......

stevemehh

I had the same issue and thought it to be the potentiometer but after testing the resistance on a multimeter the pot seemed fine.

I ran a few numbers and the capacitor connected to the servo appeared to be redundant.

Remove the capacitor from the servo connection and it will work fine

Go Up