ESP32 C3 Super Mini - Stepper Motor A4988 Driver

In December, people stop in front of the toy shop. A small lift goes up and down in the window, and its cabin always stops level with the floor. How does it know where to stop? It counts. The shaft of a stepper motor goes round in little steps of the same size, so "one floor up" is nothing more than a number. On this page, the ESP32 C3 Super Mini keeps count. It fits under the roof of a model house, yet its pins have no strength for a motor. So it only gives orders. A DIYables A4988 module takes them and feeds the coils of a NEMA 17. You begin with one turn up and one turn down. At the end, the cabin visits the floors 0, 1, 2 and 3, and it starts and brakes as gently as a real lift.

In this tutorial, you'll learn:

ESP32 C3 Super Mini and A4988 raise a model lift with a NEMA 17

Hardware Preparation

1×ESP32 C3 Super Mini
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×Stepper Motor Nema 17
1×A4988 Stepper Motor Driver
1×Expansion Board for A4988
1×12V Power Adapter
1×DC Power Jack
1×Breadboard
1×Jumper Wires

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

You may skip the expansion board, as it is optional. The bare module then wants a 100uF capacitor (35V or higher is best) and the wires of the second drawing. For the lift itself, you need a light paper cabin, a thread and a small spool for the motor shaft. There is no hurry with these parts. Both sketches also work with a bare shaft and a paper arrow.

Overview of NEMA 17 Stepper Motor

Two coils of copper wire hide in a NEMA 17, and they do not touch each other. This is what "bipolar" stands for on this page. Both ends of both coils come out of the motor. So you see four wires, and they belong together two by two. The driver has two pins for each of these pairs.

Motors with six wires are welcome too, but only four of the wires are used. A motor with five wires, like the small 28BYJ-48, needs a different driver: ESP32 C3 Super Mini - 28BYJ-48 Stepper Motor ULN2003 Driver.

Count 200 full steps, and the shaft has gone around once, because each of them is worth 1.8 degrees. With a spool on the shaft, steps turn into centimeters.

Our Lift in Numbers:

  • Spool: 19 mm thick, so each turn winds up about 6 cm of thread
  • Distance between two floors: 9 cm, which is 1.5 turns or 300 full steps
  • Floor 3: 27 cm or 900 full steps above floor 0
Coil pairs of a NEMA 17 stepper motor and the colour of each wire
A4988 Pin Letter Same Wire Elsewhere Colour Here
2B A A+, A black
2A C A-, A with a top line green
1A B B+, B red
1B D B-, B with a top line blue

"Here" means our own motor. Each factory picks other colours, so believe the datasheet of yours. You have none? Then look for the pairs like this:

  • Multimeter, ohm range: touch two wire ends. Only a few ohms on the display? Same coil
  • Only your fingers: the motor is not connected to anything. Twist two bare ends together and roll the shaft. Does it brake now? These two come from one coil

Inside a pair, the order is not critical. Swapped, the cabin simply goes down where it should go up. Mixing the pairs is the real fault. Then you hear a growl or see the shaft tremble, and the cabin does not travel.

Overview of A4988 Stepper Motor Driver

Look for a red board that measures just 20 x 15 mm or so. This is the DIYables A4988 module, a board of the StepStick type. The black chip in its center is the A4988 itself. The 2 x 8 male pins are already in place, so nothing is left to solder, and the package has a mini heat sink for the chip. One module runs one bipolar motor. A second lift would need a second module.

How can two thin signal wires move a cabin? DIR says up or down. STEP says "now": the motor goes one step further at every rising edge, the moment when STEP leaves LOW and becomes HIGH. The coils of a stepper must be switched in a fixed pattern. The translator, a unit of the chip, has this pattern built in, so your sketch never thinks about coils. The chip is also a guard. When the coil current has climbed up to the limit, it is switched off for a blink and then on again, over and over. This trick has the name current chopping. It makes 12V harmless even for a motor that is sold as a 3V type.

Key Features:

  • Motor side (VMOT): 8V to 35V DC. A 12V adapter is well inside this range
  • Logic side (VDD): 3V to 5.5V. With a C3, it has to be 3.3V
  • Coil current: about 1A as it comes out of the bag. 2A is the top, and it takes the heat sink plus good cooling
  • Five step sizes: full, 1/2, 1/4, 1/8, 1/16
  • Control: STEP and DIR, that is all
  • Guards in the chip: over-temperature shutdown, under-voltage lockout (the outputs stay off while the supply is too weak) and crossover-current protection
  • What it lacks: a FAULT pin, so it cannot report a problem to the C3

Why the A4988 Fits a Model Lift:

  • The same number of steps is always the same height, so the sketch finds a floor without any sensor
  • The coils keep their holding current at a stop, so the cabin hangs still while the doors are open
  • Two GPIO pins do the job, and the other pins of the C3 stay free for buttons, lights or a display
  • Driver and C3 together need less space than a box of matches

A4988 Pinout

A4988 module pinout with EN, MS1 to MS3, RST, SLP, STEP, DIR and the power and motor pins

Left side - signals:

  • EN: the on/off switch of the outputs. LOW is on, and the module pulls a free EN to LOW for you. HIGH is off: nobody holds the shaft, and the cabin would sink
  • MS1, MS2, MS3: together they choose the step size. Left alone, all three read LOW
  • RST: LOW resets the chip. This pin floats, which means that it has no fixed level of its own. That is why RST and SLP get a common wire
  • SLP: LOW sends the chip to sleep. A pull-up resistor on the module makes it HIGH, and the common wire shares this HIGH with RST
  • STEP: to GPIO7. It wants a full microsecond of HIGH and a full microsecond of LOW, or more
  • DIR: to GPIO6. HIGH or LOW chooses up or down

Right side - power and motor:

  • VMOT: 12V, from the + of the adapter
  • Upper GND: back to the - of the adapter
  • 2B, 2A: one pair of motor wires
  • 1A, 1B: the second pair
  • VDD: to the pin printed 3.3
  • Lower GND: to the pin printed G. The two GND pins are one line on the module

The motor pins have two spellings. On the front of the DIYables board you read B2, A2, A1, B1. On its back you read 2B, 2A, 1A, 1B.

Why VDD Gets 3.3V

The A4988 lives on two supplies. VMOT is for the muscles, VDD is for the brain. A DRV8825 would make the second one out of the first, but an A4988 cannot, so VDD must have a wire. The voltage on this wire also draws a line. Only a signal over 0.7 x VDD is a HIGH for the chip:

  • With 3.3 on VDD: everything above 2.31V is HIGH. The 3.3V pulses of GPIO7 pass with ease
  • With 5V on VDD: HIGH begins at 3.5V. A C3 pin gives 3.3V at best, so a pulse may go unnoticed, and the cabin misses its floor

On the C3, the pins 3.3 and 5V share one row, with only G between them. So look twice where the red wire goes in.

Step Size

In full steps, a light cabin can tremble a bit. The A4988 can cut each step into microsteps, and then the ride becomes smooth and quiet. In return, one floor costs more pulses.

Step Size One Turn One Floor MS1 MS2 MS3 Switches to Turn ON
full 200 pulses 300 pulses LOW LOW LOW none
1/2 400 pulses 600 pulses HIGH LOW LOW 3
1/4 800 pulses 1200 pulses LOW HIGH LOW 2
1/8 1600 pulses 2400 pulses HIGH HIGH LOW 3 and 2
1/16 3200 pulses 4800 pulses HIGH HIGH HIGH all

The last column speaks of the three DIP switches on the expansion board, where ON is HIGH. Count them from the end: the last switch (3) is MS1, the middle one (2) is MS2, the first one (1) is MS3. Without the expansion board, a wire from an MS pin to VDD replaces the ON. The sketch cannot see them, so type the same step size behind MICROSTEPS. If the two disagree, the cabin stops between two floors. For the first ride, leave everything OFF and the number at 1.

Current Limit

Too much current heats the driver, too little makes a weak lift. You choose with the round trimmer. It has no scale, but its voltage, VREF, tells you where you are:

  • Any A4988: current limit = VREF / (8 x Rs). Rs is the value of two tiny resistors on the module
  • The DIYables module: they are printed R100, 0.1 ohm. This makes VREF = 0.8 x current, so 0.48V is 0.6A, 0.6V is 0.75A and 0.8V is 1A
  • Modules with R050: VREF = 0.4 x current

How to Set It:

  • Plug only the USB cable into the C3. VDD has its 3.3V now, and the 12V adapter has no part in this
  • Multimeter in the DC volt range: black probe to G, red probe to the metal face of the trimmer
  • Take a small screwdriver, turn by a hair, read the display. Keep the blade off the neighbor parts
  • Begin at 0.4V (0.5A). Is the cabin too heavy for that? Go up bit by bit, but not over the current on the motor's label

Motor and driver grow warm at a floor, too. Nothing turns there, but the holding current flows.

The Expansion Board

DIYables also makes a 42 x 42 mm carrier for this driver (a DRV8825 fits as well). The module stands in two 8-pin sockets, and around it you find:

  • A G V S header with a row for EN, a row for STEP and a row for DIR. S means signal, V feeds VDD, G means ground. V and G run through all three rows, so wire each of them once, where you like
  • A green screw terminal for the 12V of the adapter, with the screws VIN and GND. 12-24V is printed there, and the capacitor (100uF, 35V) is already soldered
  • A white XH plug for the motor. Its pins from the top are 2B, 2A, 1A, 1B
  • Three DIP switches for the step size
  • Two jobs less: RST meets SLP on the board, and an empty EN row leaves the driver on

The V wire is no luxury here. A DRV8825 would manage without it, an A4988 would stay dead.

※ NOTE THAT:

Which way round? Both ways fit, but only one is right, and a module put in backwards can be destroyed. Compare two corners with the drawing: EN is in the left socket, near the G V S pins, and the small "VIN" arrow is where VMOT goes in.

※ NOTE THAT:

Would a DRV8825 do as well? Yes. With the power off, you could pull out one module and push in the other, because STEP and DIR work alike. Compared with the list above, the numbers are a bit bigger: 8.2V to 45V, around 1.5A per coil (cooled 2.2A), steps as fine as 1/32. And there is no V wire to think of. A paper cabin never asks for that much. Care is needed with the pins, because STEP is GPIO10 and DIR is GPIO9 on the page ESP32 C3 Super Mini - DRV8825 Stepper Motor Driver. Change them in the sketch if you swap the drivers.

Wiring Diagram between A4988 and ESP32 C3 Super Mini

Seat the ESP32 C3 Super Mini on the breadboard with the middle gap under it. You only need two breadboard columns. GPIO7 lies straight across the gap from 3.3, and GPIO6 straight across from G. So the half with the pins 21 to 5 delivers the two signals, and the half with the pins 0 to 5V delivers 3.3V and ground. A wire goes into any free hole of its column half, because these holes are joined with the pin.

Why GPIO6 and GPIO7? At power-up, the ESP32-C3 looks at GPIO2, GPIO8 and GPIO9, its boot strapping pins, to decide how to start. GPIO6 and GPIO7 are not asked, so a driver on them cannot disturb the start.

With the Expansion Board

The expansion board lies beside the breadboard. Take wires with a male end for the breadboard and a female end for the header. In the drawing, V and G are plugged into the DIR row, which you can see in the zoom. Any other row would be just as good.

The wiring diagram between ESP32 C3 Super Mini A4988 stepper motor driver

This image is created using Fritzing. Click to enlarge image

Expansion Board Comes From
S pin of STEP GPIO7 (printed "7")
S pin of DIR GPIO6 (printed "6")
one V pin 3.3V (printed "3.3")
one G pin GND (printed "G")
EN row empty
VIN screw 12V from the + of the jack
GND screw the - of the jack
2B, 2A of the plug wires A, C of the motor (black, green)
1A, 1B of the plug wires B, D of the motor (red, blue)

※ NOTE THAT:

  • 12V comes last. All other wires are in place before the adapter gets its wall socket. The 12V may only reach VIN (VMOT on the bare module). One touch of 12V on a C3 pin can ruin the board.
  • One ground for all. Adapter minus, driver ground and G of the C3 form one common line.
  • Move the motor plug only when 12V is off. A coil does not like to lose its current suddenly. It answers with a short peak of high voltage, which can destroy the A4988.
  • Do not copy the motor colours of the drawing. Its brown, yellow, pink and purple were picked for the picture.

Without the Expansion Board

The bare module stays off the breadboard too, and the C3 keeps its four pins. Two small jobs move over to you: joining RST with SLP (the orange jumper) and adding a capacitor.

The wiring diagram between ESP32 C3 Super Mini A4988 module  without expansion board

This image is created using Fritzing. Click to enlarge image

A4988 Module Comes From
STEP GPIO7
DIR GPIO6
VDD 3.3V (printed "3.3")
lower GND (under VDD) GND (printed "G")
VMOT 12V from the + of the jack
upper GND (under VMOT) the - of the jack
2B, 2A wires A, C of the motor
1A, 1B wires B, D of the motor
RST SLP, one pin below (orange jumper)
EN, MS1, MS2, MS3 empty (outputs on, full step)

※ NOTE THAT:

  • The jumper: forget it, and RST floats. The cabin may then never leave floor 0.
  • The capacitor: it is missing in the drawing, but not in your circuit. Bridge VMOT and the upper GND with 100uF, close to the module, + leg to VMOT. 35V or more is the best rating for it. It softens the voltage jumps on the 12V line.

ESP32 C3 Super Mini Code - Stepper Motor A4988 Driver

Sketch number one checks the wires, the current and the direction. It needs no library, and the cabin may still be missing.

What the code does:

  • Makes GPIO7 (STEP) and GPIO6 (DIR) outputs
  • Builds each step from a HIGH and a LOW of 2000 microseconds each
  • Sets DIR first and lets 5 microseconds pass before the pulses begin
  • Turns the spool up once with 200 pulses, waits 2.2 seconds, turns it down once and waits again
  • Divides the pulse time by MICROSTEPS, so a turn takes 0.8 seconds in every step size
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-stepper-motor-a4988-driver */ /* * ESP32 C3 Super Mini - Stepper Motor A4988 Driver (no library) * * A thread spool on the shaft of a NEMA 17 motor carries the cabin of a model lift. * The spool makes one full turn up, the cabin waits, then one full turn down, and so on. * * The A4988 listens to two signals: * DIR - HIGH or LOW: the way to turn * STEP - every change from LOW to HIGH moves the motor by one step * * Wires (the board stands on a breadboard): * GPIO7 -> STEP * GPIO6 -> DIR * 3.3 -> V of the expansion board, or VDD of the module (never the 5V pin) * G -> G of the expansion board, or the GND pin next to VDD */ #define STEP_PIN 7 // ESP32 C3 Super Mini GPIO7 -> STEP of the A4988 #define DIR_PIN 6 // ESP32 C3 Super Mini GPIO6 -> DIR of the A4988 #define UP HIGH // DIR level that pulls the cabin up #define DOWN LOW // DIR level that lets it down (cabin goes the wrong way? swap HIGH and LOW) #define MICROSTEPS 1 // 1 = full step, or 2, 4, 8, 16: the same step size as the DIP switches #define STEPS_PER_TURN (200 * MICROSTEPS) // a 1.8 degree motor needs 200 full steps for one turn #define HALF_PULSE_US (2000 / MICROSTEPS) // microseconds at HIGH, and again at LOW: 2000 + 2000 = 250 steps per second #define WAIT_MS 2200 // milliseconds the cabin waits after each turn int tripNumber = 0; // counts the trips for the Serial Monitor // One pulse = one step (or one microstep) void oneStep() { digitalWrite(STEP_PIN, HIGH); // LOW to HIGH: the motor steps now delayMicroseconds(HALF_PULSE_US); // keep STEP at HIGH for a while digitalWrite(STEP_PIN, LOW); // back to LOW, the motor does not move here delayMicroseconds(HALF_PULSE_US); // the two waits together set the speed } // Move the cabin: choose the direction, then send the pulses void moveCabin(int direction, int steps) { digitalWrite(DIR_PIN, direction); // DIR first ... delayMicroseconds(5); // ... then a short wait, so DIR is stable before the first pulse for (int i = 0; i < steps; i++) { oneStep(); } } void setup() { Serial.begin(115200); // start the Serial Monitor at 115200 baud pinMode(STEP_PIN, OUTPUT); // the ESP32 C3 sends the pulses pinMode(DIR_PIN, OUTPUT); // the ESP32 C3 picks the direction digitalWrite(STEP_PIN, LOW); // STEP stays at LOW until the first trip Serial.print("Model lift test, one spool turn = "); Serial.print(STEPS_PER_TURN); Serial.println(" steps"); } void loop() { tripNumber++; // a new trip begins // 1) One full turn up Serial.print("Trip "); Serial.print(tripNumber); Serial.println(" UP cabin rises 6 cm"); moveCabin(UP, STEPS_PER_TURN); delay(WAIT_MS); // the motor stands still and holds the cabin // 2) One full turn down Serial.print("Trip "); Serial.print(tripNumber); Serial.println(" DOWN cabin sinks 6 cm"); moveCabin(DOWN, STEPS_PER_TURN); delay(WAIT_MS); // wait again before the next trip }

Detailed Instructions

  • New board? Do the page Getting Started with ESP32 C3 Super Mini before this one. It brings the ESP32 boards into the Arduino IDE.
  • DIP switches: None of the three is ON. No wire on the MS pins means the same for the bare module.
  • Circuit: Copy the drawing wire by wire, without power on the 12V side.
  • VREF: Give the C3 its USB-C cable, then bring the trimmer to your value, as explained above.
  • Arrow: A paper arrow, held on the shaft by tape, will show you every turn.
  • Board: In the Tools menu, take ESP32C3 Dev Module and the COM port of the C3.
  • Sketch: Put the code into a new Arduino IDE window and press Upload.
How to upload ESP32 C3 Super Mini code on Arduino IDE
  • Text: Start the Serial Monitor with 115200 baud.
  • Motion: 12V on! Compare the arrow with the text:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
Model lift test, one spool turn = 200 steps Trip 1 UP cabin rises 6 cm Trip 1 DOWN cabin sinks 6 cm Trip 2 UP cabin rises 6 cm Trip 2 DOWN cabin sinks 6 cm Trip 3 UP cabin rises 6 cm Trip 3 DOWN cabin sinks 6 cm
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2
  • What to look at: The arrow has to rest where it started, trip after trip. During a wait, pinch the shaft and try to twist it: it fights back. This is the force that carries the cabin. The speed, 75 RPM, is calm enough to start without a ramp.
  • Down instead of up? Exchange the words HIGH and LOW in the lines of UP and DOWN. The other way is hardware: pull the adapter, then put the red motor wire where the blue one was, and the blue one where the red one was.
  • Pro Tip: No text at all? Look in the Tools menu: the line USB CDC On Boot has to say Enabled. Change it and send the sketch once more.

ESP32 C3 Super Mini Code - Model Lift with Soft Start and Stop

A real lift does not jump. So this time the AccelStepper library makes the pulses. It puts long gaps between them at first, then shorter ones, and long ones again before the stop.

What the code does:

  • Creates the motor in the AccelStepper::DRIVER mode, which needs two pin numbers: first STEP, then DIR
  • Allows 450 steps per second at most, and lets the speed change by 300 of them within a second
  • Counts down from 8 at the start, so you can reach for the adapter
  • Calls the starting place floor 0, then visits floor 1, 3, 0 and 2, again and again
  • Multiplies the floor number by 300 steps to get the target for moveTo()
  • Repeats run() in a while loop until the cabin has arrived, with no delay() on the way
  • Prints the floor and the ride time, and keeps the doors open for 3 seconds
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-stepper-motor-a4988-driver */ /* * ESP32 C3 Super Mini - Model Lift with the A4988 Driver and AccelStepper * * A NEMA 17 motor winds a thread on a spool and takes a small cabin to the * floors 0, 1, 2 and 3. Each ride starts softly and stops softly. * * Library: AccelStepper by Mike McCauley * * Wires: GPIO7 -> STEP, GPIO6 -> DIR, 3.3 -> V / VDD (never 5V), G -> GND * * The board cannot see the cabin. It calls the place where the cabin stands * at the start "floor 0" and counts the steps from there. */ #include <AccelStepper.h> #define STEP_PIN 7 // ESP32 C3 Super Mini GPIO7 -> STEP of the A4988 #define DIR_PIN 6 // ESP32 C3 Super Mini GPIO6 -> DIR of the A4988 #define MICROSTEPS 1 // 1, 2, 4, 8 or 16: the same step size as the DIP switches #define TOP_SPEED 450 // the fastest the motor may go, in full steps per second #define ACCELERATION 300 // how many steps per second the speed may change in one second #define DOOR_MS 3000 // the doors stay open for 3 seconds at each floor #define START_WAIT 8 // seconds to plug in the 12V adapter before the first ride const long STEPS_PER_TURN = 200L * MICROSTEPS; // steps for one turn of the spool const long STEPS_PER_FLOOR = STEPS_PER_TURN * 3 / 2; // 1.5 turns x 6 cm of thread = 9 cm = one floor const int ROUTE[] = {1, 3, 0, 2}; // the floors to visit, again and again const int STOPS = sizeof(ROUTE) / sizeof(ROUTE[0]); // how many floors are in the list // DRIVER = a chip with one STEP pin and one DIR pin, like the A4988 AccelStepper lift(AccelStepper::DRIVER, STEP_PIN, DIR_PIN); int floorNow = 0; // the floor where the cabin stands int routeIndex = 0; // the place in the ROUTE list // Take the cabin to a floor and come back when it has arrived void rideTo(int floorWanted) { Serial.print("Doors close. Floor "); Serial.print(floorNow); Serial.print(floorWanted > floorNow ? " ^ up to " : " v down to "); Serial.println(floorWanted); unsigned long startTime = millis(); // remember when the ride began lift.moveTo(floorWanted * STEPS_PER_FLOOR); // only sets the target, the motor has not moved yet // run() makes one step whenever one is due, and it works out the next speed. // It returns true until the cabin has arrived. No delay() and no printing in here. // Why a while loop? The ESP32-C3 has one core. Between two passes of loop(), its // Arduino core takes a 5 ms break every 2 seconds, and the motor would feel that. while (lift.run()) { } floorNow = floorWanted; // the cabin is there Serial.print("Ding! Floor "); Serial.print(floorNow); Serial.print(" after "); Serial.print((millis() - startTime) / 1000.0, 1); // the ride time with one digit after the point Serial.println(" s, doors open"); } void setup() { Serial.begin(115200); // start the Serial Monitor at 115200 baud lift.setMaxSpeed(TOP_SPEED * MICROSTEPS); // the library counts microsteps, so multiply lift.setAcceleration(ACCELERATION * MICROSTEPS); // a smaller number gives a softer start and stop lift.setMinPulseWidth(3); // STEP stays HIGH for 3 microseconds (the A4988 needs 1) lift.setCurrentPosition(0); // step 0 = floor 0 // Count down, so there is time to plug in the 12V adapter for (int seconds = START_WAIT; seconds > 0; seconds--) { Serial.print("Cabin on floor 0? 12V plugged in? First ride in "); Serial.println(seconds); delay(1000); } } void loop() { rideTo(ROUTE[routeIndex]); // go to the next floor of the list routeIndex++; // the place of the floor after that if (routeIndex >= STOPS) { routeIndex = 0; // end of the list: begin again } delay(DOOR_MS); // the motor stands still now, so delay() does no harm here }

Detailed Instructions

  • Library: Open the Library Manager of the Arduino IDE, type "AccelStepper" and install the library of Mike McCauley.
  • Search for AccelStepper created by Mike McCauley and click the Install button.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Library Manager
Type:
All
Topic:
All
AccelStepper by Mike McCauley
Provides an object-oriented interface for 2, 3 or 4 pin stepper motors and motor drivers. More info
1.64
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
ESP32C3 Dev Module on COM15
1
  • 12V out: Pull the adapter. Without 12V, the spool can be turned by hand.
  • Cabin on floor 0: Let the cabin down to its lowest place. The C3 has no eyes, so it trusts you on this.
  • Upload: Send the sketch to the board and open the Serial Monitor (115200 baud).
  • 12V in: Plug in the adapter before the countdown is over. Too late? Pull the adapter, bring the cabin back to floor 0 and press RST on the C3: it counts from 8 again.
  • Watch the ride: Each line tells you where the cabin is going and where it has stopped:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
Cabin on floor 0? 12V plugged in? First ride in 3 Cabin on floor 0? 12V plugged in? First ride in 2 Cabin on floor 0? 12V plugged in? First ride in 1 Doors close. Floor 0 ^ up to 1 Ding! Floor 1 after 1.8 s, doors open Doors close. Floor 1 ^ up to 3 Ding! Floor 3 after 2.7 s, doors open Doors close. Floor 3 v down to 0 Ding! Floor 0 after 3.4 s, doors open Doors close. Floor 0 ^ up to 2 Ding! Floor 2 after 2.7 s, doors open Doors close. Floor 2 v down to 1 Ding! Floor 1 after 1.8 s, doors open
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2
  • What to look at: Compare the times. Three floors take less than twice as long as one floor. On a short ride, the motor is still gaining speed when it already has to slow down. Only the three-floor ride reaches 450 steps per second.
  • Softer or faster? Set ACCELERATION to 120 for a sleepy old lift, or TOP_SPEED and ACCELERATION to 700 for a skyscraper. If the cabin no longer stops level, go back a little.
  • Other house? Change STEPS_PER_FLOOR to your floor height and ROUTE to your own list of floors.
  • Pro Tip: Without 12V, nothing holds the cabin and it sinks. Real lifts have a counterweight, and yours can have one too: hang it on a second thread, wound around the spool the other way. It goes down when the cabin goes up, and it takes work off the motor. And it is a toy, so the cabin is for dolls only.

Line-by-line Code Explanation

The above ESP32 C3 Super Mini code contains line-by-line explanation. Please read the comments in the code!

Troubleshooting

  • Dead lift, and the spool is loose: The chip has no 3.3V, no 12V, or it is asleep. Trace the red wire from 3.3 to V (VDD), feel if the adapter plug is in, and look for the orange jumper on the bare module.
  • Dead lift, but the spool is locked: The driver is awake and waits for pulses. Follow the wire from GPIO7 to STEP.
  • Growling or trembling on the spot: Sort the motor wires again, the coil pairs may be mixed. If they are fine, ask less of the motor (a smaller TOP_SPEED, a smaller ACCELERATION) or feed it a little more VREF.
  • Every ride goes the wrong way: Pull the adapter and reverse one coil. For example, what was on 2B goes to 2A, and the other way round.
  • Hot driver, and the cabin drops now and then: That is the over-temperature shutdown. Reduce VREF, and let the heat sink do its part.
  • The cabin stops between two floors: Compare MICROSTEPS with the DIP switches, and remember that MS1 is the last switch.
  • The floors drift away after many rides: Some steps get lost. Try a lighter cabin, a softer ACCELERATION, or a bit more VREF.

Applications and Project Ideas

Floors are only one way to use counted steps. With the WiFi and Bluetooth LE of the C3, the same circuit can become:

  • Shop window lift: show a new product on every floor, and stop longer at the special offer
  • Advent calendar house: one ride per day, to the window with the right date
  • Dumbwaiter for a board game: send cards or snacks to the upper end of the table
  • Bird feeder hoist: pull the feeder up to the branch, and let it down for refilling
  • Cable car: move a gondola between two shelves, with a stop at each book end
  • Talking lift: let a mini MP3 player module announce the floors

Video Tutorial

Challenge Yourself

  • Easy: Add a 4 to ROUTE and find out how many steps floor 4 needs. Is your thread long enough?
  • Easy: Set MICROSTEPS to 8, turn on the DIP switches 3 and 2, and listen to the difference
  • Medium: Show the floor number on a 128x64 OLED while the doors are open
  • Medium: Call the lift with a keypad: the keys 0 to 3 choose the floor
  • Advanced: Hide a limit switch under floor 0. At every start, let the cabin sink slowly until it presses the switch, so nobody has to place it by hand
  • Advanced: Collect several calls during a ride, and visit the floors in a clever order, as a real lift does

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!