[Solved] Question about Project 5: Servo w/ Pot

Hey guys, I did Project 5 from the starter kit and I have a question. I just want to understand this better. I have the Arudino Uno w/ Starter Kit. I'm using the given schematics from the project book.

So the project just tries to have you control a servo with a potentiometer. What I noticed was the servo motor continues to run after it opens fully (potVal: 1023, angle: 179). It doesn't do this when its fully closed (potVal: 0, angle: 0). This makes me not want to leave the servo at the 179 degree position because I don't want the motor to stay running. Actually when I look at the Serial Monitor, this happens from angle 174 to 179 (eg - potVal: 1023, angle 174).

Why could this be? It doesn't make sense to me that the input from the pot could reach 1023 before the output to the servo reached 179 with

angle = map(potVal, 0, 1023, 0, 179);

Thanks for reading! Here's the rest of my code:

#include <Servo.h>
Servo myServo;
int const potPin = A0;
int potVal;
int angle;

void setup() {
 myServo.attach(9);
 Serial.begin(9600);
}

void loop() {
  potVal = analogRead(potPin);
  Serial.print("potVal: ");
  Serial.print(potVal);
  angle = map(potVal, 0, 1023, 0, 179);
  Serial.print(", angle: ");
  Serial.println(angle);
  myServo.write(angle);
  delay(15);
}

Wait, maybe I was wrong about reaching 1023 at 174, because I didn't save the serial monitor info and I can't duplicate it.

But that still doesn't explain why it keeps running in the fully opened position. Or why the angle jumps around like that between 177 and 179.

potVal: 1023, angle: 179
potVal: 1013, angle: 177
potVal: 1023, angle: 179
potVal: 1014, angle: 177
potVal: 1021, angle: 178
potVal: 1023, angle: 179
potVal: 1012, angle: 177
potVal: 1023, angle: 179
potVal: 1023, angle: 179
potVal: 1012, angle: 177
potVal: 1023, angle: 179
potVal: 1023, angle: 179
potVal: 1013, angle: 177

WMath.cpp

long map(long x, long in_min, long in_max, long out_min, long out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

That piece of serial monitor is when the pot is at a fixed position? If so, the pot you use is not very good at the far end and jumps around a bit. Because I see ADC readings between 1012 and 1023. And because it jumps around a bit the servo position will as well.

And another thing to notice. A servo can jitter a bit if it's in a position. So it moves a little bit around the set point and it makes a buzzing noise. Cheap servo's do this more then the better ones.

Hey guys, I did Project 5 from the starter kit...

Does it have you powering the servo from the arduino?

awol - thanks for the reference

septillion - yes, that piece from the serial monitor is when the pot is in a fixed position. you're probably right, it's probably due to cheap parts.

zoomkat - yes, arduino-powered

Thank you all, i think my question is answered : )

zoomkat:
Does it have you powering the servo from the arduino?

jtdoria:
zoomkat - yes, arduino-powered

Bzzzzzt, wrong answer 8)

zk was hoping you would say "no": a servo should not be powered from the Arduino, although it is of course controlled from the Arduino. Conventional wisdom is to provide servo/s with external power, as shown below for 3 servos. Make sure to join the grounds as shown.

servo power.png