Servo not working with nodemcu 0.9 esp-12 ESP8266

trying to run basic sketch sweep.

servo does nothing despite fidgeting when initial plug in.

Servo Motor MG995 360 Degree Continuous Rotation - ProtoSupplies

It needs 4.8-7.2 V
and micro usb gives 5V & 1 Amp

processor nodemcu 0.9 esp-12

what's wrong

/* Sweep
 by BARRAGAN <http://barraganstudio.com>
 This example code is in the public domain.

 modified 8 Nov 2013
 by Scott Fitzgerald
 https://www.arduino.cc/en/Tutorial/LibraryExamples/Sweep
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(D1);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
}

The drawing looks okey.
Can You use a DMM and check Vcc at the servo?
Is the servo logic level the same as the ESP8266?

Plenty of servos (54 pages) in that link. Can You get down to the servo You use and post a link to it?

I don't understand

There are circuits/devices using 0 - 3.3 volt logic and other devices using 0 to 5 volt logic. They are not straight on compatible.
The signal the servo uses is most likely 0 to 5.0 volt.
I don't know the ESP that well but suspect its output is like 0 to 3.3 volt level. Often 5 volt devices work being given 0 to 3.3 volt signals.
I didn't find the exact datasheet of Your servo so I can't say for sure if that's the problem.

I edited the link would you be willing to look at it. And I just ordered a multimeter should be here tomorrow. I also changed my code but it didn't do anything

Thanks. That servo needs a power supply capable of delivering 1.5 amp. This current is used when starting from standing still. What is the rating of the supply You use?

I found no data indicating any logic fault. (3.3 versus 5 volt)

ESP8266 is a 3.3V device, so the HIGH voltage on an output pin is 3.3V, not 5V. But all servos I tried so far worked with 3.3V at the signal input.
A problem may be the D1 output pin. GPIO1 is TX of Serial, and by default used for debug output.
Did you try another pin, e.g. GPIO5?

And sometimes there is a little bit confusion with the Dx numbering and the GPIO numbering. Can you make a photo of your board?

E.g. compare this:
esp12
and this

I would always recommend to use the GPIO numbers directly ( without 'D' )

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.