做了一個簡單實驗, 利用Arduino/Motoduino控制七顆伺服馬達(手上只有七顆)和一顆步進馬達(2-Phase)運轉,運轉還算順暢! 主要利用 I/O Expansion Shield疊在motoduino上,除了馬達電線容易接線外,還可讓七顆伺服馬達吃外部電源.DIY material (材料):
1. Motoduino (Arduino + L293D motor driver)
2. I/O Expansion shield
3. Servo motor (伺服馬達) x 7
4. Stepper Motor(步進馬達 二相四線) x 1
5. 9V Battery x 2
I/O Expansion Shield V5
Arduino Sketch: (有興趣網友可以把重複程式建立function來呼叫)
#include <Stepper.h>
#include <Servo.h>
Servo servo12; // Define servo12
Servo servo11; // Define servo11
Servo servo10; // Define servo10
Servo servo9; // Define servo9
Servo servo4; // Define servo4
Servo servo3; // Define servo3
Servo servo2; // Define servo2
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution // for your motor
const int Motor_E1 = 5; // digital pin 5 of Arduino (PWM)
const int Motor_E2 = 6; // digital pin 6 of Arduino (PWM)
const int Motor_M1 = 7; // digital pin 7 of Arduino
const int Motor_M2 = 8; // digital pin 8 of Arduino
Stepper myStepper(stepsPerRevolution, Motor_M1, Motor_M2);
int pos = 0;
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
pinMode(Motor_M1, OUTPUT);
pinMode(Motor_M2, OUTPUT);
digitalWrite( Motor_E1, HIGH); // speed control
digitalWrite( Motor_E2, HIGH); // speed control
servo12.attach(12);
servo11.attach(11);
servo10.attach(10);
servo9.attach(9);
servo4.attach(4);
servo3.attach(3);
servo2.attach(2);
}
void loop() {
// step one revolution in one direction:
// Serial.println("clockwise");
myStepper.step(200);
delay(500);
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
servo12.write(pos); // tell servo to go to position in variable 'pos'
servo11.write(pos); // tell servo to go to position in variable 'pos'
servo10.write(pos); // tell servo to go to position in variable 'pos'
servo9.write(pos); // tell servo to go to position in variable 'pos'
servo4.write(pos); // tell servo to go to position in variable 'pos'
servo3.write(pos); // tell servo to go to position in variable 'pos'
servo2.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
servo12.write(pos); // tell servo to go to position in variable 'pos'
servo11.write(pos); // tell servo to go to position in variable 'pos'
servo10.write(pos); // tell servo to go to position in variable 'pos'
servo9.write(pos); // tell servo to go to position in variable 'pos'
servo4.write(pos); // tell servo to go to position in variable 'pos'
servo3.write(pos); // tell servo to go to position in variable 'pos'
servo2.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
servo12.write(pos); // tell servo to go to position in variable 'pos'
servo11.write(pos); // tell servo to go to position in variable 'pos'
servo10.write(pos); // tell servo to go to position in variable 'pos'
servo9.write(pos); // tell servo to go to position in variable 'pos'
servo4.write(pos); // tell servo to go to position in variable 'pos'
servo3.write(pos); // tell servo to go to position in variable 'pos'
servo2.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
servo12.write(pos); // tell servo to go to position in variable 'pos'
servo11.write(pos); // tell servo to go to position in variable 'pos'
servo10.write(pos); // tell servo to go to position in variable 'pos'
servo9.write(pos); // tell servo to go to position in variable 'pos'
servo4.write(pos); // tell servo to go to position in variable 'pos'
servo3.write(pos); // tell servo to go to position in variable 'pos'
servo2.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 10ms for the servo to reach the position
} `
for(pos = 0; pos < 180; pos += 1){ // goes from 0 degrees to 180 degrees
servo12.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 0; pos < 180; pos += 1){ // goes from 0 degrees to 180 degrees
servo11.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 0; pos < 180; pos += 1){ // goes from 0 degrees to 180 degrees
servo10.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 0; pos < 180; pos += 1){ // goes from 0 degrees to 180 degrees
servo9.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 0; pos < 180; pos += 1) { // goes from 0 degrees to 180 degrees
servo4.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 0; pos < 180; pos += 1) { // goes from 0 degrees to 180 degrees
servo3.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 0; pos < 180; pos += 1) { // goes from 0 degrees to 180 degrees
servo2.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 180; pos>=1; pos-=1) { // goes from 180 degrees to 0 degrees
servo2.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 180; pos>=1; pos-=1) { // goes from 180 degrees to 0 degrees
servo3.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 180; pos>=1; pos-=1) { // goes from 180 degrees to 0 degrees
servo4.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 180; pos>=1; pos-=1) { // goes from 180 degrees to 0 degrees
servo9.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 180; pos>=1; pos-=1) { // goes from 180 degrees to 0 degrees
servo10.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 180; pos>=1; pos-=1) { // goes from 180 degrees to 0 degrees
servo11.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 180; pos>=1; pos-=1) { // goes from 180 degrees to 0 degrees
servo12.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 0; pos < 180; pos+=1) { // goes from 0 degrees to 180 degrees
servo12.write(pos); // tell servo to go to position in variable 'pos'
servo11.write(pos); // tell servo to go to position in variable 'pos'
delay(5);
}
for(pos = 180; pos >=1; pos-=1) { // goes from 180 degrees to 0 degrees
servo12.write(pos);
servo11.write(pos); // tell servo to go to position in variable 'pos'
delay(5);
}
myStepper.step(-200);
delay(500);
}
Video: http://www.youtube.com/watch?v=rB-noWhgbXM&list=UU6aKpj71jLKYABYLr3Wbpuw&index=1&feature=plcp
更多影片請看: http://www.youtube.com/user/sinocgtchen
部落格 : http://sinocgtchen.blogspot.com
Motoduino資訊: http://motoduino.com
1. Motoduino (Arduino + L293D motor driver)
2. I/O Expansion shield
3. Servo motor (伺服馬達) x 7
4. Stepper Motor(步進馬達 二相四線) x 1
5. 9V Battery x 2
接線圖
接線圖
I/O Expansion Shield V5
Arduino Sketch: (有興趣網友可以把重複程式建立function來呼叫)
#include <Stepper.h>
#include <Servo.h>
Servo servo12; // Define servo12
Servo servo11; // Define servo11
Servo servo10; // Define servo10
Servo servo9; // Define servo9
Servo servo4; // Define servo4
Servo servo3; // Define servo3
Servo servo2; // Define servo2
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution // for your motor
const int Motor_E1 = 5; // digital pin 5 of Arduino (PWM)
const int Motor_E2 = 6; // digital pin 6 of Arduino (PWM)
const int Motor_M1 = 7; // digital pin 7 of Arduino
const int Motor_M2 = 8; // digital pin 8 of Arduino
Stepper myStepper(stepsPerRevolution, Motor_M1, Motor_M2);
int pos = 0;
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
pinMode(Motor_M1, OUTPUT);
pinMode(Motor_M2, OUTPUT);
digitalWrite( Motor_E1, HIGH); // speed control
digitalWrite( Motor_E2, HIGH); // speed control
servo12.attach(12);
servo11.attach(11);
servo10.attach(10);
servo9.attach(9);
servo4.attach(4);
servo3.attach(3);
servo2.attach(2);
}
void loop() {
// step one revolution in one direction:
// Serial.println("clockwise");
myStepper.step(200);
delay(500);
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
servo12.write(pos); // tell servo to go to position in variable 'pos'
servo11.write(pos); // tell servo to go to position in variable 'pos'
servo10.write(pos); // tell servo to go to position in variable 'pos'
servo9.write(pos); // tell servo to go to position in variable 'pos'
servo4.write(pos); // tell servo to go to position in variable 'pos'
servo3.write(pos); // tell servo to go to position in variable 'pos'
servo2.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
servo12.write(pos); // tell servo to go to position in variable 'pos'
servo11.write(pos); // tell servo to go to position in variable 'pos'
servo10.write(pos); // tell servo to go to position in variable 'pos'
servo9.write(pos); // tell servo to go to position in variable 'pos'
servo4.write(pos); // tell servo to go to position in variable 'pos'
servo3.write(pos); // tell servo to go to position in variable 'pos'
servo2.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
servo12.write(pos); // tell servo to go to position in variable 'pos'
servo11.write(pos); // tell servo to go to position in variable 'pos'
servo10.write(pos); // tell servo to go to position in variable 'pos'
servo9.write(pos); // tell servo to go to position in variable 'pos'
servo4.write(pos); // tell servo to go to position in variable 'pos'
servo3.write(pos); // tell servo to go to position in variable 'pos'
servo2.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
servo12.write(pos); // tell servo to go to position in variable 'pos'
servo11.write(pos); // tell servo to go to position in variable 'pos'
servo10.write(pos); // tell servo to go to position in variable 'pos'
servo9.write(pos); // tell servo to go to position in variable 'pos'
servo4.write(pos); // tell servo to go to position in variable 'pos'
servo3.write(pos); // tell servo to go to position in variable 'pos'
servo2.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 10ms for the servo to reach the position
} `
for(pos = 0; pos < 180; pos += 1){ // goes from 0 degrees to 180 degrees
servo12.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 0; pos < 180; pos += 1){ // goes from 0 degrees to 180 degrees
servo11.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 0; pos < 180; pos += 1){ // goes from 0 degrees to 180 degrees
servo10.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 0; pos < 180; pos += 1){ // goes from 0 degrees to 180 degrees
servo9.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 0; pos < 180; pos += 1) { // goes from 0 degrees to 180 degrees
servo4.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 0; pos < 180; pos += 1) { // goes from 0 degrees to 180 degrees
servo3.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 0; pos < 180; pos += 1) { // goes from 0 degrees to 180 degrees
servo2.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 180; pos>=1; pos-=1) { // goes from 180 degrees to 0 degrees
servo2.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 180; pos>=1; pos-=1) { // goes from 180 degrees to 0 degrees
servo3.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 180; pos>=1; pos-=1) { // goes from 180 degrees to 0 degrees
servo4.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 180; pos>=1; pos-=1) { // goes from 180 degrees to 0 degrees
servo9.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 180; pos>=1; pos-=1) { // goes from 180 degrees to 0 degrees
servo10.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 180; pos>=1; pos-=1) { // goes from 180 degrees to 0 degrees
servo11.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 180; pos>=1; pos-=1) { // goes from 180 degrees to 0 degrees
servo12.write(pos); // tell servo to go to position in variable 'pos'
delay(10);
}
for(pos = 0; pos < 180; pos+=1) { // goes from 0 degrees to 180 degrees
servo12.write(pos); // tell servo to go to position in variable 'pos'
servo11.write(pos); // tell servo to go to position in variable 'pos'
delay(5);
}
for(pos = 180; pos >=1; pos-=1) { // goes from 180 degrees to 0 degrees
servo12.write(pos);
servo11.write(pos); // tell servo to go to position in variable 'pos'
delay(5);
}
myStepper.step(-200);
delay(500);
}
Video: http://www.youtube.com/watch?v=rB-noWhgbXM&list=UU6aKpj71jLKYABYLr3Wbpuw&index=1&feature=plcp
更多影片請看: http://www.youtube.com/user/sinocgtchen
部落格 : http://sinocgtchen.blogspot.com
Motoduino資訊: http://motoduino.com
我想請教一下馬達的吃電問題,讓五顆伺服馬達穩定供電,那需要多少V的電池才夠呢?
回覆刪除需要看馬達規格才能計算出!
刪除我的馬達規格為towerpro mg995 五顆,請問該怎麼計算呢?
刪除工作電壓為 4.8V~6V
回覆刪除