廢棄的掃描儀也可以再利用。把其中的步進電機和皮帶傳送機構取出來,用Arduino進行控制,即可做成升降機。其中的機械改造是比較費力的問題,但相信對多數人而言,只是用時多少和做工粗細的問題。而步進電機的控制卻可能是比較麻煩的事,因為你得到的這個步進馬達上面并不提供多少有價值的參數,甚至很多連型號都懶得告訴你。下面就介紹我從舊掃描儀中得到的一個步進電機是如何用Arduino進行控制的。
我從掃描儀上得到的步進馬達與外界的連接線有四根:顏色分別為:白色、紅色、藍色和黃色。要讓步進電機正常運轉,還需要一塊馬達驅動板,這里我選擇了L293D控制板,將步進電機連接到驅動板的M3和M4控制端:
///////////////////////////Hardware connections//////////////////////
我從掃描儀上得到的步進馬達與外界的連接線有四根:顏色分別為:白色、紅色、藍色和黃色。要讓步進電機正常運轉,還需要一塊馬達驅動板,這里我選擇了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); */
}