专注电子技术学习与研究
当前位置:单片机教程网 >> MCU设计实例 >> 浏览文章

将废弃的扫描仪改造成升降机

作者:黄大垣   来源:本站原创   点击数:  更新时间:2013年11月27日   【字体:
      废弃的扫描仪也可以再利用。把其中的步进电机和皮带传送机构取出来,用Arduino进行控制,即可做成升降机。其中的机械改造是比较费力的问题,但相信对多数人而言,只是用时多少和做工粗细的问题。而步进电机的控制却可能是比较麻烦的事,因为你得到的这个步进马达上面并不提供多少有价值的参数,甚至很多连型号都懒得告诉你。下面就介绍我从旧扫描仪中得到的一个步进电机是如何用Arduino进行控制的。
    我从扫描仪上得到的步进马达与外界的连接线有四根:颜色分别为:白色、红色、蓝色和黄色。要让步进电机正常运转,还需要一块马达驱动板,这里我选择了L293D控制板,将步进电机连接到驱动板的M3和M4控制端:
 ///////////////////////////Hardware connections//////////////////////
 ////                driver board:L293D                              ///
 ////stepper motor connected to:    M3 &M4               ///
 ////driver board//        M31    M32      M41      M42    ///
 ////stepper motor//       wt     rd       blu      yw            ///
 //步进电机线颜色          白     红       蓝       黄          ///
 ///////////////////////////////////////////////////////////////////////////////////
应用控制 参考程序:
// Stepper driver for Mybot
/*
 *name:stepper driver for mybot
 *function:control stepper motor to move up and down
 *designed: by mzc
 *date:2012.07.21
 */
 //////////////////////////LCD and Keypad code///////////////////////
#include <LCD4Bit_mod.h> 
#include <AFMotor.h>
//create object to control an LCD.  
//number of lines in display=1
LCD4Bit_mod lcd = LCD4Bit_mod(2); 

 
//Key message
char msgs[5][15] = {"Right Key OK ", 
                    "Up Key OK    ", 
                    "Down Key OK  ", 
                    "Left Key OK  ", 
                    "Select Key OK" };
int  adc_key_val[5] ={30, 150, 360, 535, 760 };
int NUM_KEYS = 5;
int adc_key_in;
int key=-1;
int oldkey=-1;
////End LCD and key///
 ///////////////////////////Hardware connections//////////////////////
 ////                driver board:L293D                            ///
 ////stepper motor connected to:    M3 &M4                         ///
 ////driver board//        M31    M32      M41      M42            ///
 ////stepper motor//       wt     rd       blu      yw             ///
 //步进电机线颜色          白     红       蓝       黄
 /////////////////////////////////////////////////////////////////////
 
 /*\\\\\\\\\\\\\\\\\ARDUINO CONNECTED PIN:\\\\\\\\\\\\\\\\\\\\\\\\\\\
  *    MEGA2560                AF MOTOR SHIELD(293D)
         D44(4)                    DIR_CLK---DB4
         D45(7)                    DIR_EN 
         D46(8)                    DIR_SER
         D47(12)                   DIR_LATCH
  *//////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/

 

 
// Connect a stepper motor with 48 steps per revolution (7.5 degree)
// to motor port #2 (M3 and M4)
AF_Stepper motor(48, 2);

 
void setup() {
   lcd.init();
  //optionally, now set up our application-specific display settings, overriding whatever the lcd did in lcd.init()
  //lcd.commandWrite(0x0F);//cursor on, display on, blink on.  (nasty!)
   lcd.clear();
   
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Stepper test!");

 
  motor.setSpeed(540);  // 10 rpm   
}

 
void loop() {
//  Serial.println("Single coil steps");
 // motor.step(500, FORWARD, SINGLE); 
 // motor.step(100, BACKWARD, SINGLE); 

 
//  Serial.println("Double coil steps");
//  motor.step(100, FORWARD, DOUBLE); 
//  motor.step(100, BACKWARD, DOUBLE);
    lcd.cursorTo(2, 0);  //line=2, x=0
//  lcd.printIn("Stepper is running");
  lcd.printIn("Stepper is up");
  motor.step(1500, FORWARD, INTERLEAVE); //上行1500步
  lcd.printIn("Stepper is down");
  motor.step(1500, BACKWARD, INTERLEAVE);  //下行1500步
/*
  Serial.println("Micrsostep steps");
  motor.step(100, FORWARD, MICROSTEP); 
  motor.step(100, BACKWARD, MICROSTEP); */
}
 
关闭窗口

相关文章