Servo motor doesn't go beyond 90 degrees

feno

Feb 7, 2023
2
Joined
Feb 7, 2023
Messages
2
Newbie here. I have interfaced Tower Pro SG90 motor with raspberrypi and ran sweep.py which takes the motor arm from 0 to 180 degrees perfectly fine, but when I interface the same motor with ESP8266 and use <servo.h> library the motor just don't go beyond 90 degrees. Motor is fine and is connected to 5V supply too (Tried on board 5V and external as well). Its mind boggling and I cant find any help anywhere on this.

Here is sample program

#include <Servo.h>
Servo myservo;
void setup ()
{
myservo.attach(0);
}
void loop ()
{
myservo.write(0);
delay(1000);
myservo.write(180);
delay(2000);
myservo.write(0);
delay(1000);
}

Even tried writing in milliseconds but same results

#include <Servo.h>
Servo myservo;
void setup()
{
myservo.attach(0);
myservo.writeMicroseconds(1500);
}
void loop() {
delay(500); // set servo to mid-point;
myservo.writeMicroseconds(0);
delay(500); // set servo to mid-point;
myservo.writeMicroseconds(3000);
delay(500); // set servo to mid-point;
}
 

Bluejets

Oct 5, 2014
7,374
Joined
Oct 5, 2014
Messages
7,374
Show data sheet on the servo in question.
Also show library you used previously and the one you use now.
 
Last edited:

danadak

Feb 19, 2021
1,063
Joined
Feb 19, 2021
Messages
1,063
Does library run servo - 90 to + 90 ?


Regards, Dana.
 

feno

Feb 7, 2023
2
Joined
Feb 7, 2023
Messages
2
This solved the problem , apparently servo.h doesnt handle servos well on ESP8266

myservo.attach(0, 500, 2400);
myservo.writeMicroseconds(500);
myservo.writeMicroseconds(3000);
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
14,271
Joined
Nov 17, 2011
Messages
14,271
Does library run servo - 90 to + 90 ?
I'd think this to be a matter of definition. Acc. to the library's documentation the servo angle is controlled between 0 ° and 180 °. However, if you consider the 90 ° library value as the midpoint and define this as the 0 ° physical position, then the servo obviously moves between
-90 ° physical == 0 ° library value and
+90 ° physical == 180 ° library value.
 
Top