I have an Arduino Uno R3 as well as a NodeMCU ESP8266. I am attempting to make the MG995 Servo spin to certain angles. My setup works when connected to the Arduino Uno R3, but does not work too well when connected to the NodeMCU.
As you may note in this code, I am attempting to spin the servo clockwise and counterclockwise with time intervals in between. When working with the Arduino, it works fine. However, when connected to the NodeMCU, the servo only moves approximately half of what I am asking it to do. For example, it spins 90 degrees clockwise and anticlockwise.
For the NodeMCU circuit, I am using a mini breadboard. I have connected a 5mm Terminal Block which is receiving power from a 5V2A power supply brick connected to a wall socket. I have connected GND to GND and POWER to POWER on the servo. I have confirmed that the servo works as intended and this is the same setup I use when connected to the Arduino Uno R3. I have the servo's signal power connected to D4 on the NodeMCU (which is GPIO 2). I have the NodeMCU GND connected to the same GND as the servo (via the breadboard). I am powering the NodeMCU via the USB port and connected to my laptop.
The setup for the NodeMCU is the exact same as the one with the Arduino Uno (except I connect the servo's signal wire to GPIO 9 on the Arduino). So I am not sure what is causing the servo to not fully rotate.
Just to add to my original post, I have also tested this with the NodeMCU ESP32. In this case, instead of the standard Servo.h library, I used the ESP32Servo.h library. With the exact same setup, it worked perfectly.
Is this perhaps a library issue? Where the standard Servo.h library is incompatible with the NodeMCU ESP8266? If so, is there a specific library I might be able to use with it (like I have done with the ESP32)?
yaa there is an issue with default servo library.it won't allow you to move servo motor more than 90 degrees on nodemcu/esp8266. i tried arduino create agent where we can upload code via browser then it was working fine.
Hi kilgag, I tested your suggestion, and it works! But I would like to know why. The SG90 has a duty cycle of 1 ms ranging from 1 ms to 2 ms. Therefore, the correct parameters in the .attach() method should be 1000 and 2000, isn't it? But I tested that, and it does not work.