Infrared Remote Control Experiment

Infrared Remote Control Experiment

Introduction

In this experiment, you will use an infrared (IR) remote control and receiver to interact with an Arduino. The Arduino will decode the signals sent by the remote and perform specific actions, such as turning an LED on or off.

Components Needed

Circuit Setup

  1. Connect the IR receiver module:
    • GND pin to Arduino GND
    • VCC pin to Arduino 5V
    • OUT pin to Arduino digital pin 2
  2. Connect the LED:
    • Long leg (+) to Arduino digital pin 9 through a 330Ω resistor
    • Short leg (-) to GND

Code for Infrared Remote Control

Upload the following code to your Arduino to decode IR signals and control the LED:

// Include the IRremote library
#include 

const int RECV_PIN = 2; // Pin connected to IR receiver
const int LED_PIN = 9;  // Pin connected to LED
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
    Serial.begin(9600);
    irrecv.enableIRIn(); // Start the IR receiver
    pinMode(LED_PIN, OUTPUT);
    digitalWrite(LED_PIN, LOW);
    Serial.println("Ready to receive IR signals");
}

void loop() {
    if (irrecv.decode(&results)) {
        Serial.println(results.value, HEX); // Print the decoded value in hexadecimal format

        // Check the received value and control the LED
        switch (results.value) {
            case 0xFFA25D: // Replace with your remote's ON button code
                digitalWrite(LED_PIN, HIGH); // Turn LED on
                Serial.println("LED ON");
                break;

            case 0xFF629D: // Replace with your remote's OFF button code
                digitalWrite(LED_PIN, LOW); // Turn LED off
                Serial.println("LED OFF");
                break;

            default:
                Serial.println("Unknown signal");
        }
        irrecv.resume(); // Receive the next signal
    }
}
            

Explanation

The code uses the IRremote library to decode the signals sent by the IR remote. Here's how it works:

Troubleshooting