2015年10月5日 星期一

Building the Android APP to control Arduino Smart Car (製作Android APP控制Arduino 智慧車)


Below is a compeleted sample code created from MIT APP inventor2.
To Show how to connect to Andruino thru BT.
You can modify it by youself to meet which function you want.
Bassically,it is really easy to build a APP to support Arduino +BT projects  .

##這是一個用MIT APP Inventor2 所製作的Andriod APP .透過藍芽連接可以用來控制
由Arduino 所做的智慧小車.這是一個完整的範例,你也可以自己修改它來完成其他功能.
基本上由MIT APP Inventor2 來製作的Andriod APP 其實非常簡單,很容易就可以達成跟Arduino 做藍芽(BT)連線控制的動作.

Download this APP.Arduino SmartCar


<Picture 1> This is the APP layout ,At first,put the elements on the Screen1.
<Picture 1> 首先放所有元件在Screen1.




 <Picture 2>Programming like as blocks.This picture show the initialize  variables and do the BT connecting.
 <Picture 2>底下開始就是用積木拼圖式的方式做程式設計,底下這段做完變數初始化後,便是做來藍芽連線的功能.

 <Picture 3> When puch the buttons on the APP Screen to send the "TEXT command" to Anduino thru BT.The  " TEXT command" like as "ST","FW","BW","RW","LW" ,you can define them by yourself.then,On Arduino Side ,When Arduino SmartCar   get these " TEXT commands" to do the motor actions.Such as when get "ST" then stop the Car.When get the "FW" then let the SmartCar driving forward.

 <Picture 3> 底下的程式當按下APP上的上下左右的按鈕時,在藍芽以連線的狀態下會送出"文字命令" 像"ST","FW","BW","RW","LW" ,這些是純文字形式你可以自己定義他們,例如"ST" 就代表停止,"FW"代表車子往前走.這些"文字命令" 透過藍芽傳到Arduino 智慧小車端,在Arduino的程式裡就可以做對應的控制.



 <Picture 4>Below coding is relative with "checkbox" function.I created 3 checkbox function switch.   When Checkbox1 be selected ,It indicated Arduino SmartCar in "Phone controlled  mode" and Checkbox2   be selected It  indicated Arduino SmartCar in  "AUTO mode".The last Checkbox3 be selected means "Search Line mode".  Arduino SmartCar can get these   "AA"/"BB"/"CC"  text command to switch the driving mode.and change the slide bar can change the car speed.It can send the "P0"-"P9" text to arduino with 10 level speed.

<Picture 4>我在這個程式上做了3個 可以勾選切換行車模式的功能,當第一個checkbox被勾選時
會進了自動模式,第二個則是手機遙控模式,第三則是預留給循線模式,當Arduino收到  "AA"/"BB"/"CC"時,即可做出對應模式的切換.另外滑動滑桿則可以改變行車速度.他會送"P0"-"P9"給Arduino ,可以有10階速度調整.






<Pictur 5>This is the APP running on my Arduino Mobile phone.Firstly,power on the Arduino SmartCar and check BT function be enable on your mobile Phone.then let the mobile Phone  seraching the BT (in Arduino SmartCar BT module is HC05 ).after matching the BT then you can push the <Connect BT >Button to connect BT in APP.

<Picture 5>這是在手機執行的畫面,確定手機藍芽功能有被打開以及在Arduino SmartCar開電後,到手機的設定裡去做藍芽的配對.之後就可以在APP裡按BT連線<Connect BT Button>.




<Picture 6>Pushing the <Connect BT >Button to connect BT in APP.and select the BT module in Arduino SmartCar.Here is first one HC-05.

<Pictur6> 按下<Connect BT > Button 後選擇Arduino smartCar上的BT 模組做連線,這裡是第一個
HC-05.然後即可做車子控制.







DEMO FILM Mode1 <Auto mode> : Driving Automatically with SuperSonic.
  when detected stuff before 30 cm ,it will brake Automatically  and randomly
 change the driving  directions.




DEMO FILM Mode 2:Mobile Phone controlled mode.