Projects »

WiFi-controlled stepper motors with ESP8266

Low cost open hardware driver board for controlling two stepper motors over WiFi, and needs no Arduino/Raspberry Pi/etc

Discontinued
see new design
If you want to control a stepper motor then you could use a Raspberry Pi or Arduino with a suitable motor hat/shield, and there are some excellent ones out there. But the costs quickly add up1, especially if you need 2 stepper motors and WiFi. This simple board is my solution, joining together the well-proven EasyDriver and ESP-12F modules.
1e.g. Raspberry Pi 3 + Adafruit Stepper Motor HAT £58

And here's one I made earlier... a finished board

Features

Buy as a Kit

Supplied in kit form with the surface-mount soldering already done for you, and just easy through-hole soldering left to finish. If you can solder the headers onto a Raspberry Pi Zero or Arduino board, then you’ll have no trouble putting this together. If you'd like a refresher, Sparkfun’s How to Solder tutorial is excellent.

PCB kit with supplied components

The photo above shows exactly what is included in the kit. You’ll need your own power supply, stepper motors, limit switches (optional) and wiring.

This design was discontinued in March 2020. Please click to see the new revB design.

Q: Can I buy just the PCB on its own? Yes. If you’d like to buy 5 or more of just the PCB (i.e., without any components), you can order this design at PCBWay: you’ll get their usual excellent prices (from US$1.30/board), and I’ll get a 10% rebate to put towards my next open hardware project.

Build instructions

Hammer not required :P © Inter IKEA Systems B.V.

Tools required: soldering iron, solder, multimeter, small cross-head (Phillips) screwdriver, wire cutter (optional), sharp knife... no hammer :P

If you can solder the headers onto a Raspberry Pi Zero or Arduino board, then you’ll have no trouble putting this together. An excellent refresher is Sparkfun’s How to Solder tutorial.

  1. Solder the MP1584 voltage converter board onto 4× 2-pin headers, breaking off the headers from the included strips. Don’t join it to the main board yet, but temporarily connect the MP1584 board inputs (marked IN+ / IN- on the back) to a DC power supply (e.g. 12V) and use your multimeter to measure the output voltage (marked OUT+ / OUT-). Use a small cross-head screwdriver to adjust the potentiometer (screw) on the board until you measure any voltage from 3.0→3.6V output, which is safe for the rest of the circuit.

    Warning! skipping this voltage check could destroy the ESP and your motor drivers

    1. Check the voltage output of the MP1584 board

  2. Solder the MP1584 board to the main board, making sure it is the correct way around: the / marked on the MP1584 board should match up with / on the main board.

  3. Using a sharp knife cut the APWR jumper on both EasyDriver boards. The edge of a small flat head screwdriver can also work to scrape away the thin metal trace. You can check that the jumper has been cut successfully by using your multimeter set to continuity test mode.

  4. Use a small cross-head screwdriver to turn the potentiometer (screw) on each EasyDriver board fully clockwise (marked MIN): this sets the motor current to minimum.
  5. Attach both EasyDriver boards to the main board. You’ll need to break off a total of 2× 4-pin headers, 2× 3-pin headers and 6× 2-pin headers from the included strips. Note that 4 holes on each board are not used: PFD, RST, ENABLE & MS2. I find it easiest to place the pin headers and EasyDrivers loosely in the main board, solder the pin headers to the top of the EasyDrivers, and then turn everything over and solder the pin headers to the back of the main board.

  6. Solder the 2× 5-pin screw terminals on to the main board (marked Motor #1, Motor #2). Solder 3× 2-pin screw terminals on to the main board (marked Power, Limit #1 & Limit #2). The terminal holes should point outwards from the board, making it easy to connect up wires.

  7. Solder the radial 1000µF capacitor flush with the main board (marked C1). The longer leg of the capacitor goes in the hole marked +. Cut off the excess wire from underneath the main board.

Warning! Connecting or disconnecting the motors must ONLY be done while the controller board is disconnected from power, otherwise the EasyDriver boards will be damaged. Different motors use different colour wires, so to ensure you connect them correctly check Sparkfun’s Easy Driver Hook-up Guide and this Stepper motor wiring tutorial at 42 Bots. The ‘extra’ 5th screw terminal connects to GND, which could be used to reduce noise if your motor cable has a shield, but can be left unconnected. Once the motors are connected and running, slowly turn the EasyDriver board potentiometers (screws) anti-clockwise (increasing the current) until the motors are not skipping any steps at your chosen speed and load.

1/8 Microsteps are the default for motors used with EasyDriver boards, but if you need more speed you can change this by soldering a jumper wire from MS1 and/or MS2 pins to any GND pin on the boards. This selects 1/8 (no jumpers), 1/4, 1/2, or full motor steps (both MS1+MS2 to GND).

Optional build steps

  1. Recommended step. Remove or disable the LM317 voltage converter chip that is leftmost on each EasyDriver board. They won’t be needed and continually waste ~10mA if left connected, even in deep sleep mode. The easiest way is to use a wire cutter to break leg 3 (bottom right of the 3 legs) off from the chip, or you could desolder the entire chip for future reuse.

  2. Optional step. Using the soldering iron remove the small LED from the top left corner of both EasyDriver boards. Otherwise the LEDs stay lit all the time, even in deep sleep mode. It only saves 0.8mA, but that might be useful if your project runs off batteries.

  3. Optional step. If you want to upload sketches using a USB↔FTDI serial adaptor (instead of OTA/wirelessly) at up to 921600 baud, you can solder a 4-pin programming header on to the board, marked ResetFlash. Make sure that your adaptor uses 3.3V for I/O and not 5V, which would damage the ESP microcontroller. Many USB↔FTDI serial adaptors can’t provide enough current, so power the board separately as usual (e.g. with 12V). You’ll also need to connect the ground pin of your adaptor to any GND on the board, such as one of the 5th screw terminals.

Connect the limit switches (optional) by wiring the NC pin of the switch to a screw terminal marked NC on the main board, and the switch C pin to C. You can leave the switch’s third NO pin unconnected. If your project doesn’t use limit switches, just edit the example sketch so that the LIMIT1 / LIMIT2 inputs aren’t used to stop the motors. The two limit switch connectors can work with multiple switches wired in series, so for example you could use four switches total, two for each motor, setting the ‘home’ and ‘end’ limits of movement. Use the direction you were moving the motor to work out which limit was reached.

Mount in a case (optional) To keep the board as compact as possible there are no mounting holes for screws, but because the board is so light you can use double-sided adhesive pads to attach the PCB to your case. Alternatively, if you are 3D-printing a custom case you could design-in slots/clips that grip the edge of the PCB.

Using the board

The motor controller board ships with a WiFi Motors sketch installed that provides a WiFi access point, and a simple web server that lets you control attached motors from a web browser. e.g. with your smartphone. The access point should automatically appear on your list of local WiFi networks once you power the board. e.g. ESPmotors-XXXXXX

To connect to that new access point enter the WiFi password that is printed on the supplied anti-static bag. The password is case-sensitive, and is unique to each board shipped. Don’t lose it!

Once your smartphone is connected to the WiFi, trying to visit any website should automatically redirect you to the motor controller webpage. However if that doesn’t work, type in http://espmotors.home then you’ll be able to control the board:

Motor controller webpage

Q: Can it connect to my existing WiFi router? Yes, as shipped the example sketch provides its own WiFi access point, but you can edit that to connect to your WiFi network. Uncomment #define ESPMOTORS_STATION in file: ESPmotorsA.h and enter the name and password for your network in the file: data/wifi-station.txt. Compile and upload both the edited sketch and sketch data to the board.

Q: Can I use it with ESPHome? Yes, if you have an ESPHome automation system you can control the board that way, instead of using the example sketch. This ESPHome configuration file should get you started.

Example sketches

You can write sketches for the motor controller board using the open source Arduino IDE or similar. If you don’t already have it installed on your computer, you could do worse than follow the excellent Sparkfun Installing Arduino IDE tutorial.

Q: How do I upload my own sketch to the board? The easiest way is OTA updates by selecting the board in Tools→Port→ESPmotors-XXXXXX. This requires v1.2 firmware, your computer and board on the same WiFi network, and your computer firewall must allow the OTA traffic. Alternatively compile your sketch and then upload the resulting .bin file using the “Flash new firmware over WiFi” option at the bottom of the board’s web page. Finally you can upload sketches using a wired connection direct from your computer.

// 1. Set up sketch to enable one motor or the other

#define STEP   14
#define DIRN   12
#define MOTOR2  5
#define MOTOR1 15

// Initialise motor controller pins
pinMode(STEP, OUTPUT);
pinMode(DIRN, OUTPUT);
pinMode(MOTOR1, OUTPUT);
pinMode(MOTOR2, OUTPUT);
digitalWrite(STEP, LOW);
digitalWrite(DIRN, LOW);
    
// Enable EasyDriver #1 board only, ready for stepping
digitalWrite(MOTOR1, HIGH);
digitalWrite(MOTOR2, LOW);
// Or enable EasyDriver #2 board only, ready for stepping
//digitalWrite(MOTOR1, LOW);
//digitalWrite(MOTOR2, HIGH);

// 2. Example of stepping the enabled motor forwards or backwards

digitalWrite(DIRN, LOW);    // Pull DIRN pin LOW to move "forward"
//digitalWrite(DIRN, HIGH); // or pull DIRN pin HIGH to move "backwards"

for(x=1; x<10000; x++)      // Loop the stepping enough times for motion to be visible
{
  digitalWrite(STEP, HIGH); // Trigger one step, at least 1us pulse width
  digitalWrite(STEP, LOW);  // Pull STEP pin LOW so it can be triggered again
  delayMicroseconds(500);   // Speed of stepping is controlled by the length of this delay (0.0005 sec)
  if (!(x % 1000)) yield(); // Run 'housekeeping' tasks (e.g. WiFi) every 1000 steps (0.5 sec)
}

// 3. Example checking the limit/home switches to stop the motor
// assumes you have connected a Normally-Closed (NC) limit switch, 
// so will read HIGH in normal use, and LOW when it is pressed

#define LIMIT1 13
#define LIMIT2  4

for(x=1; x<10000; x++)      // Loop the stepping enough times for motion to be visible
{
  if (digitalRead(LIMIT1) == LOW) {
//  if (digitalRead(LIMIT2) == LOW) {
    Serial.println("Limit switch pressed to stop motor!");
    break;
  };
  // Do some motor stepping
  // ...
}

Power consumption

Power measurements were made on a 12V input supply with no stepper motors attached. Power consumption of your motors will depend on the current you set on the EasyDriver boards. The MP1584 module was set to output 3.0V.

To save power, the EasyDriver boards are disabled by default (“sleep mode”) and only need to be enabled while you are actually turning the motors. Similarly, you can disable WiFi when it is not being used to send/receive data. If you don't remove/disable the EasyDriver voltage regulators (step #8 above), then you can add 10mA onto each number below.

descriptioncurrent
Baseline usage (WiFi off, MCU on)13.4mA
Baseline + WiFi on1+30.0mA
Baseline + Single EasyDriver enabled2+30.0mA
Deep-sleep mode (MCU off)1.3mA
Deep-sleep + EasyDriver LEDs desoldered0.5mA

1WiFi power consumption can vary quite a bit depending on Tx/Rx, WiFi protocol used, Tx power level, etc.

2The board can optionally enable both EasyDrivers (and hence move both stepper motors) simultaneously, adding 30mA each.

Q: Can I run the board from a battery? Yes, but its specification will depend on the current required by your motors. A 12V or 24V battery should work well.

Download files

Schematic of circuit 2-layer PCB

If you’d like to buy 5 or more of just the PCB on its own (i.e., without any components), you can order this design at PCBWay: you’ll get their usual excellent prices (from US$1.50/board), and I’ll get a 10% rebate to put towards my next open hardware project.

Low-cost PCB manufacture by PCBWay.com

To keep costs for this board as low as possible, I originally planned to etch & drill my prototypes at home, but when I found out how cheap it was to get a handful of boards made professionally it seemed far easier to go down that route. I used a PCB comparison shopping site and chose China-based manufacturer PCBWay.com for the best price: US$15 total for 10 boards, including economy shipping (!) Despite using their cheapest options (2-3 days build + 15-30 days shipping) it only took them 2 days to build the boards + 7 days to deliver them. Very impressive.

2-layer PCB manufactured by PCBWay.com

Get US$5 voucher for your PCB: If you’re going to try PCBWay for your own projects, please consider registering via my PCBWay affiliate link: you’ll get a US$5 voucher for registering, and I’ll also get a voucher to put towards my next open hardware project :)

EasyDriver boards

At the core of this project are the excellent open hardware EasyDriver boards developed over many years by Brian Schmalz. I only source EasyDriver boards that include his “Schmalz Haus” logo and website URL on the silkscreen, complying with his Creative Commons licence. His website is at http://www.schmalzhaus.com/EasyDriver/
Fb Share this on Facebook
Nick Smith, February 2018. Last updated March 2022.