Hello I am brand new to Arduino and the forum. I am using the Vilros starter kit.
I created a spin off of example 8 with the servo write function ( I am using the library Servo.h)
In my circuit I created, I have a potentiometer as an analog input that moves the servo to its full range from 0 to 180.
I also have a LED light that turns on when the pot is at its max value. My question is the servo moves smoothly until the pot reaches it max value, the servo seems to waver or go intermittent between values at its max value. (resulting in the LED flickering as well)
If I use the seriel print feature the value is switching between about 174 and 179 when the pot is fully turned. However at all other values it is relatively stable.
Am I missing something really simple or is this a limitation of the pot or servo. attached is my code.
#include <Servo.h> // servo library
Servo servo1; // servo control object
int potPin =0;
int ledPin = 13;
int potVal;
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
servo1.attach(9);
}
How is the servo powered? Many hobby servos won't really go from 0 to180. If you try to drive the servo too far the motor will stall and pull maximum current. It is best to experimentally find the physical limits of the servo so as not to exceed the limits if you need the full range.
It is hard to see what the max will be. If I try to read pin 9 using serial print it comes back as 0. I would love to see the raw signal the servo is getting rather than just trust the included library servo.h.
For instance I have no idea what signal is actually being sent from pin 9 to the servo when I use servo.write(#)
i think you are getting confused because the same potval is being used and converted at different points in the loop
void loop()
{
potVal = analogRead(potPin);
at this point potVal is the raw input from the potpin which has a range of 0-1023
if you add a Serial.println(potVal); you will see the raw input on the pin
if you add a Serial.print("pot input: "); before that line it will make more sense when printed
potVal = map(potVal, 0, 1023, 0, 179);
at this point potVal is now the raw potpin value but the range is now between 0-179
servo1.write(potVal);
delay(30);
the next line will print what is being sent to the servo
Am I missing something really simple or is this a limitation of the pot or servo. attached is my code.
If you are powering the servo from the arduino, then when the servo hits internal end stop and stalls, the servo will pull enough current to in effect short out your arduino causing it to repeatedly reset. If the servo is large, it could possibly trip out your USB port on over current.
It is hard to see what the max will be. If I try to read pin 9 using serial print it comes back as 0. I would love to see the raw signal the servo is getting rather than just trust the included library servo.h.
For instance I have no idea what signal is actually being sent from pin 9 to the servo when I use servo.write(#)
but that is another question I suppose.
Never power a servo from Arduino 5V and never power a servo from a USB socket. Both
risk expensive damage and will not work as you have found out.
Servos take an amp or more and put noise spikes on the rail, Arduino and USB cannot
supply more than 0.5A and can be destroyed by overvoltage spikes.