總網頁瀏覽量

2013年5月9日 星期四

循線自走車製作 = Motoduino(Arduino + L293D) + IR Tracker Sensor +


底下說明如何製作一台循線自走車,將沿著地上黑色膠帶往前行駛,Arduino程式撰寫非常簡單,此次利用市場最便宜的紅外線循跡感測元件(IR Tracker Sensor)來製作及Motoduino一塊板子即可以簡單做到,請參考一下做法。


一.  使用材料 : (材料購買網站)
1.      Motoduino 或  Arduino + 馬達驅動板
2.      紅外線循跡感測器 (IR Tracker Sensor)
3.      9V電池一顆 及 電池釦線
4.      USB傳輸線 (下載程式用)
5.      小車體套件包




圖一

安裝過程 (step by step):

 Step 1: 
        圖一是所有組裝材料及工具,首先可以先把車子底盤兩面的土黃色貼紙撕下,需要花點時間撕下因為黏膠很強,如圖二,或不撕保持貼紙在上面也可以。

圖二


Step 2:
       利用螺絲及馬達固定鐵片把馬達固定在車子底盤上,如圖三及圖四。



圖三


圖四

Step 3:
         測速馬盤可以不裝上馬達轉軸上面,如要安裝上去要特別注意不要推的太進去,容易卡到馬達固定鐵片邊緣,圖三的測速馬盤就推太進去且利用四條馬達電線(兩黑兩紅)直接接上馬達或用焊接方式也可以。



Step 4:
        萬向輪的固定比較麻煩一點,利用銅柱螺絲鎖在底盤上,固定方式請參考圖五及圖六。




圖五


圖六


Step 5:
        固定IR Tracker Sensor於自走車平台下方,且利用塑膠柱螺絲鎖在前方底盤上,固定方式請參考圖七。連接 6 PIN 排線於Sensor上



                                                                          圖七




Step 6:
        連接 6 PIN 排線於Sensor上,接法如圖八及圖九(實際上只接5 pin)。
        Vcc --> 5V, GND-->GND, L -->D9, C-->D10, R-->D11。
    如果是配合新版  Motoduino U1 則
       Vcc --> 5V, GND-->GND, L -->D9, C-->D8, R-->D7



                                                                           圖八


                                                                         圖九
    




Step 7:
        完成圖如圖十。有些細節組裝可以參考我其它文章。
                                           

                                                                        圖十





Arduino 程式 (Sketch):
 程式說明:  
                              

 /////////////////////////////////////////////

///三路紅外線感測器與Motoduino的腳位對應
// 如果是用 Motoduino 第一版  使用如下
//const int SLeftLeft = 9;      //左感測器輸入腳
//const int SMiddle = 10;     //中間感測器輸入腳
//const int SRightRight = 11;     //右感測器輸入腳

// 如果是用 Motoduino U1 則使用如下  
const int SLeftLeft = 9;      //左感測器輸入腳
const int SMiddle = 8;     //中間感測器輸入腳

const int SRightRight = 7;     //右感測器輸入腳


// 馬達與motoduino的腳位對應
// 如果是用 Motoduino 第一版  
//const int Motor_E2 = 5; // 控制馬達2轉速 digital pin 5 of Arduino (PWM)    
//const int Motor_E1 = 6;  // 控制馬達1轉速 digital pin 6 of Arduino (PWM)  
//const int Motor_M1 = 7;     // 控制馬達1正反轉 digital pin 7 of Arduino
//const int Motor_M2 = 8;    // 控制馬達2正反轉 digital pin 8 of Arduino

// 如果是用 Motoduino U1 則   
const int Motor_E2 = 6; // 控制馬達2轉速 digital pin 6 of Arduino (PWM)    
const int Motor_E1 = 5;  // 控制馬達1轉速 digital pin 5 of Arduino (PWM)  
const int Motor_M1 = 10;     // 控制馬達1正反轉 digital pin 10 of Arduino


const int Motor_M2 = 11;    // 控制馬達2正反轉 digital pin 11 of Arduino
// 感測器狀態值
byte byteSensorStatus=0;

void setup() {
   //set up serial communications
   Serial.begin(57600);

  // 輸出入接腳初始設定
  pinMode(SLeftLeft, INPUT);
  pinMode(SMiddle, INPUT);
  pinMode(SRightRight, INPUT);
  
  pinMode(Motor_M1, OUTPUT);  // 設定 Motor_M1為輸出腳位
  pinMode(Motor_M2, OUTPUT);  // 設定 Motor_M2為輸出腳位
}

//////////// 主程式 ////////
void loop(){
  int nIRStatus;  

  //清除感測器狀態值
  byteSensorStatus = 0;
  // 讀取左感測器狀態值
  nIRStatus = digitalRead(SLeftLeft);
  if(nIRStatus == 1)
     byteSensorStatus = (byteSensorStatus | (0x01 << 2));
     
  // 讀取中間感測器狀態值   
  nIRStatus = digitalRead(SMiddle);
  if(nIRStatus == 1)
     byteSensorStatus = (byteSensorStatus | (0x01 << 1));
     
    // 讀取右邊感測器狀態值   
  nIRStatus = digitalRead(SRightRight);
  if(nIRStatus == 1)
     byteSensorStatus = (byteSensorStatus | 0x01);

   drivemotor(byteSensorStatus);
}
///////////////////////////

void drivemotor(byte nStatus)
{
  switch(nStatus)
  { //   感測器 黑色:1   白色:0
    case 7: // SL:1 SM:1 SR:1  //黑黑黑
            motorstop(0, 0);
            break;
    case 6: // SL:1 SM:1 SR:0  //黑黑白
            left(0, 255);
            break;
    case 5: // SL:1 SM:0 SR:1  //黑白黑
            motorstop(0, 255);
            break;
    case 4: // SL:1 SM:0 SR:0  //黑白白
            left(0, 255);
            break;
    case 3: // SL:0 SM:1 SR:1 // 白黑黑
             right(0, 255);
             break;
    case 2: // SL:0 SM:1 SR:0  // 白黑白
             forward(0, 255);
             break;
    case 1: // SL:0 SM:0 SR:1  // 白白黑
             right(0, 255);
             break;
    case 0: // SL:0 SM:0 SR:0  //白白白
             forward(0, 255);
  }

}

void motorstop(byte flag, byte motorspeed)
{
  Serial.println("停止!");
  
  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, motorspeed);
}

void backward(byte flag, byte motorspeed)
{
  Serial.println("backward!");
  
  digitalWrite( Motor_M1, LOW);
  digitalWrite( Motor_M2, LOW);
  analogWrite( Motor_E1, motorspeed);
  analogWrite( Motor_E2, motorspeed);

}

void right(byte flag, byte motorspeed)
{
  Serial.println("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("left!");  
  
  digitalWrite( Motor_M1, HIGH);
  digitalWrite( Motor_M2, HIGH);
  analogWrite( Motor_E1, motorspeed);
  analogWrite( Motor_E2, 0);

}
////////////////////////////////////////////////////


影片觀賞: http://www.youtube.com/watch?v=sTala_3r8mA&list=UU6aKpj71jLKYABYLr3Wbpuw&index=13

參考資料網站:
     http://motoduino.com
     http://sinocgtchen.blogspot.com







2013年4月25日 星期四

(Part 1)長距離溫度感測(Temperature Sensor) = Arduino UNO + S4A Sensor Board + 7 segment LED + LM35


說明:
最近專為S4A Sensor Board 開發了幾個Sensor terminal,例如溫度感測,磁簧感測,土壤濕度感測等等,今天就拿LM35溫度感測Terminal及七段顯示器來做實驗,此Terminal設計成電話線接頭的好處就是容易接線不會接錯孔位甚至燒掉板子,另一好處是可以接長距離的電話線,此實驗利用一條10公尺電話線接LM35溫度感測terminal, 另一條約30公分的電話線接 七段顯示器, S4A sensor board疊在Arduino UNO上.

一系列的Sensor Terminal即將推出...............



使用材料:
1.Arduino UNO
2.S4A Sensor Board
3.LM35 溫度感測Terminal
4.LED七段顯示器Terminal
5.兩條6P4C或6P6C電話線.
6.9V電池一顆





執行步驟:
1.下載程式到 Arduino UNO上
2. LM35溫度感測接到 A3電話孔位
3. 七段顯示接到A4A5電話孔位
4. 接上9V電池.



Arduino Sketch:


#include <ZtLib.h>
#include <Wire.h>
#define ZTSEG8B4_ADDR  0x37

int analogPin = A3;
int readValue = 0;
float temperature = 0;
void setup()
{
   ZT.I2cInit();
   Serial.begin(9600);
}

void loop()
{
  readValue = analogRead(analogPin);  // readValue : 0~1023 (ADC 10bits)
  temperature = (readValue * 0.0049);
  temperature = temperature * 100;  //
  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.print("C ");
  temperature = temperature * 100;  // for LED display
   ZT.Seg8b4DisplayDec(ZTSEG8B4_ADDR, temperature, DISP_AUTO, DOT_BIT2);
   delay(1000);  
}


觀賞影片:  https://www.youtube.com/watch?v=kp5WVIgRbIw

相關資訊請參考:
http://www.motoduino.com
http://sinocgtchen.blogspot.com



2013年2月21日 星期四

手機藍芽遙控車解決方案 = Motoduino (arduino) + Blutooth + android mobile


來做做android手機遙控車,不用寫任何程式也可以玩,利用Motoduino一塊板子簡單即可以簡單做到,請參考一下做法。


一.  使用材料 : (材料購買網站)
1.      Motoduino 或  Arduino + 馬達驅動板
2.      TTL藍芽模組
3.      9V電池一顆 及 電池釦線
4.      USB傳輸線 (下載程式用)
5.      小車體套件包

圖一

安裝過程 (step by step):

 Step 1: 
        圖一是所有組裝材料及工具,首先可以先把車子底盤兩面的土黃色貼紙撕下,需要花點時間撕下因為黏膠很強,如圖二,或不撕保持貼紙在上面也可以。

圖二


Step 2:
       利用螺絲及馬達固定鐵片把馬達固定在車子底盤上,如圖三及圖四。



圖三


圖四

Step 3:
         測速馬盤可以不裝上馬達轉軸上面,如要安裝上去要特別注意不要推的太進去,容易卡到馬達固定鐵片邊緣,圖三的測速馬盤就推太進去且利用四條馬達電線(兩黑兩紅)直接接上馬達或用焊接方式也可以。



Step 4:
        萬向輪的固定比較麻煩一點,利用銅柱螺絲鎖在底盤上,固定方式請參考圖五及圖六。




圖五


圖六


Step 5:
        接下來固定motoduino(或arduino)板子於車子底盤上,需要兩根較長的螺絲訂定,如圖七紅色圈起來的地方。

圖七


Step 6:
        接下來利用四條電線(兩黑兩紅)直接接上馬達或用焊接方式,如圖八。注意紅黑接線的位置不要搞錯,如果接錯放心馬達不會燒掉,頂多是馬達正反轉會相反。可以在下一步驟座調適。


圖八


Step 7:
         四條馬達電線接到motoduino板子上的馬達接頭 ,接線方式請參考圖九 ,以及插上藍芽模組於板子上,注意藍芽模組不可以接反。


圖九

Step 8:
           圖十為安裝完成接上電池的狀態。

圖十

Step 9:
         安裝手機APP程式到手機上。下載點請至 http://www.motoduino.com/download-twn/ 找到 Motoduino Remote Car(檔名為 mduino2.apk) ,注意手機版本要2.2以上。程式執行後畫面會出現四個按鈕,此時按下手機Menu鍵會看到一個Connect, 按下Connect進入藍芽裝置搜尋畫面後按下Device Discovery開始蒐尋遙控車的藍芽裝置,後續請參考motoduino使用手冊(motoduino)。


Step 10:
           一切都沒問題後就可以開始玩玩手機遙控車,按鈕遙控功能試完後,記得試試一個Sensor(G-Sensor)功能,只要手機前後或左右傾斜就可以控制車子前進方向。



Motoduino介紹網站: http://www.motoduino.com (source code下載處)



2012年12月17日 星期一

Arduino Interactive Shield (S4A Sensor Board)




介紹一塊新板子給初學者,Arduino Interactive Shield (AIS)主要設計給Arduino或S4A初學者使用的一塊互動板,結合麥克風、按鍵開關、光源感測、滑桿式可變電阻、LED 、蜂鳴器等元件,以及四組RJ11的接頭可供外部連接其他裝置或元件,如溫濕度感測器、土壤濕度感測器等。另外預留一個藍芽孔位給需要無線傳輸的使用者。可利用此無線傳輸跟Android手機或電腦溝通。AIS板子上也預留六根數位腳位給其他需要外部電源的裝置使用,例如連接多個伺服馬達。

一.     內容說明及特點:


特點:
1. 四個RJ11接頭容易外接其他裝置(D2/D3, A3,A4,A5)
2. 一個一公分大小的按鍵開關(D2)
3. 一個蜂鳴器(D9)
4. 一個麥克風( A2)
5. 兩顆 LED 顯示,一顆為紅色(D10),一顆為綠色(D11)
6. 一個滑桿可變電阻(10K),有效行程65mm.(A0)
7. 一個光感測元件(A1)
8. 預留一個藍芽孔位(UART)
9. RJ11接頭可用電話線連接至少10米距離的感測元件



Motoduino資訊: http://motoduino.com