I am just starting with Arduino, got "Most Complete Starter kit" and am running Lesson 9 Servo:
Micro Servo SG90
Arduino Mega 2560
The Servo does not complete 180º of rotation, only about 0 -> 165º, I wonder why?
After some research on this Forum, I've noticed similar (not equal) problems, and I've tried code and explanations on those posts, using to similar programs:
50 years since a class on microprocessors but the timing used then was 500 to 2500, middle point at 1500 microseconds at 50 Hz.
Does the library handling add micros?
Mea culpa; I took the comment in Servo.h at face value when it said "default min is 544, max is 2400". Looking further down the page, it's actually 500 and 2400 - except in the cases where it really is redefined by some boards as 544 and 2400.
Are you powering the servo with an external 5V and connecting all the grounds together? Your code looks fine, with all ^ bases covered, it may just be that those servos are inexpensive and made in such numbers that precision to their specification is not their forte.
Not normal but typical. I have 5 various "cheapy" servos, none of them will do full 180°. Here's a test program.
/*
Try this test sketch with the Servo library to see how your
servo responds to different settings, type a position
(0 to 180) or if you type a number greater than 180 it will be
interpreted as microseconds(544 to 2400), in the top of serial
monitor and hit [ENTER], start at 90 (or 1472) and work your
way toward zero (544) 5 degrees (or 50 micros) at a time, then
toward 180 (2400).
*/
#include <Servo.h>
Servo servo;
void setup() {
// initialize serial:
Serial.begin(9600); // set serial monitor baud rate to match
// set serial monitor line ending to "NewLine"
servo.write(90);
servo.attach(9);
prntIt();
}
void loop() {
// if there's any serial available, read it:
while (Serial.available() > 0) {
// look for the next valid integer in the incoming serial stream:
int pos = Serial.parseInt();
if(Serial.read() == '\n'){} //skip 1 second delay
pos = constrain(pos, 0, 2400);
servo.write(pos);
prntIt();
}
}
void prntIt()
{
Serial.print(" degrees = ");
Serial.print(servo.read());
Serial.print("\t");
Serial.print("microseconds = ");
Serial.println(servo.readMicroseconds());
}
Indeed I am, but had to find it on my own, the tutorial lesson wires it directly to the board (already left a comment with the Tutorial manufacturer), and behaviour is completely different for all different source of code values. I've started trying to solve this issue, and now I always power the board with the 9V AC adapter, thank you.
Thank you. I am still going throught the basic tutorial lessons and haven't reached yet to the serial monitor setup.
When I am done with it, I will come back here, test this code you sent me and shall keep you posted.
Thank you very much.