Arduino ULN2009 Drive Stepper Motor

Source: Internet
Author: User

I. Physical map

Two. Example code

Note: code from Foreigner http://www.4tronix.co.uk/arduino/Stepper-Motors.php

Function: Control motor positive and negative turn

This Arduino example demonstrates bidirectional operation of A//28byj-48, using a ULN2003 interface board to drive th e stepper.//The 28byj-48 motor was a 4-phase, 8-beat motor, geared down by//a factor of 68. One bipolar winding is on motor pins 1 & 3 and//the other on motor pins 2 & 4. The step angle is 5.625/64 and the//operating Frequency is 100pps. Current draw is 92mA.    Declare variables for the motor pinsint motorPin1 = 8;    blue-28byj48 pin 1int motorPin2 = 9;    pink-28byj48 pin 2int motorPin3 = 10;    yellow-28byj48 pin 3int motorPin4 = 11;  ORANGE-28BYJ48 pin 4//RED-28BYJ48 pin 5 (VCC) int motorspeed = 1200;          Variable to set stepper speedint count = 0; Count of steps Madeint Countsperrev = 512; Number of steps per full revolutionint lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, b01001};/// ////////////////////////////void Setup () {//declare the pins as outputs Pinmode (motorPin1, out  PUT);  Pinmode (motorPin2, OUTPUT);  Pinmode (motorPin3, OUTPUT);  Pinmode (MotorPin4, OUTPUT); Serial.begin (9600);} void Loop () {if (Count <  Countsperrev) clockwise ();  else if (count = = Countsperrev * 2) count = 0;  else anticlockwise (); count++;} Set Pins to ULN2003 high in sequence From 1 to 4//delay "motorspeed" between each pin setting (to determine speed) void anticlockwise () {for (int i = 0; i < 8;    i++) {setoutput (i);  Delaymicroseconds (Motorspeed);    }}void clockwise () {for (int i = 7; I >= 0; i--) {setoutput (i);  Delaymicroseconds (Motorspeed);  }}void setoutput (int out) {digitalwrite (motorPin1, Bitread (Lookup[out], 0));  Digitalwrite (MotorPin2, Bitread (Lookup[out], 1)); DIgitalwrite (MotorPin3, Bitread (Lookup[out], 2)); Digitalwrite (MotorPin4, Bitread (Lookup[out], 3));}

  

Arduino ULN2009 Drive Stepper Motor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.