• 沒有找到結果。

Lecture 11/14 – IR 紅外線

N/A
N/A
Protected

Academic year: 2022

Share "Lecture 11/14 – IR 紅外線"

Copied!
10
0
0

加載中.... (立即查看全文)

全文

(1)

Lecture 11/14 – IR 紅外線

FC Tien, YP Liu

Dept. IE&M, Taipei Tech

(2)

紅外線 Infrared

• 紅外線(Infrared, IR),波長介於 微波與可見光之間的電磁波,其波 長在760奈米(nm)至1毫米

(mm)之間,是波長比紅光長的 非可見光。

(3)

紅外線 LED

發射 接收模組 發射 接收 發射 接收

(4)

實驗 – 紅外線物體偵測

(5)

實驗 – 紅外線物體偵測程式碼

void setup() {

Serial.begin(9600);

pinMode(13, OUTPUT);

pinMode(3, OUTPUT);

pinMode(11, INPUT);

}

int irDetect(int irLedPin, int irReceiverPin, long frequency) { //tone(pin, frequency, duration)

tone(irLedPin, frequency, 20);

delay(1);

int ir = digitalRead(irReceiverPin);

return ir;

}

void loop() {

int ir = irDetect(3, 11, 38000);

if (ir == 0)

digitalWrite(13, 1);

elsedigitalWrite(13, 0);

Serial.println(ir);

delay(100);

}

(6)

實驗 – 紅外線物體偵測實際波形

(7)

紅外線資料傳遞

 避免環境中紅外線的影響,

編碼方式 38.5KHz

Ex. NEC Protocol

(8)

IRremote Arduino Library

https://github.com/z3t0/Arduino-IRremote

Make sure to delete Arduino_Root/libraries/RobotIRremote.

Where Arduino_Root refers to the install directory of Arduino.

Mac: Applications/Arduino (right mouse click -->show package contents) /Contents/Java/libraries/RobotIRremote

Windows: C:\Program Files (x86)\Arduino\libraries\RobotIRremote

(9)

#include <IRremote.h>

#include <IRremoteInt.h>

// 使用數位腳位11接收紅外線訊號 int RECV_PIN = 11;

// 初始化紅外線訊號輸入 IRrecv irrecv(RECV_PIN);

// 儲存訊號的結構 decode_results results;

void setup() {

Serial.begin(9600);

// 設為true的話,當收到訊號時,腳位13的LED便會閃爍 irrecv.blink13(true);

// 啟動接收

irrecv.enableIRIn();

}

實驗 – 紅外線資料傳遞 Rx

void loop() {

if (irrecv.decode(&results)) { // 接收紅外線訊號並解碼

Serial.print(results.value, HEX);

Serial.print(" , ");

Serial.print(results.bits);

Serial.print(" bits, Type : ");

Serial.println(results.decode_type);

irrecv.resume(); // 準備接收下一個訊號 } }

(10)

實驗 – 紅外線資料傳遞 Rx

#include <IRremote.h>

#include <IRremoteInt.h>

IRsend irsend; // IRRemote限定使用數位腳位3 void setup() {

Serial.begin(9600);

}

case '3':

v = 0x00FD40BF;

break;

case '4':

v = 0x77E1B050;

break;

case '5':

v = 0x77E1E050;

break;

case '6':

v = 0x77E11050;

break;

} void loop() {

int d;

if ( (d = Serial.read()) != -1) { // 讀取序列埠 unsigned long v = 0x0;

// 根據讀取到的資料,

// 換成代表六個按鍵的紅外線編碼 switch(d){

case '1':

v = 0x00FD00FF;

break;

case '2':

v = 0x00FD807F;

break;

case '3':

if (v != 0x0){

Serial.print("read ");

Serial.print(d);

Serial.print(", IR send ");

Serial.println(v, HEX);

irsend.sendNEC(v, 32); // 輸出紅外線訊號 //irsend.sendRC5(v, 32);

} } }

void sendNEC(unsigned long data, int nbits);

void sendSony(unsigned long data, int nbits);

void sendRaw(unsigned int buf[], int len, int hz);

void sendRC5(unsigned long data, int nbits);

void sendRC6(unsigned long data, int nbits);

void sendDISH(unsigned long data, int nbits);

void sendSharp(unsigned long data, int nbits);

void sendPanasonic(unsigned int address, unsigned long data);

void sendJVC(unsigned long data, int nbits, int repeat);

其他支援的編碼方式

參考文獻

相關文件

jar JAR file of our program (for quick start) lib Directory to put required libraries yahoo Data files for content features html Data files for social features1.

– Classes found in the package Classes found in the package java.lang java lang are imported automatically are imported automatically  into every Java program.

Asymptotic Analysis of a Path-Following Barrier Method for Linearly Constrained Convex Problems.

發射電路:為利用 PT2248 (U1,Infrared Remote Control Transmitter)及其週 邊元件、紅外線二極體(D4,IR Diode)與按鍵,共同組合成一紅外線發

Listen carefully and choose the best answers for Questions 1–5.. How many times has Candy been to Hong

Price: $120 for children; $240 for adults Venue: Hong Kong Cultural Centre As it is the first time for the Royal Russian Circus to step on to the Hong Kong stages, the director

Read it carefully, then choose the best answers for Questions 23-27 and complete Question 28.. Fake Shark’s

Comprehensively covered by Zentralblatt MAJH, Mathematical Review and Current Contents 14(3) 249-398 (2002) April 2002 Printed on