Hello guys!
I have a little tricky problem, were I already spent hours... So I hope you can help me
I want to move with my Arduino Uno a Servo in it's whole range continuously going left-right-left-right...
A first easy solution: analogWrite()
boolean countUp = true;
int Start = 0;
int Ende = 255;
int Position = Start;
void loop() {
analogWrite(3, Position);
if(Position==Ende){
countUp=false;
}
if(Position==Start){
countUp=true;
}
if(countUp==true){
Position++;
}
else{
Position--;
}
delay(30);
}
At first appeareance it works.
BUT: There are random problems. Sometimes the servo stops, or moves back. Then goes on.
What did I do wrong? (also have to say, that I have a external power supply for the servo and the board's power I connected via USB)
Second solution: using the library
#include <Servo.h>
Servo myservo;
int var = 0;
void setup() {
myservo.attach(3);
}
void loop() {
myservo.write(var);
delay(100);
var=var+3;
if(var>180){
var=0;
delay(300);
}
}
Now it seams to work without the random-errors. At first: why this?
AND: I have a realy small range now the servo is moving! This are maybe like 100°. And if I move the servo by hand I see, that it has like 200°.
How can I expand the range? Is normally the whole range usabel I see moving it by hand?
I´m really exited what you say. Maybe someone of you know what the problems are...
Thanks a lot,
Marcus