0%

IR Remote

1. Intro

IR use light to transmit data

image-20221219213927203

Light used is infrared

  • inexpensive
  • subject to interference
  • Sunlight would interference the IR

Data are modulated in 38K Hz (usually)

image-20221219214112137

Each button sends a unique code

2. Test

2.1. Sender

How to see if the controller works?

  • Human eye can’t see the light
  • Camera can see it (phone)

2.2. Receiver

image-20221219221609056

3. Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <boarddefs.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
#include <IRremote.h>

int RECV_PIN = 11; // the pin where you connect the output pin of IR sensor
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop()
{
if (irrecv.decode(&results))// Returns 0 if no data ready, 1 if data ready.
{
//int value = results.value; ;// Results of decoding are stored in result.value
Serial.println(" ");
Serial.print("Code: ");
Serial.println(results.value,HEX); //prints the value a a button press
Serial.println(" ");
irrecv.resume(); // Restart the ISR state machine and Receive the next value
}
}