有幸能從報廢的機器的光驅中拆除幾個電機,大概是像下方圖片中那樣的。可是這個電機只有四根外接的引腳,以前對不只電機不是很懂,這兩天經過查閱資料,瞭解到這個電機被稱爲兩相雙極性步進電機。git
在此大概敘述下兩相雙極性電機的工做原理。以下圖所示,步進電機只有兩相(即兩組定子),雙極性表明兩個定子纏繞的線圈能夠兩個方向通電。oop
簡單用圖片表示下90度兩相雙極性步進電機轉一圈的過程。1表示相1正向通電,1~表示相1方向通電。ui
上面只是簡單敘述了下兩相雙極性步進電機的工做原理,下面進入正題,使用proteus進行仿真Arduino來控制電機。spa
仿真:使用L298(U3)驅動四線兩相雙極性步進電機。code
代碼:MotorTwo爲兩相雙極性電機驅動。blog
/* Main.ino file generated by New Project wizard * * Created: Thu Sep 5 2013 * Processor: ATmega328P * Compiler: Arduino AVR */ #define LED ( 13 ) #define MOTOR_PIN0 ( 0 ) #define MOTOR_PIN1 ( 1 ) #define MOTOR_PIN2 ( 2 ) #define MOTOR_PIN3 ( 3 ) #define MOTOR_PIN4 ( 4 ) #define MOTOR_PIN5 ( 5 ) #define MOTOR_PIN6 ( 6 ) #define MOTOR_PIN7 ( 7 ) #define MOTOR_ENA ( 8 ) #define MOTOR_ENB ( 9 ) void setup() { // put your setup code here, to run once: pinMode( LED, OUTPUT ); pinMode( MOTOR_PIN0, OUTPUT ); pinMode( MOTOR_PIN1, OUTPUT ); pinMode( MOTOR_PIN2, OUTPUT ); pinMode( MOTOR_PIN3, OUTPUT ); pinMode( MOTOR_PIN4, OUTPUT ); pinMode( MOTOR_PIN5, OUTPUT ); pinMode( MOTOR_PIN6, OUTPUT ); pinMode( MOTOR_PIN7, OUTPUT ); pinMode( MOTOR_ENA, OUTPUT ); pinMode( MOTOR_ENB, OUTPUT ); } void MotorOne() { static int i = 3; switch( i-- ) { case 0: digitalWrite( MOTOR_PIN0, HIGH ); digitalWrite( MOTOR_PIN1, LOW ); digitalWrite( MOTOR_PIN2, LOW ); digitalWrite( MOTOR_PIN3, LOW ); break; case 1: digitalWrite( MOTOR_PIN0, LOW ); digitalWrite( MOTOR_PIN1, HIGH ); digitalWrite( MOTOR_PIN2, LOW ); digitalWrite( MOTOR_PIN3, LOW ); break; case 2: digitalWrite( MOTOR_PIN0, LOW ); digitalWrite( MOTOR_PIN1, LOW ); digitalWrite( MOTOR_PIN2, HIGH ); digitalWrite( MOTOR_PIN3, LOW ); break; case 3: digitalWrite( MOTOR_PIN0, LOW ); digitalWrite( MOTOR_PIN1, LOW ); digitalWrite( MOTOR_PIN2, LOW ); digitalWrite( MOTOR_PIN3, HIGH ); break; default: break; } if( 0 > i ) i = 3; } void LedLight() { static int i = 0; if( 0 == i++ ) digitalWrite( LED, HIGH ); else digitalWrite( LED, LOW ); if( 2 <= i ) i = 0; } void MotorTwo() { static int i = 0; switch( i++ ) { case 0: digitalWrite( MOTOR_PIN4, HIGH ); digitalWrite( MOTOR_PIN5, LOW ); digitalWrite( MOTOR_PIN6, LOW ); digitalWrite( MOTOR_PIN7, LOW ); break; case 1: digitalWrite( MOTOR_PIN4, LOW ); digitalWrite( MOTOR_PIN5, HIGH ); digitalWrite( MOTOR_PIN6, LOW ); digitalWrite( MOTOR_PIN7, LOW ); break; case 2: digitalWrite( MOTOR_PIN4, LOW ); digitalWrite( MOTOR_PIN5, LOW ); digitalWrite( MOTOR_PIN6, HIGH ); digitalWrite( MOTOR_PIN7, LOW ); break; case 3: digitalWrite( MOTOR_PIN4, LOW ); digitalWrite( MOTOR_PIN5, LOW ); digitalWrite( MOTOR_PIN6, LOW ); digitalWrite( MOTOR_PIN7, HIGH ); break; default: break; } if( 4 <= i ) i = 0; } void loop() { // put your main code here, to run repeatedly: MotorOne(); LedLight(); MotorTwo(); delay(500); }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~圖片
一切偉大的思想和行動,都有一個微不足道的開始!it