IR Remote Control

Mr. Seng Theara

Learning Objective

By the end of the lesson, student will be able to:

  • Understand how a joystick works electrically

  • Explain pull-up button logic

  • Read analog and digital signals

  • Map controller inputs to robot movements

  • Design basic control logic for robots

Learning Objective

By the end of the lesson, student will be able to:

  • Understand how IR remote communication works

  • Identify IR remote hardware components

  • Interface an IR receiver with ESP32

  • Decode IR remote button values

  • Control LEDs, motors, or robots using IR remote

What is an IR Remote?

4 Buttons

Joystick

What is an IR Remote?

An IR (Infrared) remote control is a device that uses infrared light to transmit signals to control electronic devices. It uses an IR Transmitter and an IR LED to send IR signals to an IR Receiver:

Infrared Light

Infrared light  is part of the electromagnetic spectrum, just like visible light, radio waves, and microwaves. However, it has a longer wavelength than visible light, making it invisible to the human eye.

Infrared light is often used for communication purposes due to its low interference with other electronic devices.

IR Transmitter

The IR transmitter is hidden in the remote control itself. It creates signals in a specific pattern to communicate with the IR receiver. The signals are converted to IR light with an IR LED. If you look closely you usually can see a clear LED at the front of the remote. That is the IR LED that emits the IR signal.

IR LED

The most common protocol used for IR communication is the NEC (Nihon Electronics Corporation) protocol.

The NEC protocol defines a standard way of encoding and decoding data transmitted via infrared signals. This protocol is commonly used in consumer electronics, and The NEC protocol uses a carrier frequency of 38 kHz, which means the infrared signal is modulated at this frequency

IR Receiver

The IR receiver is the component that receives the infrared signals from the remote control. It consists of a photodiode that detects the incoming infrared light and converts it into electrical signals

In order to receive and decode the NEC protocol, the IR receiver needs to be connected to a microcontroller capable of reading and interpreting the incoming signals. This allows the microcontroller to understand the button presses and perform the desired actions

IR Receiver Pin

void setup() {
  pinMode(16, INPUT);
  Serial.begin(115200);
}

void loop() {
  int button_up = digitalRead(16);
  if (button_up == LOW){
    Serial.println("Button Up is pressed");
  }else{
    Serial.println("Button Up isn't pressed");
  }

  delay(200);
}

IR Receiver

PIN 36

Library install

Declare pin 16 as INPUT because the esp32 read from the button

Install the IRremote Library

Coding

Using baudrate of 115200

#include <IRrecv.h>
#include <IRremoteESP8266.h>
#include <IRutils.h>

const uint16_t RECV_PIN = 36;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  Serial.begin(115200);
  irrecv.enableIRIn();  // Start receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(resultToHumanReadableBasic(&results));
    irrecv.resume();
  }
}

Include the library of IR

Using pin 36 from IR to esp32

Create decode result object from NEC Protocol

Checks if a complete IR signal has been received

if Successful store the data in the results

Print the result in Human Readable Text

Clear the current ir data and wait for the next IR button

Testing with IR button

Turn led on and off from IR Button

#include <IRrecv.h>
#include <IRremoteESP8266.h>
#include <IRutils.h>

const uint16_t RECV_PIN = 36;   
const uint8_t LED_PIN = 12;      // LED pin

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  Serial.begin(115200);

  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);   

  irrecv.enableIRIn();         
}

void loop() {
  if (irrecv.decode(&results)) {

    uint32_t irCode = results.value;   // Get IR code
    Serial.println(irCode, HEX);       // Print code in HEX

    if (irCode == 0xFFA25D) {
      digitalWrite(LED_PIN, HIGH);     // LED ON
      Serial.println("LED ON");
    }
    else if (irCode == 0xFF629D) {
      digitalWrite(LED_PIN, LOW);      // LED OFF
      Serial.println("LED OFF");
    }

    irrecv.resume(); 
  }
}