Pages: 1 [2]   Go Down
Author Topic: My Servo won't move [SOLVED]  (Read 2080 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50512
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
     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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
Against Stupidity, the gods themselves contend in vain.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
Against Stupidity, the gods themselves contend in vain.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
Against Stupidity, the gods themselves contend in vain.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26538
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
Against Stupidity, the gods themselves contend in vain.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Pages: 1 [2]   Go Up
Jump to: