




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、基于Arduino單片機的實物設計 題目: 基于Arduino的智能小車(烏龜)設計姓名: 學院: 專業(yè): 班級: 學號: 指導教師: 設計時間: 目錄一 、任務設計及要求3二、 Arduino42.1 Arduino簡介42.2參數(shù)說明4三、 硬件設計43.1所需硬件清單43.2硬件設計說明53.3電機驅動模塊53.3.1 L298N說明53.3.2 L298N連接圖53.4循跡模塊53.4.1尋線功能53.4.2尋線傳感器與實驗連接圖53.5避碰模塊73.5.1 超聲波模塊73.5.2 實驗連接圖73.6紅外模塊83.6.1紅外模塊說明83.6.2實物圖8四、模塊軟件設計84.1循跡模塊程
2、序84.2 紅外模塊程序104.3避碰模塊程序11五、綜合設計與調(diào)試115.1流程圖115.2軟件設計12六、總結146.1遇到問題及解決辦法141、 硬件問題142、 軟件問題156.2個人感悟15一 、任務設計及要求 利用Arduino設計智能小車(烏龜)其功能: 1、實現(xiàn)循跡(利用TCRT5000 紅外對管); 2、避碰功能(利用超聲波); 3、紅外遙控功能; 4、綜合以上功能實現(xiàn)自動循跡、避障、紅外控制的智能小車; 二、 Arduino 2.1 Arduino簡介ARDUINO 智能小烏龜是一款單片機學習應用開發(fā)系統(tǒng),以 arduino 單片機系列 atmega-328為核心.完成尋線
3、,避障,紅外遙控和藍牙遙控的功能,.套件包含了大量的趣味程序,并可擴展外置的電路模塊,從而增加小車的使用功能.旨在讓使用者在學習 ARDUINO 單片機時能脫離枯燥的理論知識,在玩樂中獲取單片機系統(tǒng)開發(fā)的能力。 2.2參數(shù)說明 1.電機參數(shù):電壓范圍:1.5-12V,電機軸長10mm,轉速 100rpm/min. 2.控制電機選用L298N驅動模塊,與單片機真正隔離. 3.三組尋線模塊,檢測黑白線,精度更高,也可用與防跌落控制. 4.紅外遙控通信模塊,組成智能小車遙控系統(tǒng). 5.超聲波模塊,小車避障系統(tǒng). 5.藍牙無線模塊,可以和手機藍牙配對遙控機器人. 6.可接入外部712V的電壓。并能搭載
4、多款傳感器模塊,根據(jù)您的想象力實現(xiàn)各種功能.三、 硬件設計3.1所需硬件清單1. 金屬減速電機 2 個;2.優(yōu)質輪胎 2 個;3.電機固定件 2 個;4 、牛眼萬向輪;5.機器人底盤 2 片;6.L298N 電機驅動板 1 個;7.ARDUINO UNO328 控制板 1 個;8.ARDUINO 傳感器擴展板 1 個;9.云臺 1 個;10.舵機 1 個;11.超聲波模塊 1 個;12.三組尋線模塊;13.紅外接收傳感器;14.單片機遙控器;15.2000MA 18650 充電電池 2 節(jié);16.18650 電池盒一個;17.18650 充電器一個。3.2硬件設計說明 結合實際、根據(jù)需要,將系
5、統(tǒng)分為四個模塊,即電機驅動模塊,循跡模塊,避碰模塊,紅外模塊,分開做,自后將其綜合起來。3.3電機驅動模塊 3.3.1 L298N說明 L298N是一個驅動模塊,就是單片機的驅動電流太小無法驅動電動機,因此L298N其起到一個放大器作用。通過控制L298N I1 I2 I3 I4接口,控制電機的正轉,反轉,轉彎和停止。 3.3.2 L298N連接圖 如下圖所示:3.4循跡模塊 3.4.1尋線功能 使小車沿著黑線走,根據(jù)黑線的位置選著行走的狀態(tài)。 3.4.2尋線傳感器與實驗連接圖 TCRT5000紅外對管的工作原理是利用紅外線對顏色的反射率不一樣,將 反射信號的強弱轉化成電流信號。黑白尋跡模塊在
6、檢測到黑色高電平有效,檢測到白色是為 低電平有效,檢測高度為 03cm。使用方法1.傳感器接口有3根排針,分別是GND ,VCC,OUT。VCC和GND為供電端,OUT是信 號輸出端。 2.檢測到物體,信號端輸出低電平;未檢測到物體,信號端輸出高電平。 3.主要判斷信號輸出端是0或者1,就能判斷物體是否存在。 性能參數(shù): 1:檢測距離,檢測白紙時約為2厘米。視顏色的不同距離有所不同,白色最遠。 2.供電電壓:2.5V12V,不要超過12V。(注意:最好用低電壓供電,供電電壓太高傳感器的壽命會變短。5V供電為佳。) 3.工作電流,5V時1820ma。經(jīng)大量測試,傳感器硬件設置為1820ma工作電
7、流時性能最 佳,主要表現(xiàn)在抗干擾能力上。4.檢測到物體,信號端輸出低電平;未檢測到物體,信號端輸出高電平。 5.傳感器輸出TTL電平,能直接與3.3V或者5V單片機IO口相連。 黑線或者白線檢測原理 1.利用黑色對光線的反射率小這個特點,當平面的顏色不是黑色時,傳感器發(fā)射出去的紅 外光被大部分反射回來。于是傳感器輸出低電平0。 2.當平面有一黑線,傳感器在黑線上方時,因黑色的反射能力很弱,反射回來的紅外光很 少,達不到傳感器動作的水平,所以傳感器還輸出1。 3.我們只要用單片機判斷傳感器的輸出端是0或者是1,就能檢測黑線。 4.檢測白線的原理和檢測黑線的原理一樣,檢測白線時,白線周邊的顏色也要
8、比較接近黑 色,然后調(diào)節(jié)紅外傳感器上面的可調(diào)電阻,將靈敏度調(diào)低,一直調(diào)到剛好周邊的顏色檢測 不到為止,那樣就能檢測白線了。連接參考圖如下:3.5避碰模塊 3.5.1 超聲波模塊超聲波智能避障實現(xiàn)方便、計算簡單、易于做到實時控制,并且在測量精度方面能達到實用的要求,因此成為常用的避障方法。 3.5.2 實驗連接圖3.6紅外模塊 3.6.1紅外模塊說明實驗前須知:1.先把 IRremote 函式庫資料夾放進 Arduino libraries 目錄底下2.開啟 IrReceive.pde 測得自 己的紅外線遙控的碼(在 Serial Monitor 可顯示 IRcode) , 再將IRcode 記
9、錄下來, 然后到程式里面修改成自 己的紅外線碼即可。3.6.2實物圖四、模塊軟件設計4.1循跡模塊程序第 9 頁 int MotorRight1=8;/IN1int MotorRight2=9;/IN2int MotorLeft1=7;/IN4int MotorLeft2=6;/IN3int speedpin=11;/定義 EA(PWM 調(diào)速)int speedpin1=10;/定義 EB(PWM 調(diào)速)接口const int SensorLeft = 5; /左感測器輸入腳const int SensorMiddle= 4 ; /中感測器輸入腳const int SensorRight =
10、3; /右感測器輸入腳int SL; /左感測器狀態(tài)int SM; /中感測器狀態(tài)int SR; /右感測器狀態(tài)void advance(int a) / 前進 digitalWrite(MotorRight1,LOW); digitalWrite(MotorRight2,HIGH); digitalWrite(MotorLeft1,LOW); digitalWrite(MotorLeft2,HIGH); delay(a*50); void left(int i) / 左轉 digitalWrite(MotorRight1,LOW); digitalWrite(MotorRight2,HIGH
11、); digitalWrite(MotorLeft1,LOW); digitalWrite(MotorLeft2,LOW); delay(i*30); void right(int c) / 右轉 digitalWrite(MotorRight1,LOW); digitalWrite(MotorRight2,LOW); digitalWrite(MotorLeft1,LOW); digitalWrite(MotorLeft2,HIGH);delay(c*30); void stopp(int d) /停止 digitalWrite(MotorRight1,LOW); digitalWrite(
12、MotorRight2,LOW); digitalWrite(MotorLeft1,LOW); digitalWrite(MotorLeft2,LOW); delay(d * 10); void back(int g) /后退 digitalWrite(MotorRight1,HIGH); digitalWrite(MotorRight2,LOW); digitalWrite(MotorLeft1,HIGH); digitalWrite(MotorLeft2,LOW); delay(g * 100); void re(int x) /右大轉 digitalWrite(MotorRight1,L
13、OW); digitalWrite(MotorRight2,HIGH); digitalWrite(MotorLeft1,HIGH); digitalWrite(MotorLeft2,LOW); delay(x * 25); void le(int h) /左打轉 digitalWrite(MotorRight1,HIGH); digitalWrite(MotorRight2,LOW); digitalWrite(MotorLeft1,LOW); digitalWrite(MotorLeft2,HIGH); delay(h * 25); void setup()Serial.begin(960
14、0); pinMode(MotorRight1, OUTPUT); / 腳位 8 (PWM) pinMode(MotorRight2, OUTPUT); / 腳位 9 (PWM) pinMode(MotorLeft1, OUTPUT); / 腳位 7(PWM) pinMode(MotorLeft2, OUTPUT); / 腳位 6 (PWM) pinMode(speedpin,OUTPUT); pinMode(speedpin1,OUTPUT); pinMode(SensorLeft, INPUT); /左感測器 pinMode(SensorMiddle, INPUT);/中感測器 pinMo
15、de(SensorRight, INPUT); /右感測器void loop() SL = digitalRead(SensorLeft); SM = digitalRead(SensorMiddle); SR = digitalRead(SensorRight); SL = digitalRead(SensorLeft); SM = digitalRead(SensorMiddle); SR = digitalRead(SensorRight);if (SM = HIGH) if (SR = LOW & SL = HIGH) / 向左 left(1); stopp(2); else
16、if (SL = LOW & SR = HIGH) right(1);stopp(2); else if(SL = HIGH & SR = HIGH ) if(count<des-1) advance(1); stopp(50); count=count+1; if(count=des-1) le(12); SL = digitalRead(SensorLeft);SM = digitalRead(SensorMiddle);SR = digitalRead(SensorRight); else if(count>=des) digitalWrite(MotorRi
17、ght1,LOW); digitalWrite(MotorRight2,LOW); digitalWrite(MotorLeft1,LOW); digitalWrite(MotorLeft2,LOW); delay(50000); else advance(2) ; else / 直進 advance(1); if (SM=LOW) if(SR=LOW & SL=HIGH) left(1); stopp(2); else if(SL=LOW & SR=HIGH) right(1); stopp(2); if(SL = LOW & SR = LOW & SM=LO
18、W) le(1); 第 16 頁4.2 紅外模塊程序long advence = 0x00FF629D;long back = 0x00FFA857;long stopp = 0x00FF02FD;long left = 0x00FF22DD;long right = 0x00FFC23D;IRrecv irrecv(RECV_PIN);decode_results results;void dump(decode_results *results) int count = results->rawlen; if (results->decode_type = UNKNOWN)Se
19、rial.println("Could not decode message"); elseif(results->decod_type=NEC)Serial.print("Decoded NEC: "); else if (results->decode_type =SONY)Serial.print("Decoded SONY: "); else if (results->decode_type = RC5) Serial.print("Decoded RC5: "); else if (re
20、sults->decode_type = RC6)Serial.print("Decoded RC6: ");Serial.print(results->value, HEX) Serial.print(" (");Serial.print(resuls->bits, DEC); Serial.println("bits)"); Serial.print("Raw("); Serial.print(count, DEC);Serial.print("): ");for (int
21、 i = 0; i < count; i+) if (i % 2) =1)Serial.print(results->rawbufi*USECPERTICK,DEC); elseSerial.print(-(int)results->rawbufi*USECPERTICK, DEC); Serial.print(" "); Serial.println(""); void setup() Serial.begin(9600); irrecv.enableIRIn(); / Start the receiver int on = 0;un
22、signed long last = millis();void(loop) i(irrecv.decode(&results) if (millis() - last > 250) on = !on; digitalWrite(13, on ? HIGH :LOW);dump(&result)if (results.value= ? ) 4.3避碰模塊程序主程序void loop() myservo.write(90); /測量 detection(); /測量角度 if(directionn = 2) /假如 directionn(方向) = 2(倒車) back(5
23、); / 倒退 stopp(); /停止 while(1); if(directionn = 8) advance(2); 五、綜合設計與調(diào)試5.1流程圖 開始 紅外信號 障礙物 路徑1 路徑2 終點 終點 開始5.2軟件設計 #include <IRremote.h> #include <Servo.h>int RECV_PIN = 12;int MotorRight1=8;/IN1int MotorRight2=9;/IN2int MotorLeft1=7;/IN4int MotorLeft2=6;/IN3int speedpin=11;int speedpin1=
24、10;const int SensorLeft = 2; const int SensorMiddle= 4 ; const int SensorRight = 5; int SL; int SM; int SR; int inputPin = A0;int outputPin =A1;int Fspeedd = 0; int directionn = 0; Servo myservo; int delay_time = 250;int Fgo = 8; int Bgo = 2; int count=0;int des=0;int f=0;/*紅外控制部分*long advence = 0x0
25、0FF629D;long b = 0x00FFA857;long s = 0x00FF02FD;long l = 0x00FF22DD;long r = 0x00FFC23D;IRrecv irrecv(RECV_PIN);decode_results results;void dump(decode_results *results)int count = results->rawlen; if (results->decode_type = UNKNOWN) Serial.println("Could not decode message"); else i
26、f (results->decode_type = NEC)Serial.print("Decoded NEC: "); else if (results->decode_type = SONY) Serial.print("Decoded SONY: "); else ifresults->decode_type = RC5) Serial.print("Decoded RC5: "); else if (results->decode_type = RC6) Serial.print("Decod
27、ed RC6: ");Serial.print(results->value, HEX); Serial.print(" ("); Serial.print(results->bits, DEC);Serial.println(" bits)"); Serial.print("Raw ("); Serial.print(count, DEC); Serial.print("): "); for (int i = 0; i < count; i+) if (i % 2) = 1)Seria
28、l.print(results->rawbufi*USECPERTICK, DEC); elseSerial.print(-(int)results->rawbufi*USECPERTICK, DEC); Serial.print(" "); Serial.println(""); int on = 0;unsigned long last = millis();void setup()Serial.begin(9600); pinMode(MotorRight1, OUTPUT); pinMode(MotorRight2, OUTPUT);
29、 pinMode(MotorLeft1, OUTPUT); pinMode(MotorLeft2, OUTPUT); pinMode(SensorLeft, INPUT); pinMode(SensorMiddle, INPUT); pinMode(SensorRight, INPUT); pinMode(speedpin,OUTPUT);pinMode(speedpin1,OUTPUT);Serial.begin(9600); irrecv.enableIRIn(); pinMode(inputPin, INPUT); pinMode(outputPin, OUTPUT); myservo.
30、attach(3); void detection() int delay_time = 250; ask_pin_F(); if(Fspeedd <3 ) directionn =Bgo; else directionn = Fgo; void ask_pin_F() myservo.write(90); digitalWrite(outputPin, LOW); delayMicroseconds(2); digitalWrite(outputPin, HIGH); delayMicroseconds(10); digitalWrite(outputPin, LOW); float
31、Fdistance = pulseIn(inputPin, HIGH); Fdistance= distance/5.8/10; Fspeedd = Fdistance; void advance(int a)digitalWrite(MotorRight1,LOW);digitalWrite(MotorRight2,HIGH);digitalWrite(MotorLeft1,LOW);digitalWrite(MotorLeft2,HIGH);delay(a*50); void left(int i) digitalWrite(MotorRight1,LOW); digitalWrite(M
32、otorRight2,HIGH);digitalWrite(MotorLeft1,LOW);digitalWrite(MotorLeft2,LOW); delay(i*30); void right(int c) digitalWrite(MotorRight1,LOW);digitalWrite(MotorRight2,LOW);digitalWrite(MotorLeft1,LOW);digitalWrite(MotorLeft2,HIGH);delay(c*30); void stopp(int d)digitalWrite(MotorRight1,LOW);digitalWrite(M
33、otorRight2,LOW);digitalWrite(MotorLeft1,LOW);digitalWrite(MotorLeft2,LOW); delay(d * 10); void back(int g) digitalWrite(MotorRight1,HIGH);digitalWrite(MotorRight2,LOW);digitalWrite(MotorLeft1,HIGH);digitalWrite(MotorLeft2,LOW); delay(g * 100); void re(int x) digitalWrite(MotorRight1,LOW); digitalWri
34、te(MotorRight2,HIGH);digitalWrite(MotorLeft1,HIGH);digitalWrite(MotorLeft2,LOW); delay(x * 25); void le(int h) digitalWrite(MotorRight1,HIGH);digitalWrite(MotorRight2,LOW);digitalWrite(MotorLeft1,LOW);digitalWrite(MotorLeft2,HIGH); delay(h * 25); void loop() analogWrite(speedpin,300);analogWrite(spe
35、edpin1,300);if (irrecv.decode(&results) if (millis() - last > 250) on = !on;digitalWrite(13, on ? HIGH : LOW);dump(&results); if (results.value = advence )digitalWrite(MotorRight1,LOW);digitalWrite(MotorRight2,HIGH);digitalWrite(MotorLeft1,LOW);digitalWrite(MotorLeft2,HIGH); des=3; if (re
36、sults.value = b )digitalWrite(MotorRight1,LOW);digitalWrite(MotorRight2,HIGH);digitalWrite(MotorLeft1,LOW);digitalWrite(MotorLeft2,HIGH); des=4;if (results.value = l )digitalWrite(MotorRight1,LOW);digitalWrite(MotorRight2,HIGH);digitalWrite(MotorLeft1,LOW);digitalWrite(MotorLeft2,HIGH); des=5; while
37、(des!=0) myservo.write(90); detection(); if(directionn = 2) f=1; des=des+2;le(20); if(f=0) SL =digitalRead(SensorLeft);SMdigitalRead(SensorMiddle);SR=digitalRead(SensorRight);if (SM = HIGH)/ if (SR = LOW & SL = HIGH) left(1); stopp(2); else if (SL = LOW & SR = HIGH) right(1); stopp(2); else
38、if(SL = HIGH & SR = HIGH ) if(count<des-1) advance(1) stopp(50); count=count+1; f(count=des-1) le(12); SL = digitalRead(SensorLeft); SM=digitalRead(SensorMiddle); SR=digitalRead(SensorRight); else if(count>=des) digitalWrite(MotorRight1,LOW);digitalWrite(MotorRight2,LOW);digitalWrite(Motor
39、Left1,LOW);digitalWrite(MotorLeft2,LOW);delay(50000); else advance(2) ; else advance(1); if (SM=LOW) if(SR=LOW & SL=HIGH) left(1);stopp(2); else if(SL=LOW & SR=HIGH) right(1);stopp(2); if(SL = LOW & SR = LOW & SM=LOW) le(1);if(f=1)SL = digitalRead(SensorLeft);SM =digitalRead(SensorMiddle)SR=digitalRead(SensorRight);if (SM = HIGH) if (SR = LOW & SL = HIGH) left(1);stopp(2) else if (S
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 服裝店導購員銷售激勵服務合同
- 海洋經(jīng)濟項目融資計劃書范文
- 地鐵車站施工組織設計與現(xiàn)場管理服務合同
- 活動替身安全保障賠償補充協(xié)議
- 高清影視作品網(wǎng)絡播放權授權與版權保護協(xié)議
- 體育教練職業(yè)生涯發(fā)展計劃
- 澳洲留學生入境關懷與接送合同
- 生態(tài)環(huán)保項目投資合伙協(xié)議
- 民航機場空調(diào)系統(tǒng)保養(yǎng)及管道清洗作業(yè)合同
- 移動應用數(shù)據(jù)隱私保護與用戶權益保護協(xié)議
- 隧道工程隧道洞口臨建施工方案
- 心理咨詢的面談技術
- DBJ∕T13-374-2021 福建省鋼筋桁架疊合樓板技術標準
- 事故池管理的有關規(guī)定
- (word完整版)污水處理廠安全評價報告
- DB50∕T 867.6-2019 安全生產(chǎn)技術規(guī)范 第6部分:黑色金屬冶煉企業(yè)
- 新產(chǎn)品開發(fā)流程課件
- 高中語文部編版選擇性必修下冊第四單元 單元學習導航 課件 (8張PPT)
- 化妝品原料-PPT課件
- 重慶市參加企業(yè)職工基本養(yǎng)老保險人員退休審批表
- 混凝土結構課程設計244
評論
0/150
提交評論