Suchcode

Lesson 21/31: Using Infrared Remote Control with Arduino | SunFounder Robojax

Lesson 21/31: Using Infrared Remote Control with Arduino | SunFounder Robojax

Introduction

In this lesson, we explore the fascinating world of infrared (IR) communication by building a project that decodes signals from a standard remote control using an Arduino. This project allows you to detect which button is pressed on an IR remote and trigger actions accordingly, such as turning on a buzzer. The ability to interface with IR remotes opens up a wide range of practical applications, from simple home automation to custom control systems.

infrare_remote
IR_receiver_pins

Here are some inspiring ideas for what you can build with this technology:

  • Universal Remote Replacement: Create a custom remote for your TV, audio system, or other IR-controlled devices.
  • Home Automation: Control lights, fans, or other appliances by pressing a button on a standard remote.
  • Interactive Projects: Build a security system that triggers an alarm when a specific button is pressed.
  • Robotics Control: Use an IR remote to wirelessly control a robot's movement and actions.
  • Accessibility Aids: Develop a simple, large-button remote for individuals with limited mobility.

Hardware & Components

This project is built around a few simple components, all of which are typically included in starter kits like the SunFounder 3-in-1 kit. You will need:

  • An Arduino board (e.g., Uno)
  • An IR receiver module (e.g., TSOP38238 or similar)
  • A standard IR remote control (with a CR2025 battery)
  • A passive buzzer
  • Jumper wires and a breadboard

Wiring Guide

ir_remote_control_wiring

Here is the simple wiring diagram for this project. The IR receiver is the key component. When you look at the receiver's curved surface, the pin layout is as follows:

  • Right Pin: Connect to the 5V pin on the Arduino.
  • Middle Pin: Connect to the GND pin on the Arduino.
  • Left Pin (Signal): Connect to digital pin 11 on the Arduino.

Additionally, for the action part of the project, connect the positive (longer) lead of the buzzer to digital pin 2 and the other lead to GND.

Code Explanation

This project relies on the IRremote library to handle the complex task of decoding the infrared signals. The code is structured to first learn the specific codes from your remote and then use them to trigger actions. Let's break down the user-configurable parts.

First, we define the pin to which the IR receiver's signal wire is connected. This is a crucial configuration that you must match with your physical wiring.

const int IR_RECEIVE_PIN = 11;  // Define the pin number for the IR Sensor

In the setup() function, the IR receiver is initialized using the pin we just defined. This tells the library to start listening for signals on that pin.

IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);  // Start the IR receiver

The core of the action-taking logic is in the loop(). The code checks if a key has been pressed and decodes it. The decodeKeyValue() function is a custom function that translates the raw hexadecimal code from the remote into a human-readable string like "POWER" or "MUTE". This is the part you will modify to match your specific remote. The example code defines a buzzerPin and turns it on only when the "POWER" button is pressed.

const int buzzerPin = 2; // Define the pin for the buzzer
// ... inside loop()
if (decodedValue == "POWER") {
    digitalWrite(buzzerPin, HIGH); // Turn the buzzer on
} else {
    digitalWrite(buzzerPin, LOW); // Turn the buzzer off
}

How to Use: The decodeKeyValue() function is the key to customizing this project. To use it with your own remote, you must first run the code with the Serial Monitor open. Press each button on your remote and note the hexadecimal value printed for each. Then, update the switch statement in the decodeKeyValue() function to map those values to meaningful names. You can then use these names in your if statements to trigger different actions, just as the example does for the "POWER" button.

Live Project & Demonstration

Once the code is uploaded, open the Serial Monitor at a baud rate of 9600. Point your remote at the IR receiver and press a button. The Serial Monitor will display the corresponding key name (e.g., "POWER", "MUTE"). To see the action in effect, press the "POWER" button. You will hear the buzzer turn on. Pressing any other button, such as "MUTE", will turn the buzzer off. This demonstrates a simple but powerful concept: using a remote control to trigger digital outputs on your Arduino.

Chapters

  • [00:00] Introduction to Infrared Remote Control with Arduino
  • [01:25] Overview of the IR Receiver and Transmitter
  • [02:24] Understanding the IR Receiver Module and Wiring
  • [03:31] Installing the IRremote Library
  • [04:22] Opening and Explaining the Decoding Code
  • [07:29] Uploading Code and Testing Remote Keys
  • [08:41] Adding an Action: Controlling a Buzzer
  • [10:37] Preview of Upcoming IR Projects

Bilder

IR_receiver_pins
IR_receiver_pins
infrare_remote
infrare_remote
ir_remote_control_wiring
ir_remote_control_wiring
904-Lesson 21/31: Arduino code fpor decoding Infrared from remote signal
Sprache: C++
This code has not been parsed yet. Please return to the admin panel to parse it.

Dinge, die Sie vielleicht brauchen

Ressourcen & Referenzen

Noch keine Ressourcen vorhanden.

Dateien📁

Arduino-Bibliotheken (zip)