課設(shè)報(bào)告基于Arduino單片機(jī)的實(shí)物設(shè)計(jì)_第1頁(yè)
課設(shè)報(bào)告基于Arduino單片機(jī)的實(shí)物設(shè)計(jì)_第2頁(yè)
課設(shè)報(bào)告基于Arduino單片機(jī)的實(shí)物設(shè)計(jì)_第3頁(yè)
課設(shè)報(bào)告基于Arduino單片機(jī)的實(shí)物設(shè)計(jì)_第4頁(yè)
課設(shè)報(bào)告基于Arduino單片機(jī)的實(shí)物設(shè)計(jì)_第5頁(yè)
已閱讀5頁(yè),還剩11頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、基于Arduino單片機(jī)的實(shí)物設(shè)計(jì) 題目: 基于Arduino的智能小車(烏龜)設(shè)計(jì)姓名: 學(xué)院: 專業(yè): 班級(jí): 學(xué)號(hào): 指導(dǎo)教師: 設(shè)計(jì)時(shí)間: 目錄一 、任務(wù)設(shè)計(jì)及要求3二、 Arduino42.1 Arduino簡(jiǎn)介42.2參數(shù)說(shuō)明4三、 硬件設(shè)計(jì)43.1所需硬件清單43.2硬件設(shè)計(jì)說(shuō)明53.3電機(jī)驅(qū)動(dòng)模塊53.3.1 L298N說(shuō)明53.3.2 L298N連接圖53.4循跡模塊53.4.1尋線功能53.4.2尋線傳感器與實(shí)驗(yàn)連接圖53.5避碰模塊73.5.1 超聲波模塊73.5.2 實(shí)驗(yàn)連接圖73.6紅外模塊83.6.1紅外模塊說(shuō)明83.6.2實(shí)物圖8四、模塊軟件設(shè)計(jì)84.1循跡模塊程

2、序84.2 紅外模塊程序104.3避碰模塊程序11五、綜合設(shè)計(jì)與調(diào)試115.1流程圖115.2軟件設(shè)計(jì)12六、總結(jié)146.1遇到問(wèn)題及解決辦法141、 硬件問(wèn)題142、 軟件問(wèn)題156.2個(gè)人感悟15一 、任務(wù)設(shè)計(jì)及要求 利用Arduino設(shè)計(jì)智能小車(烏龜)其功能: 1、實(shí)現(xiàn)循跡(利用TCRT5000 紅外對(duì)管); 2、避碰功能(利用超聲波); 3、紅外遙控功能; 4、綜合以上功能實(shí)現(xiàn)自動(dòng)循跡、避障、紅外控制的智能小車; 二、 Arduino 2.1 Arduino簡(jiǎn)介ARDUINO 智能小烏龜是一款單片機(jī)學(xué)習(xí)應(yīng)用開(kāi)發(fā)系統(tǒng),以 arduino 單片機(jī)系列 atmega-328為核心.完成尋線

3、,避障,紅外遙控和藍(lán)牙遙控的功能,.套件包含了大量的趣味程序,并可擴(kuò)展外置的電路模塊,從而增加小車的使用功能.旨在讓使用者在學(xué)習(xí) ARDUINO 單片機(jī)時(shí)能脫離枯燥的理論知識(shí),在玩樂(lè)中獲取單片機(jī)系統(tǒng)開(kāi)發(fā)的能力。 2.2參數(shù)說(shuō)明 1.電機(jī)參數(shù):電壓范圍:1.5-12V,電機(jī)軸長(zhǎng)10mm,轉(zhuǎn)速 100rpm/min. 2.控制電機(jī)選用L298N驅(qū)動(dòng)模塊,與單片機(jī)真正隔離. 3.三組尋線模塊,檢測(cè)黑白線,精度更高,也可用與防跌落控制. 4.紅外遙控通信模塊,組成智能小車遙控系統(tǒng). 5.超聲波模塊,小車避障系統(tǒng). 5.藍(lán)牙無(wú)線模塊,可以和手機(jī)藍(lán)牙配對(duì)遙控機(jī)器人. 6.可接入外部712V的電壓。并能搭載

4、多款傳感器模塊,根據(jù)您的想象力實(shí)現(xiàn)各種功能.三、 硬件設(shè)計(jì)3.1所需硬件清單1. 金屬減速電機(jī) 2 個(gè);2.優(yōu)質(zhì)輪胎 2 個(gè);3.電機(jī)固定件 2 個(gè);4 、牛眼萬(wàn)向輪;5.機(jī)器人底盤 2 片;6.L298N 電機(jī)驅(qū)動(dòng)板 1 個(gè);7.ARDUINO UNO328 控制板 1 個(gè);8.ARDUINO 傳感器擴(kuò)展板 1 個(gè);9.云臺(tái) 1 個(gè);10.舵機(jī) 1 個(gè);11.超聲波模塊 1 個(gè);12.三組尋線模塊;13.紅外接收傳感器;14.單片機(jī)遙控器;15.2000MA 18650 充電電池 2 節(jié);16.18650 電池盒一個(gè);17.18650 充電器一個(gè)。3.2硬件設(shè)計(jì)說(shuō)明 結(jié)合實(shí)際、根據(jù)需要,將系

5、統(tǒng)分為四個(gè)模塊,即電機(jī)驅(qū)動(dòng)模塊,循跡模塊,避碰模塊,紅外模塊,分開(kāi)做,自后將其綜合起來(lái)。3.3電機(jī)驅(qū)動(dòng)模塊 3.3.1 L298N說(shuō)明 L298N是一個(gè)驅(qū)動(dòng)模塊,就是單片機(jī)的驅(qū)動(dòng)電流太小無(wú)法驅(qū)動(dòng)電動(dòng)機(jī),因此L298N其起到一個(gè)放大器作用。通過(guò)控制L298N I1 I2 I3 I4接口,控制電機(jī)的正轉(zhuǎn),反轉(zhuǎn),轉(zhuǎn)彎和停止。 3.3.2 L298N連接圖 如下圖所示:3.4循跡模塊 3.4.1尋線功能 使小車沿著黑線走,根據(jù)黑線的位置選著行走的狀態(tài)。 3.4.2尋線傳感器與實(shí)驗(yàn)連接圖 TCRT5000紅外對(duì)管的工作原理是利用紅外線對(duì)顏色的反射率不一樣,將 反射信號(hào)的強(qiáng)弱轉(zhuǎn)化成電流信號(hào)。黑白尋跡模塊在

6、檢測(cè)到黑色高電平有效,檢測(cè)到白色是為 低電平有效,檢測(cè)高度為 03cm。使用方法1.傳感器接口有3根排針,分別是GND ,VCC,OUT。VCC和GND為供電端,OUT是信 號(hào)輸出端。 2.檢測(cè)到物體,信號(hào)端輸出低電平;未檢測(cè)到物體,信號(hào)端輸出高電平。 3.主要判斷信號(hào)輸出端是0或者1,就能判斷物體是否存在。 性能參數(shù): 1:檢測(cè)距離,檢測(cè)白紙時(shí)約為2厘米。視顏色的不同距離有所不同,白色最遠(yuǎn)。 2.供電電壓:2.5V12V,不要超過(guò)12V。(注意:最好用低電壓供電,供電電壓太高傳感器的壽命會(huì)變短。5V供電為佳。) 3.工作電流,5V時(shí)1820ma。經(jīng)大量測(cè)試,傳感器硬件設(shè)置為1820ma工作電

7、流時(shí)性能最 佳,主要表現(xiàn)在抗干擾能力上。4.檢測(cè)到物體,信號(hào)端輸出低電平;未檢測(cè)到物體,信號(hào)端輸出高電平。 5.傳感器輸出TTL電平,能直接與3.3V或者5V單片機(jī)IO口相連。 黑線或者白線檢測(cè)原理 1.利用黑色對(duì)光線的反射率小這個(gè)特點(diǎn),當(dāng)平面的顏色不是黑色時(shí),傳感器發(fā)射出去的紅 外光被大部分反射回來(lái)。于是傳感器輸出低電平0。 2.當(dāng)平面有一黑線,傳感器在黑線上方時(shí),因黑色的反射能力很弱,反射回來(lái)的紅外光很 少,達(dá)不到傳感器動(dòng)作的水平,所以傳感器還輸出1。 3.我們只要用單片機(jī)判斷傳感器的輸出端是0或者是1,就能檢測(cè)黑線。 4.檢測(cè)白線的原理和檢測(cè)黑線的原理一樣,檢測(cè)白線時(shí),白線周邊的顏色也要

8、比較接近黑 色,然后調(diào)節(jié)紅外傳感器上面的可調(diào)電阻,將靈敏度調(diào)低,一直調(diào)到剛好周邊的顏色檢測(cè) 不到為止,那樣就能檢測(cè)白線了。連接參考圖如下:3.5避碰模塊 3.5.1 超聲波模塊超聲波智能避障實(shí)現(xiàn)方便、計(jì)算簡(jiǎn)單、易于做到實(shí)時(shí)控制,并且在測(cè)量精度方面能達(dá)到實(shí)用的要求,因此成為常用的避障方法。 3.5.2 實(shí)驗(yàn)連接圖3.6紅外模塊 3.6.1紅外模塊說(shuō)明實(shí)驗(yàn)前須知:1.先把 IRremote 函式庫(kù)資料夾放進(jìn) Arduino libraries 目錄底下2.開(kāi)啟 IrReceive.pde 測(cè)得自 己的紅外線遙控的碼(在 Serial Monitor 可顯示 IRcode) , 再將IRcode 記

9、錄下來(lái), 然后到程式里面修改成自 己的紅外線碼即可。3.6.2實(shí)物圖四、模塊軟件設(shè)計(jì)4.1循跡模塊程序第 9 頁(yè) 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; /左感測(cè)器輸入腳const int SensorMiddle= 4 ; /中感測(cè)器輸入腳const int SensorRight =

10、3; /右感測(cè)器輸入腳int SL; /左感測(cè)器狀態(tài)int SM; /中感測(cè)器狀態(tài)int SR; /右感測(cè)器狀態(tài)void advance(int a) / 前進(jìn) digitalWrite(MotorRight1,LOW); digitalWrite(MotorRight2,HIGH); digitalWrite(MotorLeft1,LOW); digitalWrite(MotorLeft2,HIGH); delay(a*50); void left(int i) / 左轉(zhuǎn) digitalWrite(MotorRight1,LOW); digitalWrite(MotorRight2,HIGH

11、); digitalWrite(MotorLeft1,LOW); digitalWrite(MotorLeft2,LOW); delay(i*30); void right(int c) / 右轉(zhuǎn) 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) /右大轉(zhuǎn) digitalWrite(MotorRight1,L

13、OW); digitalWrite(MotorRight2,HIGH); digitalWrite(MotorLeft1,HIGH); digitalWrite(MotorLeft2,LOW); delay(x * 25); void le(int h) /左打轉(zhuǎn) 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); /左感測(cè)器 pinMode(SensorMiddle, INPUT);/中感測(cè)器 pinMo

15、de(SensorRight, INPUT); /右感測(cè)器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 / 直進(jìn) 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 頁(yè)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); /測(cè)量 detection(); /測(cè)量角度 if(directionn = 2) /假如 directionn(方向) = 2(倒車) back(5

23、); / 倒退 stopp(); /停止 while(1); if(directionn = 8) advance(2); 五、綜合設(shè)計(jì)與調(diào)試5.1流程圖 開(kāi)始 紅外信號(hào) 障礙物 路徑1 路徑2 終點(diǎn) 終點(diǎn) 開(kāi)始5.2軟件設(shè)計(jì) #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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論