Interfacing Servo Motor With NodeMCU




About: " Work until you no longer have to introduce yourself " Show some love on Instagram & Motivate me on YouTube @TheCircuit


This here is my first Instructable project.

So you want to get started with NodeMCU? Well, I'm here to share with you.Today, I'm going to show you how to get started with NodeMCU. Let's GO !

NodeMCU has on board ESP8266-12E makes the board suitable for IoT (Internet Of Things). In this Instructable I will show you how to get started with Servo using NodeMCU.

Step 1: Materials Required

Here is the list of components required to get started with the NodeMCU,

Hardware Components

  1. NodeMCU
  2. Servo Motor
  3. Bread Board
  4. Jumper Wires
  5. Micro USB Cable

Software Components

  1. Arduino IDE

Step 2: Hardware Description

What is a Breadboard?

Its a prototyping platform, where you can plug components and remove them easily. Please refer to the photo to see how its made inside. There is usually 2 bands on each sides indicating the power rails. Its made to easily connect all of the (-) and (+) together.

What is a Servo?

Servo motors are great devices that can turn to a specified angle or called position.

Usually, they have a servo arm that can turn 180 degrees. Using the NodeMCU, we can control a servo to go to a specified position. As simple as that! Here we will see how to connect a servo motor and then how to turn it to different positions.

Connection to Servo

The next job is to connect your servo motor. There are two common types of servo:

  1. White - Red - Black wired servo
  2. Orange - Red - Brown wired servo

If your servo has White - Red - Black wires, then connect it as follows

  • White wire connects to Digital pin D4
  • Black wire connects to GND pin
  • Red wire connects to 3V3 pin

If your servo has Orange - Red - Brown wires, then connect it as follows

  • Orange wire connects to Digital pin D4.
  • Brown wire connects to GND pin
  • Red wire connects to 3V3 pin

Step 3: Download Arduino IDE

To get started we need to download the Arduino IDE (Integrated Development Environment) and some necessary drivers.

  1. To download the software head over to the Arduino site:
  2. Click on Software Click on either Windows, Mac or Linux based on your Operating System.
  3. You can donate if you want or just download.
  4. When this is done, you will simply need to continue the steps to download it to your computer.
  5. You are done!

Step 4: Preparing the Arduino IDE

After downloading the Arduino IDE navigate to

  1. File tab and then click on Preferences.
  2. In the additional Boards Manager URLs add the following link (
  3. Click OK and then navigate to
  4. Tools - Boards - Boards Manager

In the search field type esp8266 > click the esp8266 by ESP8266 Community - Click Install

Now you have setup the Arduino IDE to work along with the NodeMCU.

Step 5: Coding Time

The next step is to write some code to control the Servo.

Download the "Servo.ino" file and open it up in the Arduino IDE. Then Create a new sketch and paste the code below in the arduino IDE and hit Upload.

#include <Servo.h>

Servo servo;

void setup() {

servo.attach(2); //D4




void loop() {






The code will take a few minutes to upload and then you should see the Servo changing angle from 0° to 90° at the interval set in the code.

You can tinker with it if you like, or just use it as it is.

Step 6: Upload Your Program

  1. Goto Tools
  2. Board > NodeMCU 1.0 (ESP - 12E Module)
  3. Port ( Choose the right Port )

**Make sure you have your NodeMCU model selected and the correct serial port ticked (see pics).

Then just click the Upload button**

Ready To GO



    • Tape Contest

      Tape Contest
    • Arduino Contest 2019

      Arduino Contest 2019
    • Trash to Treasure

      Trash to Treasure

    13 Discussions


    Question 2 months ago on Step 6

    I tired this and I got a constant erratic jitter from the motor. It would change behavior or stop the jitter when I giggled the wires. Everything started working as expected when I moved my power pin to VIN. I thought servos needed the 5V so I was happy to see this say otherwise. So am I missing something? It would be great to get this to work off the 3.3v power pins and some people claim success. I am fairly new to this so any input is greatly appreciated.


    3 months ago

    It worked like a charm!!!. I conected directly the servo to the board, because the Gnd, 3.3v and D4 are together!


    4 months ago

    I did everything that was here and I keep getting this error: espcomm_upload_mem failed
    I will upload an exact picture of my diagram.
    And I did replace D4 with where my servo is hooked up to D5.

    wemo WiFi board.JPG

    7 months ago

    followed all steps,working.Thanks


    1 year ago

    Servos don't work well in powered by 3.3V

    You need to connect the power of the servo to 5V. If you are powering the arduino by USB, use to Vin pin to power the servo (the servo admits 3.3V in logic, so that is not a problem. You only need to change one cable).


    1 year ago

    Good job!

    Did you use a SG90 servomotor? I read in some datasheets that it's design for a 4.8 - 5 V power input, but you connected it to NodeMCU 3.3V pin. Was the servo too weak when using 3.3V as supply voltage?


    1 year ago

    I followed each and every step still my motor is not rotating

    1 reply

    Reply 1 year ago

    Check the pin connections. You'll definitely get the output.


    1 year ago

    In ur project u haven't used IOT you have simply uploaded a servo code to nodemcu ....

    1 reply

    Reply 1 year ago

    Yes.. I will use IoT in further instructables.. And Thank You for your suggestions :)