Arduino ULN2009驱动步进电机
2015-09-06 18:21
465 查看
一.实物图
二.例子代码
注:代码来自老外 http://www.4tronix.co.uk/arduino/Stepper-Motors.php
功能:控制电机正反转
二.例子代码
注:代码来自老外 http://www.4tronix.co.uk/arduino/Stepper-Motors.php
功能:控制电机正反转
// This Arduino example demonstrates bidirectional operation of a // 28BYJ-48, using a ULN2003 interface board to drive the stepper. // The 28BYJ-48 motor is 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 pins int motorPin1 = 8; // Blue - 28BYJ48 pin 1 int motorPin2 = 9; // Pink - 28BYJ48 pin 2 int motorPin3 = 10; // Yellow - 28BYJ48 pin 3 int motorPin4 = 11; // Orange - 28BYJ48 pin 4 // Red - 28BYJ48 pin 5 (VCC) int motorSpeed = 1200; //variable to set stepper speed int count = 0; // count of steps made int countsperrev = 512; // number of steps per full revolution int lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001}; ////////////////////////////////////////////////////////////////////////////// void setup() { //declare the motor pins as outputs pinMode(motorPin1, OUTPUT); 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)); }
相关文章推荐
- Java中的StringBuilder类功能详解
- java.lang.IllegalArgumentException: the bind value at index 1 is null or java.lang.IllegalArgumen
- UE4在VS2013中各个编译配置代表意义
- 全面解释java中StringBuilder、StringBuffer、String类之间的关系
- ios UIAlertView
- Android更新ui 的几种方式?Handler 机制(二)
- iOS9新特性 - UIStack View
- UI基础-01 隐藏键盘
- DuiLib : 执行按钮事件, 模拟按钮的点击
- UE4的编译配置详解
- Failed to run the WC DB work queue associated with 错误的解决
- ZOJ 3210 A Stack or A Queue?
- Arduino 红外接收
- Qt Quick中的信号机制
- IOS获取设备的UUID
- 父视图 使用 UIViewAnimationWithBlocks 时,如何让子视图无动画
- std::priority_queue
- HDU1047 - Integer Inquiry (大数加法)
- IOS 键盘的显示与关闭,以及移动显示(UITextView处理完整版)
- shop++ CriteriaQuery 数据库查询语句