Pages: [1]   Go Down
Author Topic: 05/Mood cue - servo tries to turn more  (Read 3287 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
#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);
}
« Last Edit: February 06, 2013, 05:40:43 pm by gapan » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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?


Logged

Pages: [1]   Go Up
Jump to: