[3/29_C-Day有什麼?]系列之二:手機遙控雙足機器人

本篇內容是由  CAVEDU 的實習生-黃筱晏提供的使用心得

介紹用二足步行機器人入門這本書做出的機器人

這裡是我們團隊買書的地方:機器人王國商城

01

依照書中作法做出的樣子如下

馬達一顆控制頭部用來改變重心,另一顆為前進後退

02

單一顆9V無法供應motoduino+馬達,所以要用外接電源

→把板子上的J5 移到Ext. Vin 的地方

03

電源馬達連接:

04

藍芽接法:

藍芽設定可以參造Cooper Maa

http://coopermaa2nd.blogspot.tw/2012/06/hc-0x-bluetooth-module.html

05

將motoduino及兩顆9v電池固定後:

06

 

改用motoduino控制馬達及藍芽,軟體方面使用app inventer2

Arduino程式:

const int Motor_E2 = 5;      // digital pin 5 of Arduino (PWM)   

const int Motor_E1 = 6;     // digital pin 6 of Arduino (PWM) 

const int Motor_M2 = 7;     // digital pin 7 of Arduino

const int Motor_M1 = 8;    // digital pin 8 of Arduino

char val; //variable to receive data from the serial port(bluetooth)

 

void setup()

{

  // initialize serial communications at 57600 bps:

  Serial.begin(57600);

 

  pinMode(Motor_M1, OUTPUT);

  pinMode(Motor_M2, OUTPUT);

  Serial.println("Start here");

}

 

void loop()

{

  if(Serial.available())

  {

    val = Serial.read();

    switch(val)

    {

      case 'f':   // car forward

                forward(0, 255);

                break;

      case 'b':   // car backward

                backward(0, 255);

                break;

      case 'l':   // car turn left

                left(0, 255);

                break;

      case 'r':   // car turn right

                right(0, 255);

                break;

      case 's':   // car stop

                motorstop(0, 0);

                break;

     

    }

  }

}

 

void motorstop(byte flag, byte motorspeed)

{

  Serial.println("Stop!");

  digitalWrite( Motor_E1, motorspeed);

  digitalWrite( Motor_E2, motorspeed);

 

}

 

void forward(byte flag, byte motorspeed)

{

  Serial.println("Forward!");

 

  digitalWrite( Motor_M1, HIGH);

  digitalWrite( Motor_M2, HIGH);

 

  analogWrite( Motor_E1, motorspeed);

  analogWrite( Motor_E2, 0);

 

}

 

void backward(byte flag, byte motorspeed)

{

  Serial.println("Backward!");

 

  digitalWrite( Motor_M1, LOW);

  digitalWrite( Motor_M2, LOW);

 

  analogWrite( Motor_E1, motorspeed);

  analogWrite( Motor_E2, 0);

  

}

 

void right(byte flag, byte motorspeed)

{

  Serial.println("Head Turn Right! ");

 

  digitalWrite( Motor_M1, HIGH);

  digitalWrite( Motor_M2, HIGH);

 

  analogWrite( Motor_E1, 0);

  analogWrite( Motor_E2, motorspeed);

 

}

 

void left(byte flag, byte motorspeed)

{

  Serial.println(" Head Turn Left!");

 

  digitalWrite( Motor_M1, LOW);

  digitalWrite( Motor_M2, LOW);

 

  analogWrite( Motor_E1, 0);

  analogWrite( Motor_E2, motorspeed);

 

}

app inventer2程式:

在程式初始化時,設定各元件可否點選

07

在 ListPicker 點選之前設定藍牙的配對裝置位址與名稱

08

當 ListPicker 被點選之後,對藍芽發起連線,若成功則設定各元件能不能點選。

09

當按下按鈕後,Android 手機會經由藍牙發送一個字元給Arduino

10

按下Button7時,斷開藍牙連線,各元件恢復成連線前的樣子。

11

在手機上顯示:

12

Finish:

13

零件提供來源在這裡

Leave a comment

Your email address will not be published.


*