Arduino ULN2009驱动步进电机
一.实物图

二.例子代码
注:代码来自老外 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));
}
Arduino ULN2009驱动步进电机的更多相关文章
- arduino中驱动 步进电机
参考:https://www.arduino.cn/thread-75936-1-1.html 知识点: 步进电机是一种将电脉冲转化为角位移的执行机构.通俗一点讲:当步进驱动器接收到一个脉冲信号 ...
- FPGA驱动步进电机
步进电机 步进电机是将电脉冲信号转变为角位移或线位移的开环控制电机,是现代数字程序控制系统中的主要执行元件,应用极为广泛.在非超载的情况下,电机的转速.停止的位置只取决于脉冲信号的频率和脉冲数,而不受 ...
- python代码实现树莓派3b+驱动步进电机
python代码实现树莓派3b+驱动步进电机 之前买了个树莓派,刚买回来那会儿热情高涨,折腾了一段时间,然后就放那吃灰了.前几天忽然想起来这个东西了,决定再玩玩儿,于是就从某宝上购买了一套步进电机.驱 ...
- 使用Arduino Nano驱动Lora模块
使用Arduino Nano驱动Lora模块 为什么选用Lora 射频通信芯片有很多种,但是一般在同样功耗下,距离没有Lora远;同等范围下,没有Lora节能. Lora通信只适用于低速率,高延时的场 ...
- Arduino+A4988驱动两相四线步进电机
先吐槽一下,在某宝买东西这么多年碰到的不靠谱的卖家也没这几天多.丝杆发短,42电机只有32大,碳杆上的鱼眼粘的没法再歪了还死紧……所以组装还得几天.于是先玩了一下DC-DC降压模块和A4988,规划了 ...
- 使用Pretues仿真Arduino驱动步进电机
这几天想做一个给金鱼自动喂食的装置,所以学习了下如何操控步进电机,现在做个记录. 使用Pretues仿真Arduino的话,可以参考:http://www.geek-workshop.com/thre ...
- arduino驱动步进电机
https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/install-software 1安装库 Adafruit_Motor ...
- Arduino SPI驱动7引脚0.96寸OLED SSD1306 调试笔记
https://www.geek-workshop.com/thread-37818-1-1.html 2.下载最新库https://learn.adafruit.com/monoc ... ibra ...
- 使用STM32控制TMC5160驱动步进电机
首先先来了解一下TMC5160的3种工作模式 TMC5160通过两个引脚来控制它的工作模式:SD_MODE和SPI_MODE. 1.当SD_MODE接地,SPI_MODE拉高,TMC5160即工作在模 ...
随机推荐
- [NOIP2016day2T1] 組合數問題(problem)
题目描述 组合数C(n,m)表示的是从n个物品中选出m个物品的方案数.举个例子,从(1,2,3) 三个物品中选择两个物品可以有(1,2),(1,3),(2,3)这三种选择方法.根据组合数的定 义,我们 ...
- LINUX 内核 图 外国牛人
http://duartes.org/gustavo/blog/ http://blog.csdn.net/drshenlei
- MVC.Net:添加第三方类库的bundles引用
以jQuery Mobile为例.当我们用nuget添加jQuery Mobile的package后,需要在项目中引用jQuery Mobile.传统的做法是在html页面上添加 <link h ...
- 设置ckeditor的高度
设置ckeditor的高度 CKEDITOR.replace('text', { filebrowserImageUploadUrl : 'upload_img.do', language : 'zh ...
- Git 主要的工作流程
Git使用个进制字符的SHA- Hash来唯一标识对象 如:e98757d0598ab6eeaf1df0d87dd00826048bd80b git 有种对象 1.blob 表示文本文件,二进制文件或 ...
- MySQL命令行登陆
环境介绍 OS:CentOS6.X & Win2003 & Win2008 MySQL版本号:5.5.x 除了经常使用的MySQL管理工具,还有MySQLclient命令行工具经常被用 ...
- Android给定坐标计算距离
给定两点的经纬度.计算两点之间的距离.这里要注意经纬度一定要依照顺序填写 1. 利用android中的工具获得,单位是米 float[] results=new float[1]; Location. ...
- SharePoint 2013 Silverlight中使用Netclient对象模型
1.创建Silverlight时,选择Silverlight 4.不要选择版本号5,试了非常久版本号5都调用不了,自己也不知道什么原因.谷歌也没找到答案.后来尝试版本号4,能够调用. 至于Host t ...
- oc45--多对象内存管理 优化
// // main.m // Set方法的内存管理 #import <Foundation/Foundation.h> #import "Person.h" #imp ...
- c# winform 多条件查找 外加网络人才回答
浮生 Э 2012-11-22 c# winform 多条件查找 20 我现在有2个textbox 一个是用户名,另一个是电话 现在想对这两个进行条件查找datagridview里的数据 s ...