# 7.Infrared remote control

BiBoard ติดตั้งเซ็นเซอร์อินฟราเรดซึ่งเชื่อมต่อกับพินที่ 23 การใช้อินฟราเรดนั้นเหมือนกับที่ใช้ใน Arduino UNO ที่ใช้ AVR

ก่อนอื่นให้ดาวน์โหลดไลบรารี IRremote เวอร์ชัน 2.6.1 คุณต้องเลือกเวอร์ชัน 2.6.1 ด้วยตนเอง เนื่องจากโค้ดที่เกี่ยวข้องกับอินฟราเรดมีการเปลี่ยนแปลงในเวอร์ชันหลังๆ หากคุณใช้เวอร์ชัน 3.X คำสั่งจะไม่ถูกแปล เพื่อให้เข้ากันได้กับผลิตภัณฑ์ก่อนหน้าของเรา เราตัดสินใจใช้เวอร์ชัน 2.6.1 หลังจากการทดสอบ

![](/files/-McDQ_3-NNjGtnIW3heF)

เมื่อใช้ NyBoard เพื่อให้แน่ใจว่าสามารถคอมไพล์โค้ดได้อย่างราบรื่น เราจำเป็นต้องลบโค้ดที่ไม่จำเป็นในไลบรารี IRremote นั่นคือ ลบตัวเข้ารหัส/ตัวถอดรหัสที่เราไม่ได้ใช้ และเก็บเฉพาะ NEC\_DECODER ซึ่งก็คือ ตัวถอดรหัสสัญญาณ 38KHz ในรูปแบบ NEC

เนื่องจากความจุของหน่วยความจำแฟลชของ BiBoard นั้น “มหาศาล” เราจึงไม่จำเป็นต้องลบโค้ดที่ไม่จำเป็นในไลบรารี IRremote

![23% of flash is used on UNO](/files/-MchmuTJ0cgZ5bVpx635)

![Only 4% of flash is used on BiBoard](/files/-Mchn9LNPmtnHIslGemM)

สุดท้ายมีการแนบตัวอย่างซึ่งรับสัญญาณอินฟราเรดและพิมพ์ผ่านพอร์ตซีเรียล คุณยังสามารถใช้การตัวอย่าง อย่างเป็นทางการสำหรับการทดสอบ

```cpp
#include <Arduino.h>
#include <IRremote.h>

int RECV_PIN = 23;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup() {
  Serial.begin(115200);
  irrecv.enableIRIn();
  Serial.println("IR Receiver ready");
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    Serial.print(" - ");
    irrecv.resume(); // Receive the next value
  }
  delay(300);
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.petoi.com/thai/biboard/demo-applications/7.infrared-remote-control.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
