STEP 1 / 6ESP + IOT

ESP8266 NodeMCU Web Server: Control Stepper Motor (WebSocket)

(WebSocket) In this Project, you will learn how to use the ESP8266 NodeMCU board to make a web server that shows a web page to control a stepper motor. On the website, you can type in the…

ESP8266 NodeMCU Web Server: Control Stepper Motor (WebSocket) - source illustration from page 977
PROJECT#417
TRACKIoT
PARTS05
STAGES06
STEP 1 / 6 · Overview

Know the mission before touching a wire.

Understand what you are making, prepare the right tools, and make the workbench safe.

01

Project details

ESP8266 NodeMCU Web Server: Control Stepper Motor (WebSocket) is a iot project. (WebSocket) In this Project, you will learn how to use the ESP8266 NodeMCU board to make a web server that shows a web page to control a stepper motor. On the website, you can type in the…

Source pages
977-981
Named parts
5
Build goal
Working, tested prototype
02

Tools you need

  • Digital multimeter
  • Wire stripper and side cutters
  • Soldering iron with a fine tip
  • Current-limited bench supply
  • Computer with a data-capable USB cable

Use eye protection, good lighting, and a clean insulated surface throughout the build.

03

Safety precautions

  • Disconnect every power source before changing a connection.
  • Check component polarity, pinout, and supply voltage twice.
  • Use a current limit for the first power-up.
  • Keep liquids, loose metal, and uninsulated wires away from the bench.
Ready to continue?
STEP 2 / 6 · Parts library

Gather, identify, and understand every part.

Use the standardized inventory, then open What's this? to learn each part's role, advantages, limitations, handling, and specifications.

NAMED PROJECT INVENTORY5 PART LINES
PARTTYPEQTYREADY
MESP8266MODULE1
What's this?Image, role, pros, cons, handling & specifications
ESP8266 NodeMCU Web Server: Control Stepper Motor (WebSocket) - source illustration from page 977MODULE LEARNING VIEW

ESP8266

A programmable controller that reads inputs, makes decisions, and drives the project's outputs.

What it does here

It is the control centre and must use the documented board, pin map, supply, and logic level.

Buy / compare this part

Advantages

  • Reprogrammable and reusable
  • Large learning ecosystem
  • Complex behaviour remains changeable

Limitations

  • GPIO voltage and current are limited
  • Some pins affect boot or communication
  • Loads normally need a driver

Handling

  • Disconnect power before rewiring
  • Avoid static discharge
  • Never power motors, relays, or pumps directly from GPIO

Specifications to verify

  • Use the exact model, value, package, and rating listed for ESP8266; similar-looking parts are not always interchangeable.
  • Confirm operating voltage, logic level, pinout, memory, USB interface, and maximum GPIO current.
MNodeMCUMODULE1
What's this?Image, role, pros, cons, handling & specifications
NodeMCU ESP8266 development boardMODULE LEARNING VIEW

NodeMCU

A programmable controller that reads inputs, makes decisions, and drives the project's outputs.

What it does here

It is the control centre and must use the documented board, pin map, supply, and logic level.

Buy / compare this part

Advantages

  • Reprogrammable and reusable
  • Large learning ecosystem
  • Complex behaviour remains changeable

Limitations

  • GPIO voltage and current are limited
  • Some pins affect boot or communication
  • Loads normally need a driver

Handling

  • Disconnect power before rewiring
  • Avoid static discharge
  • Never power motors, relays, or pumps directly from GPIO

Specifications to verify

  • Use the exact model, value, package, and rating listed for NodeMCU; similar-looking parts are not always interchangeable.
  • Confirm operating voltage, logic level, pinout, memory, USB interface, and maximum GPIO current.
PStepper motorPART1
What's this?Image, role, pros, cons, handling & specifications
ESP8266 NodeMCU Web Server: Control Stepper Motor (WebSocket) - source illustration from page 977PART LEARNING VIEW

Stepper motor

An output component turns an electrical control signal into light, sound, motion, switching, or displayed information.

What it does here

It presents the circuit result or acts on the physical world.

Buy / compare this part

Advantages

  • Makes system state visible
  • Can be tested separately
  • Supports clear troubleshooting

Limitations

  • Loads may exceed controller current
  • Polarity or driver direction can matter
  • Inductive loads create voltage spikes

Handling

  • Use the documented driver stage
  • Check polarity and load current
  • Add flyback protection for inductive loads

Specifications to verify

  • Use the exact model, value, package, and rating listed for Stepper motor; similar-looking parts are not always interchangeable.
  • Confirm voltage, current, polarity, interface, driver requirements, and duty cycle.
PPower supplyPOWER1
What's this?Image, role, pros, cons, handling & specifications
ESP8266 NodeMCU Web Server: Control Stepper Motor (WebSocket) - source illustration from page 977POWER LEARNING VIEW

Power supply

A power component supplies, converts, stores, or regulates energy for the project.

What it does here

It must provide the documented voltage, polarity, isolation, and sufficient current safely.

Buy / compare this part

Advantages

  • Stable power improves reliability
  • Current limiting protects first tests
  • Regulation reduces resets and noise

Limitations

  • Wrong polarity can cause immediate damage
  • Underrated parts overheat
  • Mains circuits require qualified supervision

Handling

  • Measure output before connection
  • Use a fuse or current limit
  • Insulate exposed conductors

Specifications to verify

  • Use the exact model, value, package, and rating listed for Power supply; similar-looking parts are not always interchangeable.
  • Confirm input/output voltage, current, polarity, connector, isolation, and thermal rating.
SULN2003SEMICONDUCTOR1
What's this?Image, role, pros, cons, handling & specifications
ESP8266 NodeMCU Web Server: Control Stepper Motor (WebSocket) - source illustration from page 977SEMICONDUCTOR LEARNING VIEW

ULN2003

A semiconductor stage performs switching, amplification, regulation, rectification, or logic.

What it does here

It controls current or signal flow at a defined point in the circuit.

Buy / compare this part

Advantages

  • Fast and efficient
  • Compact
  • Can control larger loads from smaller signals

Limitations

  • Pin order varies
  • Sensitive to overvoltage and reverse polarity
  • May need cooling or bias components

Handling

  • Verify the datasheet pinout
  • Avoid static and soldering heat
  • Check notch, stripe, or flat-face orientation

Specifications to verify

  • Use the exact model, value, package, and rating listed for ULN2003; similar-looking parts are not always interchangeable.
  • Confirm pinout, maximum voltage/current, dissipation, gain or forward voltage, and package.
Ready to continue?
STEP 4 / 6 · Source code

Confirm the hardware-only control path.

This project does not include firmware in the source. The circuit itself provides the required behaviour.

01

How to connect

  1. Match every controller label to the circuit view and source pin map.
  2. Join grounds before signal wires when separate low-voltage supplies are used.
  3. Keep motors, relays, pumps, and other loads on a suitable driver and external supply.

Common mistakes

Reversed VCC/GND, board-label versus GPIO-number confusion, missing common ground, and charge-only USB cables.

Troubleshoot

Disconnect loads, continuity-test one path at a time, then test with a current limit.

02

Software preparation

No IDE, board package, library, or firmware upload is required for this project.

If you add a programmable controller as an extension, document its pin map separately.

03

How to upload code

The original design is implemented entirely in hardware, so proceed after verifying the circuit and supply.

Ready to continue?
STEP 5 / 6 · Build

Assemble, deploy, test, and troubleshoot.

Use the complete source notes in build order, then pass the final checks before calling the project finished.

ASSEMBLY

Build in functional stages

  • Power and regulation
  • Controller or processing stage
  • Inputs and sensors
  • Outputs and loads
  • Enclosure and strain relief
TEST

Power up safely

  • Inspect unpowered continuity first
  • Apply the lowest safe current limit
  • Measure supply rails before signals
  • Add one load at a time
  • Record expected and actual results
TROUBLESHOOT

Work from simple to complex

  • Confirm power, ground, polarity, and orientation
  • Compare each pin with the source
  • Test inputs separately from outputs
  • Replace only one variable at a time
  • Power off before every correction
PROJECT-SPECIFIC BUILD NOTES

Follow the documented instructions.

These notes come from this project's source and remain in their original order.

01

Project overview

Project build note

(WebSocket) In this Project, you will learn how to use the ESP8266 NodeMCU board to make a web server that shows a web page to control a stepper motor. On the website, you can type in the number of steps and choose whether to go clockwise or counterclockwise. It also shows whether the motor is running or has stopped. The WebSocket protocol is what makes it possible for the client and the server to talk to each other. All clients are kept up to date on the current state of the motor. 1) Parts Required 28BYJ-48 Stepper Motor + ULN2003 Motor Driver ESP8266 (read Best ESP8266 Development Boards) (read Best ESP8266 Development Boards) Connecting wires 5V Source of Power 2) Add-on for Arduino IDE and ESP8266 Boards

We'll use Arduino IDE to programme the ESP8266, so you'll need to have the ESP8266 add-on installed. 3) Filesystem Uploader Plugin We'll use a plugin for Arduino IDE called LittleFS Filesystem uploader to send the HTML, CSS, and JavaScript files we need to build this project to the ESP8266 filesystem (LittleFS). 4) Libraries There are different ways to use a microcontroller to control a stepper motor. We'll use the AccelStepper library on the ESP8266 to control the stepper motor. This library makes it easy to move the motor a certain number of steps, set its speed, acceleration, and do a lot more. There is a lot of good documentation about how to use the library's methods. Check it out here. Use the steps below to add the library to your Arduino IDE. Click on Sketch > Include Library > Manage Libraries... Look for the word "accelstepper." Mike McCauley's AccelStepper library should be put in place. Version 1.61.0 is what we're using. You need to install the following libraries to build the web server: ESPAsyncWebServer (.zip folder) (.zip folder) ESPAsyncTCP (.zip folder) (.zip folder) You can't use the Arduino Library Manager to install the ESPAsyncWebServer and ESPAsynTCP libraries. To get the library files, you need to click on the links above. Then, in your Arduino IDE, go to Sketch > Include Library > Add.zip Library and choose the libraries you just downloaded.

Installing Libraries (VS Code + PlatformIO) If you're using PlatformIO to programme the ESP8266, add these lines to the platformio.ini file to include the libraries. You should also change the Serial Monitor speed to 115200 and set the filesystem to LittleFS. 5) Schematic Diagram The stepper motor is connected to the ESP8266 in the way shown in the following diagram. Note: You should use an outside 5V power supply to power the ULN2003 motor driver.

02

Project Overview

Project build note

The web page you'll make for this project is shown in the picture below. On the web page, there is a form where you can choose how many steps you want the motor to move and whether you want it to move clockwise or counterclockwise.

It also shows what the motor is doing, whether it is spinning or not. Additionally, there’s a gear icon that spins as long as the motor is spinning. The gear spins clockwise or counterclockwise direction accordingly to the chosen direction. WebSocket protocol is how the server and the client talk to each other. When you click on the GO! button, it calls a JavaScript function that sends a message using the WebSocket protocol with all the information: steps and directions (3). This is how the message is set up: So, if you put in 2000 steps and the direction clockwise, it will send this

03

message

Project build note

At the same time, it will change the motor state on the web page, and the gear will start spinning in the proper direction (2).

The server then gets the message (4) and turns the motor in the right way (5). When the motor stops turning (6), the ESP will send a message to the client(s), also using the WebSocket protocol, telling them that the motor has stopped (7). When this request comes in, the client(s) update the web page with the motor state (8).

Ready to continue?
PROJECT ACHIEVED

You built ESP8266 NodeMCU Web Server: Control Stepper Motor (WebSocket).

You followed the full workflow from understanding the mission to testing the finished project. That is a real engineering achievement - well done.

ESP8266 NodeMCU with HC-SR04 Ultrasonic Sensor with Arduino IDE project thumbnail featuring ESP8266, NodeMCU, Ultrasonic sensor
NEXT IOT ADVENTURE

ESP8266 NodeMCU with HC-SR04 Ultrasonic Sensor with Arduino IDE

Ready to reuse what you learned in another project from the same track?

Start this project
Browse all 500 projects