Arduino MKR WiFi 1010 - Stepper Motor A4988 Driver

Seedlings under a glass roof get too hot soon after the sun comes out. A roof vent lets the warm air leave, but somebody has to lift it: a small gap in the cool morning sun, wide open in the heat, shut before a cold night. Put a threaded rod on a NEMA 17 stepper motor and nobody has to, because this motor can stop the vent at a quarter open just as well as at fully open. It wants 12V, though, and far more current than the 3.3V pins of Arduino MKR WiFi 1010 can give. The A4988 driver closes that gap. In this tutorial, we are going to learn:

Arduino MKR WiFi 1010 and A4988 driver open a roof vent with NEMA 17

Hardware Preparation

1×Arduino MKR WiFi 1010
1×Micro USB Cable
1×Stepper Motor Nema 17
1×A4988 Stepper Motor Driver
1×Expansion Board for A4988
1×12V Power Adapter
1×DC Power Jack
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 .

The expansion board is a comfort part and optional. It gives the motor a plug and the 12V a screw terminal. Builders without it need a 100uF capacitor and one short jumper wire in its place, as circuit 2 shows.

Overview of A4988 Stepper Motor Driver

A stepper motor is a demanding guest. Its coils want power one after the other, always in the same order, and they want a limited amount of it. The A4988 is a chip that serves exactly one such motor. Ours rides on a red DIYables board, a StepStick of some 20 x 15 mm, no bigger than a stamp. The 2 x 8 pins are soldered at the factory, and you need no soldering iron. The MKR only has to say two things: "one step, please" on the STEP wire, and "this way round" on the DIR wire.

A4988 Module
Drives 1 stepper motor, bipolar (a 6-wire motor is fine if you use 4 of its wires)
Feeds the Motor (VMOT) anything from 8V to 35V DC, our adapter has 12V
Feeds the Logic (VDD) anything from 3V to 5.5V, the MKR has 3.3V
Current through a Coil some 1A, and 2A at the very most once the heat sink is on and the cooling is good
Microstep Choices half, quarter, eighth, sixteenth
Guards Itself against overheating (it shuts down), low voltage (it locks out), crossover current
FAULT Pin the A4988 was built without one
Extra in the Package 1 stick-on heat sink

Pinout

A4988 driver pinout on a red module, each of the 16 pins named and explained

Sixteen pins look like a lot of work, but let us sort them by who sits at the other end of the wire.

Four pins belong to the MKR:

  • STEP pin: needs to be connected to D4, where the sketch makes its pulses
  • DIR pin: needs to be connected to D3. HIGH and LOW are the two ways the shaft can turn.
  • VDD pin: needs to be connected to the MKR pin named VCC (3.3V). Only the logic part of the chip uses it.
  • Lower GND pin, under VDD: needs to be connected to a GND hole of the MKR

Two pins belong to the 12V adapter:

  • VMOT pin: needs to be connected to + of the adapter. The motor is fed from here.
  • Upper GND pin, under VMOT: needs to be connected to - of the adapter. The module ties its two GND pins together, so this is the ground link to the MKR as well.

Four pins belong to the motor:

  • 2B pin and 2A pin: the two ends of coil 2
  • 1A pin and 1B pin: the two ends of coil 1. (The top of the module prints letter first, so B2, A2, A1, B1. Underneath you find 2B, 2A, 1A, 1B, the names we use.)

Two pins need a partner on the module itself:

  • RST pin: needs to be connected to its neighbor SLP. It is the reset of the chip, active LOW, and the module does nothing to keep it HIGH. Alone, it floats.
  • SLP pin: the chip sleeps while this one is LOW. Here the module has a pull-up, so SLP rests at HIGH and takes RST along.

The last four get nothing:

  • EN pin: HIGH makes the outputs let go of the motor, and two fingers can turn the rod. LOW makes them work. An empty EN is pulled LOW by the module.
  • MS1, MS2, MS3 pins: together they set the microsteps. Empty ones read LOW, and the driver then works in full steps.

What Happens at Each Pulse

Let us follow a single step. The sketch lifts D4 from LOW to HIGH, and the A4988 sees this rising edge on STEP. It checks DIR, moves the shaft one step that way, and waits for the next rising edge. So the number of edges opens the vent wider, and the gap between them sets the pace. Short pulses are no problem: the driver asks for 1 microsecond at HIGH and 1 microsecond at LOW, or more.

Which coil is next? The sketch does not care. The chip has a translator, and this part knows the coil pattern by heart. It also guards the current by chopping: a coil at its limit is cut off and switched on again, again and again. The label of a motor may say 2V, 3V or 4V, and 12V would be too much for it without this trick. With chopping, the 12V adapter is all right.

Inside the NEMA 17

Our NEMA 17 is of the bipolar kind. That means two coils with two wires each, so a pair of wires always belongs to one coil. One full step is 1.8 degrees, so two hundred of them close the circle. Now think of the vent. If its rod makes 8 turns on the way from shut to wide open, the way is 1600 steps long. One percent of the opening is then 16 steps, which is more than fine enough for fresh air.

Microsteps for a Quiet Vent

Single full steps can make a pane of glass rattle. The cure is to cut each step into 2, 4, 8 or 16 microsteps: the rod turns more evenly and with less noise, but every turn costs more pulses. MS1, MS2 and MS3 pick the cut. The expansion board has one DIP switch for each of them, and a switch at ON makes its pin HIGH. The order is a small trap: MS1 belongs to the switch with number 3, MS2 to number 2, and MS3 to number 1.

Put ON MS1, MS2, MS3 One Step Becomes Pulses per Turn Pulses from Shut to Open (8 Turns)
no switch LOW, LOW, LOW 1 full step 200 1600
switch 3 HIGH, LOW, LOW 1/2 step 400 3200
switch 2 LOW, HIGH, LOW 1/4 step 800 6400
switches 2 and 3 HIGH, HIGH, LOW 1/8 step 1600 12800
switches 1, 2 and 3 HIGH, HIGH, HIGH 1/16 step 3200 25600

Both sketches on this page have a line with MICROSTEPS. Put the cut you chose (1, 2, 4, 8 or 16) there, because the MKR cannot feel how the switches stand. If the two disagree, "25%" on the screen is not 25% at the window.

VDD and the Two Supply Pins of the MKR

There is no regulator for the logic inside the A4988, so the voltage for it has to come in on VDD. And VDD does more than feed the chip. It also fixes the level from which STEP and DIR count as HIGH, which is 0.7 x VDD. The MKR owns two pins that could do the job, 5V and VCC (3.3V), but D4 and D3 never give more than 3.3V. Compare:

Red Wire Starts at 0.7 x VDD Do 3.3V Signals Get over It?
VCC (3.3V) 2.31V yes, by almost 1V
5V 3.5V no, they are 0.2V short and steps may get lost

Therefore VDD takes its power from VCC, always. And as the pins of the MKR are not 5V tolerant, 5V has no business in this circuit at all. Count before you plug: from the USB end, the header begins with 5V, then VIN, then VCC, then GND. You want hole number three.

Current Limit for a Motor That Waits

Next to the chip sits a trimmer, a tiny adjusting screw. It decides at how many amperes the chopping begins. No multimeter can show you those amperes directly, but VREF is easy to reach, and it follows the limit: limit = VREF / (8 x Rs). Rs stands for the sense resistors, two parts of 0.1 ohm on the DIYables module with R100 printed on them. This shortens the formula to VREF = 0.8 x limit. A motor limit of 0.6A needs 0.48V, one of 0.9A needs 0.72V. If you own an A4988 from another maker, read the print before you calculate: R050 makes it VREF = 0.4 x limit.

Adjusting takes a minute:

  • How many amperes per coil may your motor get? Its datasheet knows. Start well under that number.
  • Keep the 12V unplugged. VDD is wired, the MKR is on USB, and this already gives a VREF to measure.
  • DC voltage on the multimeter, black to GND, red to the trimmer itself. Its metal top is the test point.
  • Turn, measure, turn, measure, each time only a few degrees. Take a narrow screwdriver that cannot slip onto other parts.

Why not simply choose the maximum? Because a vent waits in one place for hours, and during all that time the holding current flows through the coils. A motor at rest gets warm, and its driver too. Put the heat sink on, and stop raising VREF as soon as the vent opens without trouble.

What About the DRV8825?

It is the stronger relative, with 8.2V to 45V for the motor (A4988: 8V to 35V), about 1.5A per coil or 2.2A when cooled (A4988: about 1A, or 2A), and microsteps down to 1/32 (A4988: 1/16). It also does without the VDD wire. The rest is the same: the signals are STEP and DIR, and it plugs into the same expansion board. When your vent is heavy, read Arduino MKR WiFi 1010 - DRV8825 Stepper Motor Driver.

Wiring Diagram

Two circuits follow, and you need only one of them. Four holes of the MKR are in use either way. D4 and D3 are neighbors on one header, VCC and GND are neighbors on the opposite one. The red wire wears the tag 3V3, which is its voltage, while the board prints VCC at that hole.

Circuit 1 (Expansion Board)

Two 8-pin sockets take the A4988, without any tools. The four wires of the MKR end on a block of nine pins, which the picture shows enlarged. The letters below this block mean ground (G), voltage for VDD (V) and signal (S).

The wiring diagram between Arduino MKR WiFi 1010 A4988 expansion board and NEMA 17

This image is created using Fritzing. Click to enlarge image

※ NOTE THAT:

Two checks before any power. First, the direction of the module: VMOT must be at the corner with the small "VIN" arrow, and the side from EN to DIR must be toward the G V S pins. The wrong way round may be the end of the module. Second, the red wire on V: with a DRV8825 you could forget it, with an A4988 nothing works without it.

Wire in the Picture Leaves the MKR at Arrives at the Expansion Board
yellow D4 STEP row, S
green D3 DIR row, S
red VCC (3.3V) EN row, V
black GND EN row, G

Any other V and any other G would do as well, because each column of three is joined on the board. EN row, S: leave it empty, the driver is switched on that way. Now the other parts of the board:

  • Green screw terminal with the print 12-24V: the DC power jack, + at VIN and - at GND. Keep this voltage far from every MKR pin.
  • White 4-pin plug: the cable of the motor, see the next part.
  • Three DIP switches: all OFF, because our sketches begin with full steps.
  • Not needed here: the RST to SLP wire and a capacitor. The board brings both along (the capacitor is 100uF / 35V).

Colors of the Motor Cable

Coil plan of a NEMA 17, wires A and C are one coil, B and D the other
Driver Pin Our Wire Is Letter in the Plan You May Also Read
2B black A A+
2A green C A-, or an A under a bar
1A red B B+
1B blue D B-, or a B under a bar

Lines one and two are one coil (coil 2 of the driver), lines three and four the other (coil 1). Read downwards, you also get the order of the contacts in the white plug. Our diagrams use brown, yellow, pink and purple for these four. That is only for your eyes, no real cable has to look like it.

Do not trust our colors if your motor is another model. Its datasheet knows better. Without a datasheet, ask a multimeter: if it reads a few ohms between two wires, they share a coil. With bare hands it goes like this. Join two wires, then try to turn the shaft. Does it resist more than before? Same coil.

One habit saves drivers: first the 12V off, then the motor plug. If the plug moves while the power is on, the motor kicks back with a voltage spike that is able to destroy the A4988.

Circuit 2 (Module Only)

This is the circuit for the smallest box: no second board, all wires on the module. Since its pins are male, the jumper wires should be female on that side.

Arduino MKR WiFi 1010 wired to a bare A4988 module, NEMA 17 and 12V jack

This image is created using Fritzing. Click to enlarge image

From To the Module Pin
MKR D4 STEP
MKR D3 DIR
MKR VCC (3.3V) VDD
MKR GND lower GND (under VDD)
12V jack, + side VMOT
12V jack, - side upper GND (under VMOT)
motor wires black and green 2B and 2A
motor wires red and blue 1A and 1B
RST pin (orange jumper) SLP
left open EN, MS1, MS2, MS3

Please do not build it without these two:

  • The orange jumper. Nothing else gives RST a level, and an A4988 in reset is deaf: pulses come in, the motor does nothing.
  • A 100uF capacitor, best a 35V type or higher, which we did not draw. Give it the spot right next to the module, with the + leg at VMOT and the other leg at the GND below.

For both circuits: the grounds of MKR, driver and adapter are one, and the wires above make them so. The 12V belongs to VIN or VMOT and to no pin of the MKR. Power comes last: plug the adapter in when nothing is left to wire.

How To Program For A4988 and NEMA 17

  • For plain pulses you need no library. Give the wires their names, const int STEP_PIN = 4; and const int DIR_PIN = 3;, and make both pins OUTPUT.
  • One turn in numbers: const int MICROSTEPS = 1; and const int STEPS_PER_TURN = 200 * MICROSTEPS;
  • Before a move, choose the way with digitalWrite(DIR_PIN, HIGH); or LOW. A delayMicroseconds(10); behind it gives the level time to settle.
  • A step is four lines: digitalWrite(STEP_PIN, HIGH);, a pause, digitalWrite(STEP_PIN, LOW);, a pause. Repeat them 200 times for a full-step turn.
  • With 2000 microseconds in each pause, a step takes 4 milliseconds and a turn 0.8 seconds. From a standstill, a NEMA 17 follows this pace. A quick vent needs a soft start instead.
  • The soft start comes from the AccelStepper library: #include <AccelStepper.h> and AccelStepper ventMotor(AccelStepper::DRIVER, STEP_PIN, DIR_PIN);. DRIVER is its name for boards with STEP and DIR inputs.
  • In setup(), three settings are enough: ventMotor.setMaxSpeed(TOP_SPEED);, ventMotor.setAcceleration(RAMP_RATE); and ventMotor.setMinPulseWidth(3);
  • ventMotor.moveTo(goal); names the place to go to, counted in steps from the starting place. It does not move anything yet.
  • The moving is the job of ventMotor.run();. It never makes more than one step, so loop() must call it all the time. ventMotor.distanceToGo() shrinks to 0, and at 0 the vent is there.
  • After Serial.begin(9600); comes while (!Serial && millis() < 3000);. The SAMD21 chip of the MKR handles USB itself, and the wait keeps the first line from being lost.

Arduino Code - Test Turn for the Vent Rod

We begin without a library and without a vent. The motor makes one turn the "open" way, waits 1.8 seconds, makes one turn the "close" way, waits again, and goes on like this. If that works, all the wires are right. (With microsteps, this sketch shortens its pulses by itself, and a turn still takes 0.8 seconds.)

/* * This Arduino MKR WiFi 1010 code was developed by newbiely.com * * This Arduino MKR WiFi 1010 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-mkr/arduino-mkr-wifi-1010-stepper-motor-a4988-driver */ // Arduino MKR WiFi 1010 + A4988 + NEMA 17: test of the vent rod, one turn to open and one turn to close // Plain digitalWrite(), no library const int STEP_PIN = 4; // MKR pin D4: one pulse here is one step const int DIR_PIN = 3; // MKR pin D3: HIGH = open, LOW = close const int MICROSTEPS = 1; // put in what MS1, MS2, MS3 say: 1, 2, 4, 8 or 16 const int STEPS_PER_TURN = 200 * MICROSTEPS; // the NEMA 17 has 200 full steps, each of them 1.8 degrees const int HALF_PULSE_US = 2000 / MICROSTEPS; // length of the HIGH half and of the LOW half in microseconds const int REST_MS = 1800; // the rod stands still this long (ms) after each turn // makes "count" pulses in the direction that DIR has right now void sendSteps(int count) { for (int i = 0; i < count; i++) { digitalWrite(STEP_PIN, HIGH); // the A4988 moves the shaft at this edge delayMicroseconds(HALF_PULSE_US); digitalWrite(STEP_PIN, LOW); // back to LOW, ready for another edge delayMicroseconds(HALF_PULSE_US); } } void setup() { Serial.begin(9600); while (!Serial && millis() < 3000); // native USB: up to 3 seconds for the Serial Monitor to open pinMode(STEP_PIN, OUTPUT); pinMode(DIR_PIN, OUTPUT); digitalWrite(STEP_PIN, LOW); // a known start level, so that no step is counted by accident Serial.print("Vent rod test, steps in one turn: "); Serial.println(STEPS_PER_TURN); } void loop() { Serial.print("DIR HIGH, rod opens the vent ... "); digitalWrite(DIR_PIN, HIGH); delayMicroseconds(10); // the direction has to be steady when the pulses come sendSteps(STEPS_PER_TURN); Serial.println("1 turn done"); delay(REST_MS); Serial.print("DIR LOW, rod closes the vent ... "); digitalWrite(DIR_PIN, LOW); delayMicroseconds(10); sendSteps(STEPS_PER_TURN); Serial.println("1 turn back"); delay(REST_MS); }

Detailed Instructions

  • Build circuit 1 or circuit 2, but leave the 12V unplugged until later.
  • Draw a dot on the edge of the shaft with a marker pen. It shows you where a turn ends.
  • Connect Arduino MKR WiFi 1010 to PC via Micro USB cable.
  • Navigate to the Arduino IDE, choose Arduino MKR WiFi 1010 as the board and pick its port. Never used this board? Then Getting Started with Arduino MKR WiFi 1010 comes first.
  • Adjust VREF with the multimeter, as shown above.
  • Copy the above code into the IDE and press Upload.
How to upload Arduino MKR WiFi 1010 code on Arduino IDE
  • Time for the 12V: plug the adapter in, and the dot goes on its first trip.
  • The Serial Monitor (9600 baud) tells you which way the motor goes.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino MKR WiFi 1010
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino MKR WiFi 1010' on 'COM15')
New Line
9600 baud
Vent rod test, steps in one turn: 200 DIR HIGH, rod opens the vent ... 1 turn done DIR LOW, rod closes the vent ... 1 turn back DIR HIGH, rod opens the vent ... 1 turn done DIR LOW, rod closes the vent ... 1 turn back DIR HIGH, rod opens the vent ... 1 turn done
Ln 11, Col 1
Arduino MKR WiFi 1010 on COM15
2

Look at the dot after each "1 turn back". It has to sit exactly where it sat when you began. A dot that wanders off a bit each time means lost steps. Give the motor slightly more current then, or longer pauses.

Did you hear the knock at the start of each turn? The first pulse already comes at full pace, and the shaft is thrown into motion. Glass and hinges will not like that, so the next sketch treats them better.

Arduino Code - Roof Vent with Soft Start and Four Positions

A real vent follows the weather, and here the sketch invents the weather. Cool but sunny means 25% open, mild means 60%, very hot means 100%, and a cold night means 0%. The weather changes four seconds after each stop. Shut is step 0, and wide open is 8 turns away at step 1600. AccelStepper stretches the pulses at both ends of a move, which lets the vent glide off and settle gently.

/* * This Arduino MKR WiFi 1010 code was developed by newbiely.com * * This Arduino MKR WiFi 1010 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-mkr/arduino-mkr-wifi-1010-stepper-motor-a4988-driver */ // Arduino MKR WiFi 1010 + A4988 + NEMA 17: a greenhouse roof vent that opens a little or a lot // Needs the AccelStepper library by Mike McCauley, which makes every move begin and end gently #include <AccelStepper.h> const int STEP_PIN = 4; // MKR pin D4: step pulses const int DIR_PIN = 3; // MKR pin D3: direction const int MICROSTEPS = 1; // put in what MS1, MS2, MS3 say: 1, 2, 4, 8 or 16 const long STEPS_PER_TURN = 200L * MICROSTEPS; const int VENT_TURNS = 8; // the rod turns 8 times between a shut and a wide open vent const long VENT_STEPS = VENT_TURNS * STEPS_PER_TURN; // 8 turns are 1600 full steps const float TOP_SPEED = 700.0; // speed limit in steps per second const float RAMP_RATE = 350.0; // how much faster the motor may get within a second const unsigned long WEATHER_TIME = 4000; // the weather "changes" 4000 ms after the vent has stopped // four kinds of weather, and for each of them the opening in percent const char* WEATHER[] = {"cool but sunny", "mild", "very hot", "a cold night"}; const int OPENING[] = {25, 60, 100, 0}; const int WEATHER_COUNT = 4; AccelStepper ventMotor(AccelStepper::DRIVER, STEP_PIN, DIR_PIN); int weatherNow = -1; // -1: no weather yet, the vent is still shut bool ventMoving = false; unsigned long clockMs = 0; // when the last thing happened (vent started or vent stopped) // takes the next weather of the list and gives the motor a new goal void nextWeather() { weatherNow = (weatherNow + 1) % WEATHER_COUNT; long goal = VENT_STEPS * OPENING[weatherNow] / 100; // printing takes time, so it is done here, while no step is due Serial.print("It is "); Serial.print(WEATHER[weatherNow]); Serial.print(", vent goes to "); Serial.print(OPENING[weatherNow]); Serial.print("% = step "); Serial.println(goal); ventMotor.moveTo(goal); // nothing turns yet, that is up to run() ventMoving = true; clockMs = millis(); } void setup() { Serial.begin(9600); while (!Serial && millis() < 3000); // native USB: up to 3 seconds for the Serial Monitor to open ventMotor.setMaxSpeed(TOP_SPEED); ventMotor.setAcceleration(RAMP_RATE); ventMotor.setMinPulseWidth(3); // pulses of 3 microseconds, 1 would be the minimum // AccelStepper begins to count at 0, therefore shut the vent before you switch on Serial.print("Roof vent: shut is step 0, wide open is step "); Serial.println(VENT_STEPS); clockMs = millis(); } void loop() { ventMotor.run(); // looks at the time and makes a step if one is due if (ventMotor.distanceToGo() != 0) { return; // still on the way, so do nothing that costs time } if (ventMoving) { Serial.print(" there, motor ran for "); Serial.print((millis() - clockMs) / 1000.0, 1); Serial.println(" s"); ventMoving = false; clockMs = millis(); } if (millis() - clockMs >= WEATHER_TIME) { nextWeather(); } }

Detailed Instructions

  • No wire changes. If a real vent already hangs on the rod, pull out the 12V adapter and shut the vent by hand.
  • Get the library: click on Libraries in the Arduino IDE, type "AccelStepper", and press Install at the entry by 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
Arduino MKR WiFi 1010
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
Arduino MKR WiFi 1010 on COM15
1
  • Copy the above code over the test sketch and press Upload.
  • Plug the adapter back in and press the reset button of the MKR one time (two fast presses would start the upload mode). The sketch starts over and calls the present place of the vent 0%.
  • The Serial Monitor, at 9600 baud again, gives the weather report:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino MKR WiFi 1010
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino MKR WiFi 1010' on 'COM15')
New Line
9600 baud
Roof vent: shut is step 0, wide open is step 1600 It is cool but sunny, vent goes to 25% = step 400 there, motor ran for 2.0 s It is mild, vent goes to 60% = step 960 there, motor ran for 2.4 s It is very hot, vent goes to 100% = step 1600 there, motor ran for 2.6 s It is a cold night, vent goes to 0% = step 0 there, motor ran for 4.2 s It is cool but sunny, vent goes to 25% = step 400 there, motor ran for 2.0 s
Ln 11, Col 1
Arduino MKR WiFi 1010 on COM15
2

Compare the move to 25% with the move back to 0%. For the cold night the rod goes four times as far (1600 steps against 400), yet it needs only about twice as long. The ramp is the reason. The speed grows by 350 each second, so 700 steps per second are reached after two seconds. In a short move the motor has to brake long before that. Only the way from 100% back to 0% is long enough for full speed.

Make it fit your own vent:

  • VENT_TURNS is the number of rod turns from shut to wide open. Turn the rod by hand and count.
  • WEATHER and OPENING belong together, one opening for each kind of weather. Add or remove entries in both, and correct WEATHER_COUNT.
  • RAMP_RATE is the softness. Half the number gives a gentler, longer start.
  • With microsteps, the vent gets slower, since TOP_SPEED counts pulses. Raise TOP_SPEED and RAMP_RATE little by little until you like the pace.
  • The MKR has no eyes on the vent, it counts. That is why the vent must be shut when the sketch starts. In a finished build, a limit switch can find the shut position.

Ideas for your greenhouse:

  • Replace the invented weather by a measured one. Humid or hot air, read as in Arduino MKR WiFi 1010 - DHT22, could pick the percent value.
  • The first drops on a rain sensor could send the vent to 0%.
  • An LCD next to the pots could show the opening in big numbers.
  • A fifth wire can cool the driver: connect S in the EN row (EN on the bare module) to a spare MKR pin and write HIGH between two moves. The holding current is then gone, but so is the hold, so this is only for a vent that stays where it is.

Troubleshooting

  • The vent stays where it is, and the shaft turns freely: either no 3.3V arrives at VDD or the chip sits in reset. Follow the red wire from VCC to V (or VDD). In circuit 2, inspect the orange jumper. Last, feel whether the 12V plug is really in.
  • It only hums and shivers: a wire of one coil has changed places with a wire of the other. Compare them with the color table. All correct? Then the motor lacks current, or the sketch asks for too much speed or too quick a ramp.
  • Open and shut are exchanged: with the 12V off, swap black and green at 2B and 2A. One coil is enough.
  • The heat sink burns your finger, and the vent pauses in the middle of a move: the over-temperature shutdown did its job. Less VREF and more air will help, and the heat sink should be on.
  • The vent opens twice, four times or only a fraction as far as planned: look at the DIP switches, then at MICROSTEPS. They have to tell the same story.
  • Since you added WiFi code, the motor stutters: a WiFi call holds up loop(), and run() comes too late. Send and receive only while distanceToGo() is 0.

Video Tutorial

※ 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!