{"id":8878,"date":"2018-04-23T03:23:14","date_gmt":"2018-04-23T07:23:14","guid":{"rendered":"https:\/\/qxf2.com\/blog\/?p=8878"},"modified":"2018-04-23T03:23:14","modified_gmt":"2018-04-23T07:23:14","slug":"arduino-tutorials-for-testers-stepper-motor","status":"publish","type":"post","link":"https:\/\/qxf2.com\/blog\/arduino-tutorials-for-testers-stepper-motor\/","title":{"rendered":"Arduino Tutorials for Testers: Stepper Motor"},"content":{"rendered":"<p>This is the last tutorial of Arduino tutorial series. In this tutorial, you will learn about how to interface stepper motor with Arduino and how to move rotor accurately to a specific angle.<\/p>\n<hr \/>\n<h3>Components Required:<\/h3>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>Arduino Board<\/li>\n<li>Jumper Wires<\/li>\n<li>Stepper Motor ( 28BYJ-48 5VDC)\n<figure id=\"attachment_8879\" aria-describedby=\"caption-attachment-8879\" style=\"width: 492px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2018\/04\/stepper-motor-and-step-wiring.jpg\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-8879\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2018\/04\/stepper-motor-and-step-wiring.jpg\" alt=\"Stepper Motor and Step Wiring\" width=\"492\" height=\"173\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2018\/04\/stepper-motor-and-step-wiring.jpg 492w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2018\/04\/stepper-motor-and-step-wiring-300x105.jpg 300w\" sizes=\"auto, (max-width: 492px) 100vw, 492px\" \/><\/a><figcaption id=\"caption-attachment-8879\" class=\"wp-caption-text\">Fig. 1 Stepper Motor and Step Wiring<\/figcaption><\/figure>\n<p>Above Fig. 1 shows the image of stepper motor 28BYJ-48 and its step wiring details. Stepper Motor (28BYJ-48) operates on 5V DC and it is unipolar type of stepper motor. It has 4 phase. By controlling phase coils, you can move the stepper\u00a0motor. To move stepper motor in clockwise or anticlockwise direction, we need to provide a step signals in specific\u00a0sequential order to the stepper\u00a0motor. To know more about how stepper motor works refer the link <a href=\"https:\/\/www.imagesco.com\/articles\/picstepper\/02.html\">here<\/a>.<\/li>\n<li>Stepper Motor Driver ULN 2003\/2803\n<figure id=\"attachment_8880\" aria-describedby=\"caption-attachment-8880\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2018\/04\/IMG_20180402_172325211_HDR.jpg\" data-rel=\"lightbox-image-1\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-8880\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2018\/04\/IMG_20180402_172325211_HDR-300x282.jpg\" alt=\"ULN2003 Driver Board\" width=\"300\" height=\"282\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2018\/04\/IMG_20180402_172325211_HDR-300x282.jpg 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2018\/04\/IMG_20180402_172325211_HDR-768x721.jpg 768w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2018\/04\/IMG_20180402_172325211_HDR-1024x962.jpg 1024w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2018\/04\/IMG_20180402_172325211_HDR.jpg 1053w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-8880\" class=\"wp-caption-text\">Fig.2 ULN2003 Driver Board<\/figcaption><\/figure>\n<p>Above fig 2 shows ULN2003 Driver Board. Arduino Uno alone is not capable to drive a stepper motor.\u00a0 So, a driver is\u00a0must for driving a stepper motor.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p><strong>Note:<\/strong> You can get these components fairly easily at many places (including online). We bought for our engineers this <a href=\"https:\/\/www.amazon.in\/dp\/B01KNR581U\/ref=ox_ya_os_product\">Arduino super-starter kit<\/a>.<\/p>\n<hr \/>\n<h3>For what kind of applications do you need Stepper Motor?<\/h3>\n<p>You can use the stepper motor in any application where you need precise positioning with a motor. Stepper motors can&#8217;t run at higher speeds but have a high holding torque. Below are the few applications where you can use the stepper motor:<\/p>\n<ol>\n<li>In Robotics (for ex. in mobile robots for precise movement)<\/li>\n<li>For Railway Gate Control System<\/li>\n<li>In automobiles (for ex. for head light adjustment)<\/li>\n<li>For 3D printer<\/li>\n<li>We used it for testing Fitbit heart rate monitoring system, you will get the details\u00a0<a href=\"https:\/\/qxf2.com\/blog\/testing-the-fitbit-heart-rate-monitoring-system-part-2\/\">here<\/a><\/li>\n<\/ol>\n<hr \/>\n<h3>\u00a0Interfacing of Stepper Motor with Arduino Uno:<\/h3>\n<figure id=\"attachment_8881\" aria-describedby=\"caption-attachment-8881\" style=\"width: 650px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2018\/04\/1522671932.jpg\" data-rel=\"lightbox-image-2\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8881 size-full\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2018\/04\/1522671932.jpg\" alt=\"Interfacing of Stepper Motor with Arduino Uno\" width=\"650\" height=\"322\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2018\/04\/1522671932.jpg 650w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2018\/04\/1522671932-300x149.jpg 300w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/a><figcaption id=\"caption-attachment-8881\" class=\"wp-caption-text\">Fig.3 Interfacing of Stepper Motor with Arduino Uno<\/figcaption><\/figure>\n<p><strong>Wiring Details:<\/strong><\/p>\n<ol>\n<li>Connect pin number (8 to 11) of\u00a0Arduino Uno to ULN Driver Board pin (IN1 to IN4) respectively.<\/li>\n<li>Connect &#8216;Vcc&#8217; pin of Arduino Uno to &#8216;+&#8217; pin of\u00a0ULN Driver Board<\/li>\n<li>Connect &#8216;GND&#8217; pin of Arduino Uno to &#8216;-&#8216; pin of\u00a0ULN Driver Board<\/li>\n<li>Connect\u00a0ULN Driver Board and Stepper motor using the connector as shown in fig. 3<\/li>\n<\/ol>\n<p>Look at above fig 3 and wiring details to interface the stepper motor with Arduino Uno.<\/p>\n<hr \/>\n<h3>Write a code to drive stepper motor clockwise and anticlockwise:<\/h3>\n<pre lang=\"Arduino\">#include <Stepper.h> \r\n\/\/Declare variables and assign pin number\r\nint in1Pin = 8;\r\nint in2Pin = 9;\r\nint in3Pin = 10;\r\nint in4Pin = 11;\r\nconst int stepsPerRevolution = 2048;\/\/ Update the number of steps per revolution required for your motor\r\n\/\/ Create a stepper object \r\n\/\/ Note: We are using 28BYJ-48 5VDC Stepper Motor, for this motor, we need to set wiring sequence to (1-3-2-4) instead of (1-2-3-4)\r\nStepper motor(stepsPerRevolution, in1Pin, in3Pin, in2Pin, in4Pin); \r\n \r\nvoid setup()\r\n{ Serial.begin(9600);  \/\/Enable serial monitor\/communication\r\n  Serial.print(\"Set motor speed to (in RPM) : \");  \/\/ prompt message on serial monitor for user\r\n  while(Serial.available()==0); { }     \/\/ wait here until user enter input data\r\n  int user_speed= Serial.parseInt();   \/\/ Read entered integer value and store it in a variable\r\n  Serial.println(user_speed);    \/\/ print user speed on serial monitor\r\n  motor.setSpeed(user_speed);  \/\/ Set stepper motor speed to user defined speed\r\n}\r\n\r\nvoid loop()\r\n{ \r\n  \/\/ step one revolution in one direction:\r\n  Serial.println(\"clockwise\"); \/\/ print text on serial monitor\r\n  motor.step(stepsPerRevolution); \/\/ rotate motor in clockwise direction for one revolution\r\n  delay(500);\r\n\r\n  \/\/ step one revolution in the other direction:\r\n  Serial.println(\"counterclockwise\"); \/\/ print text on serial monitor\r\n  motor.step(-stepsPerRevolution); \/\/ rotate motor in anticlockwise direction for one revolution\r\n  delay(500);\r\n}\r\n<\/pre>\n<p>Above sketch\/code uses Arduino&#8217;s\u00a0standard library &#8216;Stepper&#8217;. Arduino&#8217;s &#8216;Stepper&#8217; library runs in 4 step mode. To know more about the library and its functions refer the link <a href=\"https:\/\/www.arduino.cc\/en\/Reference\/Stepper\">here<\/a>.\u00a0The gear ratio of our stepper motor is 64 and step angle for 4 step sequence is 11.25 degrees. You need this value to calculate the number of steps required to move the motor 360 degrees(one revolution).<\/p>\n<p><strong>The formula&#8217;s to calculate steps required to move one revolution and move to a specific angle:<\/strong><\/p>\n<ol>\n<li>stepsPerRevolution = (360\/Step Angle) * Gear ratio<br \/>\n= 360\/11.25 * 64<br \/>\n= 2048<\/li>\n<li>No. of steps requires to move \u2018X\u2019 angle = ( stepsPerRevolution \/ 360 ) * \u2018X\u2019<\/li>\n<\/ol>\n<p>Now upload the above sketch and open the serial monitor. You will see a message on the serial monitor about stepper motor speed. Please provide motor speed and press enter. Now, your motor starts rotating in clockwise and anticlockwise alternately. To stop rotating motor\u00a0or to run a motor at the different speed, just press reset button of Arduino Uno. Our stepper motor rotates fine for speed 0 to 25 RPM and it varies from motor to motor.<\/p>\n<hr \/>\n<p>Hope you liked this tutorial. In this tutorial, you learned how to interface with and control a stepper motor. This was the last tutorial of <a href=\"https:\/\/qxf2.com\/blog\/arduino-tutorial-series-for-testers\/\">series<\/a>. Till now, you learned about reading the data from analog and digital pins, generating digital and analog signals on Arduino pins, interfacing and operating of the LCD display, Servo motor, Stepper motor, Ultrasonic sensor, IR Receiver and use of serial monitors for debugging Arduino code. Now, you are ready to understand how hardware products are designed and you can also guess how they were programmed. You may also have gotten ideas about how to test products that have both hardware and software in them.<\/p>\n<p><strong>Learn more <a href=\"https:\/\/qxf2.com\/blog\/about-qxf2\/\">about Qxf2 Services<\/a>.<\/strong><\/p>\n<hr \/>\n","protected":false},"excerpt":{"rendered":"<p>This is the last tutorial of Arduino tutorial series. In this tutorial, you will learn about how to interface stepper motor with Arduino and how to move rotor accurately to a specific angle. Components Required: Arduino Board Jumper Wires Stepper Motor ( 28BYJ-48 5VDC) Above Fig. 1 shows the image of stepper motor 28BYJ-48 and its step wiring details. Stepper [&hellip;]<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[159,117],"tags":[119,163],"class_list":["post-8878","post","type-post","status-publish","format-standard","hentry","category-arduino","category-hardware-testing","tag-arduino","tag-stepper-motor"],"_links":{"self":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/8878","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/comments?post=8878"}],"version-history":[{"count":16,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/8878\/revisions"}],"predecessor-version":[{"id":9282,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/8878\/revisions\/9282"}],"wp:attachment":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/media?parent=8878"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/categories?post=8878"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/tags?post=8878"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}