Ok so on saturday I will be exhibiting at maker faire so im in a rush. I made a mini 3d printed robotic arm last week to pickup candy. Its controlled by 3 potentiometers. One to move the hook up and down. One to move the arm up and down. And one to turn it 360 degrees. With the servo that turn the whole thing, I found had broke. So it cant control the exact spot its at (the potentiometer in the servo is broken) so I changed the code a bit so the more you turn it, the faster it goes. And in the middle of the potentiometers movement it stops. So I used 2 elastics so when you let go of it it goes back to "stop". It works great but the servo is super sensitive to small movements. Is there anyway I can make the servo move slower? The servo that I need to work is "myservo2" and the potentiometer that controls it is "potpin1" (val1)
#include <Servo.h>
Servo myservo1;
Servo myservo2;
Servo myservo3;
int potpin = 0;
int val;
int potpin1 = 1;
int val1;
int potpin2 = 2;
int val2;
void setup()
{
myservo1.attach(9);
myservo2.attach(10);
myservo3.attach(11);// attaches the servo on pin 9 to the servo object
}
void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo1.write(val); // sets the servo position according to the scaled value
val1 = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023)
val1 = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo2.write(val1); // sets the servo position according to the scaled value
val2 = analogRead(potpin2); // reads the value of the potentiometer (value between 0 and 1023)
val2 = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo3.write(val2); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
i_luv_arduino:
The servo that I need to work is "myservo2" and the potentiometer that controls it is "potpin1" (val1)
Wouldn't it make life a lot easier if potpin2 controlled myservo2 ? ?
Anyway, for the speed question look at the servo sweep example that comes with the Arduino IDE. By moving a little at a time you can go as slow as you want. Use servo.writeMicroseconds() if you need finer control.
The servo that I need to work is "myservo2" and the potentiometer that controls it is "potpin1"
Why? Why isn't the servo that controls the base called baseServo? Why isn't the pin that the speed control potentiometer called smithAndWesson? Or something meaningful?
Why? Why isn't the servo that controls the base called baseServo? Why isn't the pin that the speed control potentiometer called smithAndWesson? Or something meaningful?
This appears to be totally worthless as to solving the broken servo issue. Perhaps I missed something.
And in the middle of the potentiometers movement it stops. So I used 2 elastics so when you let go of it it goes back to "stop". It works great but the servo is super sensitive to small movements.
Sounds like the bad servo is now acting like a continuous rotation servo. If so maybe try mapping the bad servo to a smaller command range like below.
val1 = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023)
val1 = map(val, 0, 1023, 80, 100); // scale it to use it with the servo (value between 0 and 180)
myservo2.write(val1);
Thanks to all the replys, if anyone is reading this and cant fix a servo I simply opened it up, and epoxied the potentiometer to the last gear, the servo works fine, also I made it move in steps like you suggested, its ready for the maker-faire at last! And btw about the variable names it shouldn't matter what I want to call them, as long as I know what they do.
i_luv_arduino:
And btw about the variable names it shouldn't matter what I want to call them, as long as I know what they do.
Of course the compiler does not care. But it is a lot more meticulous than us humans. Using meaningful and consistent names for variable makes the logic easier to understand - especially when problems arise.
Will you remember (without any effort) what those variable do, and how they relate to each other, in 6 months time?