{"id":11321,"date":"2023-10-12T14:10:42","date_gmt":"2023-10-12T11:10:42","guid":{"rendered":"https:\/\/learn.groundstudio.eu\/?p=11321"},"modified":"2024-08-06T14:18:10","modified_gmt":"2024-08-06T11:18:10","slug":"l298n-motor-driver-stepper-motor-control","status":"publish","type":"post","link":"https:\/\/learn.groundstudio.eu\/en\/l298n-motor-driver-stepper-motor-control\/","title":{"rendered":"L298N motor driver &#8211; Stepper motor control"},"content":{"rendered":"<div data-post-id=\"11972\" class=\"insert-page insert-page-11972 \"><h1 class='insert-page-title'>Introduction<\/h1><\/div>\n\n\n<p>Stepper motors find extensive applications across various fields, including textile machinery, printing presses, medical imaging devices, CNC machines, and many other types of equipment. However, effectively controlling stepper motors requires a comprehensive understanding because each machine often requires custom design and management. To address this challenge, a range of motor driver modules have been developed, enhancing the precision and control of DC motors through microcontrollers like the Arduino.<\/p>\n\n\n\n<p>In this tutorial, we will demonstrate the interfacing of a stepper motor with L298N motor driver, using a development board.<\/p>\n\n\n\n<p>The L298N Motor Driver module comprises an L298N Motor Driver IC and a 78M05 Voltage Regulator. The 78M05 Voltage Regulator activates only when a jumper is inserted. When the power source voltage is 12V or lower, the voltage regulator supplies power to the internal circuitry, and the 5V pin can be used as an output to power the microcontroller. In cases where the power supply voltage exceeds 12V, the jumper should be removed, and a separate 5V source must be connected to the 5V connector to power the internal circuitry.<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.34%\">\n<p><\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.34%\">\n<figure class=\"wp-block-image aligncenter size-full is-style-zoooom\"><img loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"500\" src=\"https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/Motor_Driver_Module_L298N__For_Arduino_Stepper_Motor_Dual_H_Bridge_Motor_Driver-1.jpg\" alt=\"\" class=\"wp-image-11323\" srcset=\"https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/Motor_Driver_Module_L298N__For_Arduino_Stepper_Motor_Dual_H_Bridge_Motor_Driver-1.jpg 500w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/Motor_Driver_Module_L298N__For_Arduino_Stepper_Motor_Dual_H_Bridge_Motor_Driver-1-300x300.jpg 300w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/Motor_Driver_Module_L298N__For_Arduino_Stepper_Motor_Dual_H_Bridge_Motor_Driver-1-150x150.jpg 150w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/Motor_Driver_Module_L298N__For_Arduino_Stepper_Motor_Dual_H_Bridge_Motor_Driver-1-12x12.jpg 12w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/ardushop.ro\/ro\/electronica\/84-l298n-punte-h-dubla-dual-h-bridge-motor-dcsteppe.html\">Buy here \ud83d\uded2<\/a><\/div>\n<\/div>\n\n\n\n<p>L298N stepper motor driver<\/p>\n<\/div>\n<\/div>\n\n\n<div data-post-id=\"12338\" class=\"insert-page insert-page-12338 \"><h1 class='insert-page-title'>Required hardware<\/h1><\/div>\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<figure class=\"wp-block-table\"><table><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong>Name <\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>Details<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>Image<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>Quantity<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Jade Uno+ <br>GroundStudio<\/td><td class=\"has-text-align-center\" data-align=\"center\"><\/td><td class=\"has-text-align-center\" data-align=\"center\"><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"150\" class=\"wp-image-11334\" style=\"width: 150px;\" src=\"https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/groundstudio-jade-uno-plus.jpg\" alt=\"\" srcset=\"https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/groundstudio-jade-uno-plus.jpg 900w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/groundstudio-jade-uno-plus-300x300.jpg 300w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/groundstudio-jade-uno-plus-150x150.jpg 150w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/groundstudio-jade-uno-plus-768x768.jpg 768w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/groundstudio-jade-uno-plus-12x12.jpg 12w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/td><td class=\"has-text-align-center\" data-align=\"center\">1<\/td><td class=\"has-text-align-center\" data-align=\"center\"><button onclick=\"window.open('https:\/\/ardushop.ro\/home\/2653-groundstudio-jade-uno-plus.html','_blank')\">\ud83d\uded2 Buy here<\/button> <\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">USB cable<\/td><td class=\"has-text-align-center\" data-align=\"center\">Type C<\/td><td class=\"has-text-align-center\" data-align=\"center\"><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"150\" class=\"wp-image-11333\" style=\"width: 150px;\" src=\"https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/cablu-usb-tip-c-1m.jpg\" alt=\"\" srcset=\"https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/cablu-usb-tip-c-1m.jpg 900w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/cablu-usb-tip-c-1m-300x300.jpg 300w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/cablu-usb-tip-c-1m-150x150.jpg 150w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/cablu-usb-tip-c-1m-768x768.jpg 768w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/cablu-usb-tip-c-1m-12x12.jpg 12w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/td><td class=\"has-text-align-center\" data-align=\"center\">1<\/td><td class=\"has-text-align-center\" data-align=\"center\"><button onclick=\"window.open('https:\/\/ardushop.ro\/home\/1830-cablu-usb-tip-c-1m.html','_blank')\">\ud83d\uded2 Buy here<\/button><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Jumper wires<\/td><td class=\"has-text-align-center\" data-align=\"center\">male-female<\/td><td class=\"has-text-align-center\" data-align=\"center\"><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"150\" class=\"wp-image-11332\" style=\"width: 150px;\" src=\"https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/10-x-fire-dupont-mama-tata-20cm.jpg\" alt=\"\" srcset=\"https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/10-x-fire-dupont-mama-tata-20cm.jpg 900w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/10-x-fire-dupont-mama-tata-20cm-300x300.jpg 300w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/10-x-fire-dupont-mama-tata-20cm-150x150.jpg 150w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/10-x-fire-dupont-mama-tata-20cm-768x768.jpg 768w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/10-x-fire-dupont-mama-tata-20cm-12x12.jpg 12w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/td><td class=\"has-text-align-center\" data-align=\"center\">4<\/td><td class=\"has-text-align-center\" data-align=\"center\"><button onclick=\"window.open('https:\/\/ardushop.ro\/home\/291-10-x-fire-dupont-mama-tata-20cm.html',_blank')\">\ud83d\uded2 Buy here<\/button><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Motor driver<\/td><td class=\"has-text-align-center\" data-align=\"center\">L298N<\/td><td class=\"has-text-align-center\" data-align=\"center\"><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"150\" class=\"wp-image-11323\" style=\"width: 150px;\" src=\"https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/Motor_Driver_Module_L298N__For_Arduino_Stepper_Motor_Dual_H_Bridge_Motor_Driver-1.jpg\" alt=\"\" srcset=\"https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/Motor_Driver_Module_L298N__For_Arduino_Stepper_Motor_Dual_H_Bridge_Motor_Driver-1.jpg 500w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/Motor_Driver_Module_L298N__For_Arduino_Stepper_Motor_Dual_H_Bridge_Motor_Driver-1-300x300.jpg 300w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/Motor_Driver_Module_L298N__For_Arduino_Stepper_Motor_Dual_H_Bridge_Motor_Driver-1-150x150.jpg 150w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/Motor_Driver_Module_L298N__For_Arduino_Stepper_Motor_Dual_H_Bridge_Motor_Driver-1-12x12.jpg 12w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/td><td class=\"has-text-align-center\" data-align=\"center\">1<\/td><td class=\"has-text-align-center\" data-align=\"center\"><button onclick=\"window.open('https:\/\/ardushop.ro\/home\/291-10-x-fire-dupont-mama-tata-20cm.html',_blank')\">\ud83d\uded2 Buy here<\/button><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Stepper motor<\/td><td class=\"has-text-align-center\" data-align=\"center\">Nema17<\/td><td class=\"has-text-align-center\" data-align=\"center\"><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"150\" class=\"wp-image-11336\" style=\"width: 150px;\" src=\"https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/motor-pas-cu-pas-nema17-18-grade-18a.jpg\" alt=\"\" srcset=\"https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/motor-pas-cu-pas-nema17-18-grade-18a.jpg 900w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/motor-pas-cu-pas-nema17-18-grade-18a-300x300.jpg 300w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/motor-pas-cu-pas-nema17-18-grade-18a-150x150.jpg 150w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/motor-pas-cu-pas-nema17-18-grade-18a-768x768.jpg 768w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/motor-pas-cu-pas-nema17-18-grade-18a-12x12.jpg 12w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/td><td class=\"has-text-align-center\" data-align=\"center\">1<\/td><td class=\"has-text-align-center\" data-align=\"center\"><button onclick=\"window.open('https:\/\/ardushop.ro\/printare-3d\/103-motor-pas-cu-pas-nema17-18-grade-18a.html',_blank')\">\ud83d\uded2 Buy here<\/button><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Power supply<\/td><td class=\"has-text-align-center\" data-align=\"center\">12V<\/td><td class=\"has-text-align-center\" data-align=\"center\"><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"150\" class=\"wp-image-11338\" style=\"width: 150px;\" src=\"https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/sursa-alimentare-12v-3a.jpg\" alt=\"\" srcset=\"https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/sursa-alimentare-12v-3a.jpg 900w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/sursa-alimentare-12v-3a-300x300.jpg 300w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/sursa-alimentare-12v-3a-150x150.jpg 150w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/sursa-alimentare-12v-3a-768x768.jpg 768w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/sursa-alimentare-12v-3a-12x12.jpg 12w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/td><td class=\"has-text-align-center\" data-align=\"center\">1<\/td><td class=\"has-text-align-center\" data-align=\"center\"><button onclick=\"window.open('https:\/\/ardushop.ro\/home\/517-sursa-alimentare-12v-3a.html',_blank')\">\ud83d\uded2 Buy here<\/button><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Adaptor<\/td><td class=\"has-text-align-center\" data-align=\"center\">Female<\/td><td class=\"has-text-align-center\" data-align=\"center\"><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"150\" class=\"wp-image-11340\" style=\"width: 150px;\" src=\"https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/pereche-mufe-alimentare.jpg\" alt=\"\" srcset=\"https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/pereche-mufe-alimentare.jpg 900w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/pereche-mufe-alimentare-300x300.jpg 300w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/pereche-mufe-alimentare-150x150.jpg 150w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/pereche-mufe-alimentare-768x768.jpg 768w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/pereche-mufe-alimentare-12x12.jpg 12w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/td><td class=\"has-text-align-center\" data-align=\"center\">1<\/td><td class=\"has-text-align-center\" data-align=\"center\"><button onclick=\"window.open('https:\/\/ardushop.ro\/home\/365-pereche-mufe-alimentare.html',_blank')\">\ud83d\uded2 Buy here<\/button><\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\"><\/div>\n\n\n<div data-post-id=\"12373\" class=\"insert-page insert-page-12373 \"><h1 class='insert-page-title'>Circuit diagram<\/h1><\/div>\n\n\n<figure class=\"wp-block-image aligncenter size-large is-style-zoooom\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"337\" src=\"https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/frz_l298nnema_jadeuno3-2-1024x337.png\" alt=\"cover\" class=\"wp-image-11451\" srcset=\"https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/frz_l298nnema_jadeuno3-2-1024x337.png 1024w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/frz_l298nnema_jadeuno3-2-300x99.png 300w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/frz_l298nnema_jadeuno3-2-768x253.png 768w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/frz_l298nnema_jadeuno3-2-1536x506.png 1536w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/frz_l298nnema_jadeuno3-2-18x6.png 18w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2023\/10\/frz_l298nnema_jadeuno3-2.png 1760w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n<div data-post-id=\"12379\" class=\"insert-page insert-page-12379 \"><h1 class='insert-page-title'>Connection table<\/h1><\/div>\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>L298N motor driver<\/strong><\/td><td><strong>Connection<\/strong><\/td><\/tr><tr><td>GND<\/td><td>Power connector and board&#8217;s GND<\/td><\/tr><tr><td>12 V jumper<\/td><td>Remove if motor voltage &gt; 12 V!<\/td><\/tr><tr><td>5V+ (optional)<\/td><td>5V board if 12 V jumper is removed<\/td><\/tr><tr><td>IN1<\/td><td>Board&#8217;s pin 8<\/td><\/tr><tr><td>IN2<\/td><td>Board&#8217;s pin 9<\/td><\/tr><tr><td>IN3<\/td><td>Board&#8217;s pin 10<\/td><\/tr><tr><td>IN4<\/td><td>Board&#8217;s pin 11<\/td><\/tr><tr><td>ENA and ENB jumper<\/td><td>Leave installed<\/td><\/tr><tr><td>OUT1 + OUT2<\/td><td>Stepper motor coil A<\/td><\/tr><tr><td>OUT3 + OUT4<\/td><td>Stepper motor coil B<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full is-style-zoooom\"><img loading=\"lazy\" decoding=\"async\" width=\"759\" height=\"669\" src=\"https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2024\/01\/L298N-pinout-1.png\" alt=\"\" class=\"wp-image-12032\" srcset=\"https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2024\/01\/L298N-pinout-1.png 759w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2024\/01\/L298N-pinout-1-300x264.png 300w, https:\/\/learn.groundstudio.eu\/wp-content\/uploads\/2024\/01\/L298N-pinout-1-14x12.png 14w\" sizes=\"auto, (max-width: 759px) 100vw, 759px\" \/><\/figure>\n<\/div>\n<\/div>\n\n\n\n<p><strong>Important note: remove the +12V jumper if you are using a power supply higher than 12 V.<\/strong><\/p>\n\n\n\n<p>When the +12V jumper is attached, the on-board voltage regulator is enabled and it will create the 5 V logic voltage. When you remove the jumper, you need to provide the board with 5 V from the Arduino.<\/p>\n\n\n\n<p>You also need to keep both the ENA and ENB jumpers in place so the the motor is always enabled.<\/p>\n\n\n<div data-post-id=\"12385\" class=\"insert-page insert-page-12385 \"><h1 class='insert-page-title'>Arduino code<\/h1><\/div>\n\n\n<p>You can upload the following example code to your Arduino using the&nbsp;<a href=\"https:\/\/www.arduino.cc\/en\/main\/software\" target=\"_blank\" rel=\"noreferrer noopener\">Arduino IDE<\/a>.<\/p>\n\n\n\n<p>This example uses the&nbsp;<strong>Stepper.h<\/strong>&nbsp;library, which should come pre-installed with the Arduino IDE. You can find it by going to&nbsp;<strong>Sketch &gt; Include Library &gt; Stepper<\/strong>.<\/p>\n\n\n\n<p>This sketch turns the stepper motor 1 revolution in one direction, pauses, and then turns 1 revolution in the other direction.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Stepper.h library example code for L298N driver with stepper motor and Arduino<\/h3>\n\n\n\n<pre class=\"wp-block-code has-white-color has-text-color has-background\" style=\"border-width:6px;background-color:#243447\"><code>\/* Example sketch to control a stepper motor with L298N motor driver, a development board and Stepper.h library.\n\n\/\/ Include the Stepper library:\n#include &lt;Stepper.h&gt;\n\n\/\/ Define number of steps per revolution:\nconst int stepsPerRevolution = 200;\n\n\/\/ Initialize the stepper library on pins 8 through 11:\nStepper myStepper = Stepper(stepsPerRevolution, 8, 9, 10, 11);\n\nvoid setup() {\n  \/\/ Set the motor speed (RPMs):\n  myStepper.setSpeed(100);\n}\n\nvoid loop() {\n  \/\/ Step one revolution in one direction:\n  myStepper.step(200);\n\n  delay(2000);\n\n  \/\/ Step one revolution in the other direction:\n  myStepper.step(-200);\n\n  delay(2000);\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Code explanation<\/h2>\n\n\n\n<p>The sketch starts by including the Stepper.h Arduino library.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Include the Stepper library:\n#include &lt;Stepper.h&gt;<\/code><\/pre>\n\n\n\n<p>Next we need to define how many steps it takes for the motor to rotate 1 revolution. n this example we will be using the motor in&nbsp;<strong>full-step mode<\/strong>. This means it takes 200 steps to rotate 360 degrees. You can change this value if you want if you are using a different type of stepper motor or setup.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Define number of steps per revolution:\nconst int stepsPerRevolution = 200;<\/code><\/pre>\n\n\n\n<p>After this, you need to create a new instance of the Stepper class, which represents a particular stepper motor connected to the Arduino. For this we use the function&nbsp;<code>Stepper(steps, pin1, pin2, pin3, pin4)<\/code>&nbsp;where steps is the number of steps per revolution and pin1 through pin4 are the pins used to drive the stepper motor. In our case these are pins 8, 9, 10 and 11.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Initialize the stepper library on pins 8 through 11:\nStepper myStepper = Stepper(stepsPerRevolution, 8, 9, 10, 11);<\/code><\/pre>\n\n\n\n<p>In this case I called the stepper motor \u2018myStepper\u2019 but you can use other names as well, like \u2018z_motor\u2019 or \u2018liftmotor\u2019 etc.&nbsp;<code>Stepper liftmotor = Stepper(stepsPerRevolution, 8, 9, 10, 11);<\/code>. The name \u2018myStepper\u2019 will be used to set the speed and number of steps for this particular motor. Note that you can create multiple stepper objects with different names if you want to control more than one motor.<\/p>\n\n\n\n<p>In the&nbsp;<code>setup()<\/code>&nbsp;we define the speed of the motor. You can set the speed of the motor in&nbsp;<strong>RPM<\/strong>&nbsp;with the function&nbsp;<kbd>setSpeed(rpm)<\/kbd>. I set it to 100, so we should see around 1.6 revolutions per second.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> \/\/ Set the motor speed (RPMs):\n  myStepper.setSpeed(100);<\/code><\/pre>\n\n\n\n<p>In the loop section of code, we simply call the&nbsp;<code>step(steps)<\/code>&nbsp;function which turns the motor a specific number of steps at a speed determined by the&nbsp;<code>setSpeed(rpm)<\/code>&nbsp;function. Passing a negative number to this function reverses the spinning direction of the motor.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void loop() {\n  \/\/ Step one revolution in one direction:\n  myStepper.step(200);\n\n  delay(2000);\n\n  \/\/ Step on revolution in the other direction:\n  myStepper.step(-200);\n\n  delay(2000);\n}<\/code><\/pre>\n\n\n\n<p>Note that the&nbsp;<strong>step(steps)<\/strong>&nbsp;function is&nbsp;<strong>blocking<\/strong>, this means it will wait until the motor has finished moving to pass control to the next line in your sketch.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Application and uses<\/h2>\n\n\n\n<p>Stepper motors are widely used in various applications that require precise control of rotational motion. Here&#8217;s a brief description of some common stepper motor applications:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>3D Printing<\/strong>: Stepper motors are used to control the movement of the print head and build platform in 3D printers, enabling precise layer-by-layer printing.<\/li>\n\n\n\n<li><strong>CNC Machines<\/strong>: Stepper motors drive the movement of cutting tools and workpieces in computer numerical control (CNC) machines, ensuring accurate machining operations.<\/li>\n\n\n\n<li><strong>Robotics<\/strong>: Stepper motors play a critical role in the movement and positioning of robot arms, joints, and other components, allowing for precise and controlled motion.<\/li>\n\n\n\n<li><strong>Textile Machinery<\/strong>: In textile industry machinery, stepper motors control the movement of various elements like spindles, rollers, and fabric feeders, enabling intricate fabric patterns.<\/li>\n\n\n\n<li><strong>Camera and Photography Equipment<\/strong>: Stepper motors are used in autofocus mechanisms, zoom lenses, and camera panning systems for accurate positioning and movement control.<\/li>\n\n\n\n<li><strong>Medical Devices<\/strong>: Stepper motors are found in medical imaging equipment, such as MRI machines and CT scanners, where precise motion is vital for high-quality imaging.<\/li>\n\n\n\n<li><strong>Automated Systems<\/strong>: Stepper motors are used in automated systems for tasks like conveyor belt control, packaging, and material handling.<\/li>\n\n\n\n<li><strong>Telescopes and Astronomy<\/strong>: Stepper motors enable precise tracking and positioning in telescopes, equatorial mounts, and other astronomy equipment.<\/li>\n\n\n\n<li><strong>Biotechnology and Laboratory Equipment<\/strong>: Stepper motors are used in laboratory automation, such as pipetting and sample handling in medical and biotech research.<\/li>\n\n\n\n<li><strong>Consumer Electronics<\/strong>: Stepper motors are found in various consumer devices, including DVD drives, 3D printers, and home automation systems.<\/li>\n\n\n\n<li><strong>Automotive<\/strong>: In the automotive industry, stepper motors are used in systems like fuel injection, HVAC controls, and headlamp positioning.<\/li>\n\n\n\n<li><strong>Security Systems<\/strong>: Stepper motors control movements in security cameras, pan-tilt-zoom (PTZ) systems, and access control systems.<\/li>\n<\/ol>\n\n\n\n<p>Stepper motors are favored for their ability to move in precise, discrete steps, making them suitable for applications where accuracy and control are essential. Their versatility and reliability make them a key component in various industries.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>L298N + Nema17 stepper + development board + Arduino code<\/p>\n","protected":false},"author":2,"featured_media":12039,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_layout":"no_sidebar_content_centered","footnotes":""},"categories":[18,16],"tags":[],"class_list":["post-11321","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-connectingexamples","category-tutorials"],"_links":{"self":[{"href":"https:\/\/learn.groundstudio.eu\/en\/wp-json\/wp\/v2\/posts\/11321","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learn.groundstudio.eu\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learn.groundstudio.eu\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learn.groundstudio.eu\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/learn.groundstudio.eu\/en\/wp-json\/wp\/v2\/comments?post=11321"}],"version-history":[{"count":43,"href":"https:\/\/learn.groundstudio.eu\/en\/wp-json\/wp\/v2\/posts\/11321\/revisions"}],"predecessor-version":[{"id":12389,"href":"https:\/\/learn.groundstudio.eu\/en\/wp-json\/wp\/v2\/posts\/11321\/revisions\/12389"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/learn.groundstudio.eu\/en\/wp-json\/wp\/v2\/media\/12039"}],"wp:attachment":[{"href":"https:\/\/learn.groundstudio.eu\/en\/wp-json\/wp\/v2\/media?parent=11321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learn.groundstudio.eu\/en\/wp-json\/wp\/v2\/categories?post=11321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learn.groundstudio.eu\/en\/wp-json\/wp\/v2\/tags?post=11321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}