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:
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:
#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);
}