專(zhuān)注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計(jì)實(shí)例 >> 瀏覽文章

將廢棄的掃描儀改造成升降機(jī)

作者:黃大垣   來(lái)源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2013年11月27日   【字體:
      廢棄的掃描儀也可以再利用。把其中的步進(jìn)電機(jī)和皮帶傳送機(jī)構(gòu)取出來(lái),用Arduino進(jìn)行控制,即可做成升降機(jī)。其中的機(jī)械改造是比較費(fèi)力的問(wèn)題,但相信對(duì)多數(shù)人而言,只是用時(shí)多少和做工粗細(xì)的問(wèn)題。而步進(jìn)電機(jī)的控制卻可能是比較麻煩的事,因?yàn)槟愕玫降倪@個(gè)步進(jìn)馬達(dá)上面并不提供多少有價(jià)值的參數(shù),甚至很多連型號(hào)都懶得告訴你。下面就介紹我從舊掃描儀中得到的一個(gè)步進(jìn)電機(jī)是如何用Arduino進(jìn)行控制的。
    我從掃描儀上得到的步進(jìn)馬達(dá)與外界的連接線有四根:顏色分別為:白色、紅色、藍(lán)色和黃色。要讓步進(jìn)電機(jī)正常運(yùn)轉(zhuǎn),還需要一塊馬達(dá)驅(qū)動(dòng)板,這里我選擇了L293D控制板,將步進(jìn)電機(jī)連接到驅(qū)動(dòng)板的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            ///
 //步進(jìn)電機(jī)線顏色          白     紅       藍(lán)       黃          ///
 ///////////////////////////////////////////////////////////////////////////////////
應(yīng)用控制 參考程序:
// 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             ///
 //步進(jìn)電機(jī)線顏色          白     紅       藍(lán)       黃
 /////////////////////////////////////////////////////////////////////
 
 /*\\\\\\\\\\\\\\\\\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); */
}
 
關(guān)閉窗口

相關(guān)文章