# 第十二週週記 ###### tags: `創新原型實作` `第十二週` ## 個人作業 ### 紅外線搖控馬達-利用紅外線遙控馬達正轉、反轉、暫停 #### 接線方面 馬達驅動板:A1-B接D9、A1-A接D8、GND、VCC 紅外線接收器:OUTPUT接紅外線PIN腳D2或 GND VCC關於數位訊號區跟類比訊號區,[數位及類比訊號](https://taiwanteacher.pixnet.net/blog/post/1815217-arduino-%E9%A1%9E%E6%AF%94analog%2C%E6%95%B8%E4%BD%8Ddigital%E6%8E%A5%E8%85%B3%E4%BB%8B%E7%B4%B9_taiwan-teache)這邊有簡單的介紹兩者間的差別,數位概念如同0跟1、有或沒有一樣,類比訊訊號則是可高可低、可大可小(舉例如上禮拜光敏電阻即為類比,從環境中得到光照度數值)。 這周作業在實作上有點難度,首先是接線上,我們這組非常可惜無法跟少林足球的汽車維修員一樣隨身攜帶板手跟螺絲起子(上次忘記把課堂上的螺絲起子拿回來),所以只能憑蠻力跟筆刀連接驅動版到馬達上,基本上有大致接完線,但因為無法拴緊馬達跟驅動板,只能跟禮拜一一樣,聽馬達有沒有聲音。  #### 程式方面 程式主要是由沁柔的電腦操作(我的電腦17吋太大,光插上板子就佔滿整個桌面),根據組員分析加上從 [source code](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/private/IRTimer.hpp) 發現是因為裡面按照不同的板子分配 timer,但是沒有寫到我們用的。因為對板子的硬體架構不太確定,便不確定怎麼改,就沒有試了。 ```cpp= #include <IRremote.h> //the numbers "should" be the outputs from ir remote control #define START 10000 #define STOP 20000 #define BACKWARD 30000 //control int irPin = (int)7; IRrecv irrecv_irPin(irPin); decode_results results_irPin; //motor int motorPin = (int)8; int motorSpeed = (int)9; int sspeed = (int)(150); int dir = 0; //direction void setup() { //motor init pinMode(motorPin, OUTPUT); pinMode(motorSpeed, OUTPUT) //IR init irrecv_irPin.enableIRIn(); Serial.begin(9600); } void low_in() { digitalWrite(motorPin, LOW); analogWrite(motorSpeed, sspeed); } void high_in() { digitalWrite(motorPin, HIGH); analogWrite(motorSpeed, sspeed); } void stop_in() { digitalWrite(motorPin, LOW); analogWrite(motorSpeed, 0); } void loop() { if (irrecv_irPin.decode(&reself_irPin)) { Serial.println(results_irPin.value); if (results_irPin.value == START) low_in(); else if (results_irPin.value == STOP) stop_in(); else if (results_irPin.value == BACKWARD) { dir = (dir+1)%2; if (dir) high_in(); else low_in(); } delay(1000); } irrecv_irPin.resume(); } ``` #### 相關資料: https://blog.jmaker.com.tw/irremoterecv/ https://a091234765.pixnet.net/blog/post/399995512 ### 為什麼使用digitalRead得到的值會是0-1023之間 概念上就是讀取類比訊號並轉為數位訊號,實行上Arduino 沒有真正的類比輸出(analog output),只有用 PWM 技術模擬出的類比輸出,PWN即為不斷的開與關模擬出0伏特到5伏特的電壓, 所以為模擬輸出,我們則稱類比輸出。通常在讀取0-5V電壓轉譯為數位訊號時,輸出電壓數值為(0-1023)及PWM數值(0~255),而0到1023相當於1024,也就是2的十次方,由10個(0、1或開關)的一串數字組合出來的結果。 #### 相關資料 https://frank1025.pixnet.net/blog/post/339436976-%5Barduino%5D002-arduino%E7%AF%84%E4%BE%8B%E7%A8%8B%E5%BC%8F-%E9%A1%9E%E6%AF%94%E9%9B%BB%E5%A3%93%E8%BD%89%E6%95%B8%E4%BD%8D%E8%A8%8A%E8%99%9F https://iottalk.vip/static/arduino/index.html ## 本周實作心得 為解決上次發生的跳線無法用問題,我們這組這次先檢測跳線是否能用之後才開始操作,並且在操作過程中還發生馬達有聲音但沒有運轉的情況,仔細檢查才發現是與馬達驅動板間沒接好,重新鎖好螺絲後運行正常,這次主要由我負責接線、沁柔負責程式,最後很順利有完成但忘記要拍照留個紀念,到了小組諮詢時間,我們也在思考如何讓自己的期末專案能夠更有創意,目前主要是想先完成手機鬧鐘驅動、眼部發光、嘴部開合後再加上能夠遇人迴避、擴音的功能。
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up