Go Down

Topic: My Servo won't move [SOLVED] (Read 2409 times) previous topic - next topic

PaulS

Code: [Select]
     Serial.print("Raw value: ");
     Serial.println(number);
     Serial.print("Servo angle: ");
     Serial.println(sVal);

number is a float. By default, floats are printed to two decimal places. You need an optional 2nd argument to get more (or less) than 2 decimal places.

InventiousTech

Well, that would do it. Any other ideas about the servo?

PeterH

If the sweep example works then the hardware should be OK. I can't see any reason why the sketch shouldn't move the servo to the angle it is printing out, so there's a faulty assumption here somewhere.

I suggest you take a copy of the sketch and replace the whole of loop() with something like this:

Code: [Select]

void loop()
{
  delay(5000);
 sVal = 134;
 myservo.write(sVal);
 Serial.print("Servo angle: ");
 Serial.println(sVal);
}


If everything works as we assume, the sketch should move the servo to angle 90, wait five seconds and then move it to angle 134. It will also print out a message to show that it has done it. Does it print out the message? Does the servo move as expected?
I only provide help via the forum - please do not contact me for private consultancy.

InventiousTech

Ok, I tried what you said, the servo moves as expected, and the message prints just fine. Now I will try bringing back the servo related bits of the void loop and see what happens.

InventiousTech

Got it working, it had to do with the fact that sVal was assigning improperly due to being an integer. I mad sVal a float, and it started working, but I had to type cast sVal to int in the myservo.write statement.

AWOL

Quote
I had to type cast sVal to int in the myservo.write statement.

You didn't have to, but it would do no harm.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

InventiousTech


You didn't have to, but it would do no harm.


Hmm, well it didn't work before I type cast it. Oh well, it works. Anyway, thanks guys for all the help!

Go Up