Skip to content

Technik Blog

Programmieren | Arduino | ESP32 | MicroPython | Python | Raspberry Pi | Raspberry Pi Pico

Menu
  • About me
  • Contact
  • Deutsch
  • English
Menu

Arduino Lesson #4 – programming IR Remote control

Posted on 14. October 202210. March 2024 by Stefan Draeger

In this new post at my technic blog, I like to show you how to code an IR Remote control at Arduino UNO R3.

Arduino Lesson #4 - programming IR Remote control
Arduino Lesson #4 – programming IR Remote control

In my last post Arduino Lesson #3 – control tiny servo motor SG90 I show you how to code and control a servo motor. In this post, I want to control this servo motor with an IR remote control.

  • Required components
  • IR Remote control module
    • Connect an IR Remote control module at an Arduino UNO
  • Build your own tiny IR Receiver module at Breadboard
  • Programming an IR Remote control Module
    • Prevent message “The function decode(&results)) is deprecated and may not work as expected! Just use decode() without a parameter and IrReceiver.decodedIRData.”

Required components

If you want to rebuild the following samples, you need:

  • an Arduino UNO R3*,
  • USB-Type-B datacable* (for printer or scanner),
  • IR Receiver module*,
  • some LEDs* with 220 Ohm resistor*,
  • a servo motor type SG90*,
  • some Breadboardwires*, male – male, 10 cm,
  • a 400 pin Breadboard*

Note from me: The links marked with an asterisk (*) are affiliate links. If you make a purchase through these links, I will receive a small commission to help support this blog. The price for you remains unchanged. Thank you for your support!

required parts for samples with IR Remote control
required parts for samples with IR Remote control

You don’t have to buy an IR remote control, for this post you can also use your remote control from your TV or satellite receiver. This will save some money for other upcoming lessons.

IR Remote control module

The easiest way to read signals from an IR Remote control is to use a module. This module has 3 pins.

  • – > GND
  • middle > 5V
  • S > data line
IR Receiver module (frontside)
IR Receiver module (frontside)
IR Receiver module (backside)
IR Receiver module (backside)

Connect an IR Remote control module at an Arduino UNO

The connection to an Arduino UNO is very simple, you only have to connect three wires. The pin with symbol minus goes to GND, the middle pin to 5V and the pin with “S” have to connect to a digital pin.

connect IR Remote module to Arduino UNO
connect IR Remote module to Arduino UNO

Build your own tiny IR Receiver module at Breadboard

An IR Remote control module can easily build with the following parts:

  • IR Receiver Diode,
  • 220 Ohm Resistor,
  • tiny, red, 3 mm LED,
  • a 400 Pin Breadboard,
  • some Breadboardwires or Jumperwires
tiny circuit IR LED & 3mm LED at Arduino Nano
tiny circuit IR LED & 3mm LED at Arduino Nano
easy IR Receiver with IR LED and LED at Arduino Nano
easy IR Receiver with IR LED and LED at Arduino Nano

Programming an IR Remote control Module

The next following samples will work with the ready to use module and the DIY IR Receiver circuit.

First, you need a library to read the IR receiver led signals, in your Arduino IDE is such a library pre-installed. So you don’t have to install this.

Here is a small sample of how to read and handle such signals.

//library to handle IR Receiver Diode
#include <IRremote.h>

//tiny, 3 mm Status LED at digital pin 13
#define statusLed 13
//IR Receiver Diode connected at digital pin 8
#define irReceiverDiode 8

//some connected LEDs
#define ledGreen 3
#define ledYellow 4
#define ledRed 5
#define ledBlue 6

//create object with attached
IRrecv irrecv(irReceiverDiode);
//field for results
decode_results results;

void setup() {
  //define pins from LEDs as OUTPUT
  pinMode(ledGreen, OUTPUT);
  pinMode(ledYellow, OUTPUT);
  pinMode(ledRed, OUTPUT);
  pinMode(ledBlue, OUTPUT);
  pinMode(statusLed, OUTPUT);

  //define pin from IR Receiver Diode as INPUT
  pinMode(irReceiverDiode, INPUT);

  //begin communication
  irrecv.enableIRIn();
  //begin serial communication with 9600 baud
  Serial.begin(9600);
}

void loop() {
  //if successful receive some data, then ...
  if (irrecv.decode(&results)) {
    //store data in field value
    int value = results.value;
    //consume the data and clear
    irrecv.resume();
    //print the value to the serial interface
    Serial.println(value);
    //activate status LED
    digitalWrite(statusLed, HIGH);
    //tiny brake to light up the LED
    delay(75);
    //deactive status LED
    digitalWrite(statusLed, LOW);
  }
}

When you run this sample and press buttons on your IR remote control, the value from your key will write to the serial interface.

Next, you can use this numbers in a Switch-Case construct to control some LEDs.

//fields to store status of LEDs
bool ledGreenActive = false;
bool ledYellowActive = false;
bool ledRedActive = false;
bool ledBlueActive = false;

void loop() {
  //if successful receive some data, then ...
  if (irrecv.decode(&results)) {
  ...
     //handle received data...
     switch (value) {
        case 12495: ledGreenActive = !ledGreenActive; break;
        case 6375: ledYellowActive = !ledYellowActive; break;
        case 31365: ledRedActive = !ledRedActive; break;
        case 4335: ledBlueActive = !ledBlueActive; break;
     }

     resetLEDs();
   ....
}

//set actual states to LEDS
void resetLEDs() {
  digitalWrite(ledGreen, ledGreenActive);
  digitalWrite(ledYellow, ledYellowActive);
  digitalWrite(ledRed, ledRedActive);
  digitalWrite(ledBlue, ledBlueActive);
}

Here you get the complete Code to download.

IR Receiver Diode – control LEDsHerunterladen

Prevent message “The function decode(&results)) is deprecated and may not work as expected! Just use decode() without a parameter and IrReceiver.decodedIRData.”

If you run the above example, you will see the following message on the serial port.

The function decode(&results)) is deprecated and may not work as expected! Just use decode() without a parameter and IrReceiver.decodedIRData.<fieldname> .

The code will work, but if you want to prevent this message, you have to rewrite this code a little bit.

//library to handle IR Receiver Diode
#include <IRremote.h>

//tiny, 3 mm Status LED at digital pin 13
#define statusLed 13
//IR Receiver Diode connected at digital pin 8
#define irReceiverDiode 8

//some connected LEDs
#define ledGreen 3
#define ledYellow 4
#define ledRed 5
#define ledBlue 6

//fields to store status of LEDs
bool ledGreenActive = false;
bool ledYellowActive = false;
bool ledRedActive = false;
bool ledBlueActive = false;

void setup() {
  //define pins from LEDs as OUTPUT
  pinMode(ledGreen, OUTPUT);
  pinMode(ledYellow, OUTPUT);
  pinMode(ledRed, OUTPUT);
  pinMode(ledBlue, OUTPUT);
  pinMode(statusLed, OUTPUT);

  //define pin from IR Receiver Diode as INPUT
  pinMode(irReceiverDiode, INPUT);

  //begin communication
  IrReceiver.begin(irReceiverDiode, ENABLE_LED_FEEDBACK);
  //begin serial communication with 9600 baud
  Serial.begin(9600);
}

void loop() {
  //if successful receive some data, then ...
  if (IrReceiver.decode()) {
    //store data in field value
    int value = String(IrReceiver.decodedIRData.command, DEC).toInt();
    //consume the data and clear
    IrReceiver.resume();
    //print the value to the serial interface
    Serial.println(value);
    //activate status LED
    digitalWrite(statusLed, HIGH);
    //tiny brake to light up the LED
    delay(75);
    //deactive status LED
    digitalWrite(statusLed, LOW);

    switch (value) {
      case 12: ledGreenActive = !ledGreenActive; break;
      case 24: ledYellowActive = !ledYellowActive; break;
      case 94: ledRedActive = !ledRedActive; break;
      case 8: ledBlueActive = !ledBlueActive; break;
    }

    resetLEDs();
  }
}

//set actual states to LEDS
void resetLEDs() {
  digitalWrite(ledGreen, ledGreenActive);
  digitalWrite(ledYellow, ledYellowActive);
  digitalWrite(ledRed, ledRedActive);
  digitalWrite(ledBlue, ledBlueActive);
}

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Fragen oder Feedback?

Du hast eine Idee, brauchst Hilfe oder möchtest Feedback loswerden?
Support-Ticket erstellen

Newsletter abonnieren

Bleib auf dem Laufenden: Erhalte regelmäßig Updates zu neuen Projekten, Tutorials und Tipps rund um Arduino, ESP32 und mehr – direkt in dein Postfach.

Jetzt Newsletter abonnieren

Unterstütze meinen Blog

Wenn dir meine Inhalte gefallen, freue ich mich über deine Unterstützung auf Tipeee.
So hilfst du mit, den Blog am Leben zu halten und neue Beiträge zu ermöglichen.

draeger-it.blog auf Tipeee unterstützen

Vielen Dank für deinen Support!
– Stefan Draeger

Categories

Links

Blogverzeichnis Bloggerei.de TopBlogs.de das Original - Blogverzeichnis | Blog Top Liste Blogverzeichnis trusted-blogs.com

Stefan Draeger
Königsberger Str. 13
38364 Schöningen

Tel.: 01778501273
E-Mail: info@draeger-it.blog

Folge mir auf

  • Impressum
  • Datenschutzerklärung
  • Disclaimer
  • Cookie-Richtlinie (EU)
©2025 Technik Blog | Built using WordPress and Responsive Blogily theme by Superb
Cookie-Zustimmung verwalten
Wir verwenden Cookies, um unsere Website und unseren Service zu optimieren.
Funktional Always active
Die technische Speicherung oder der Zugang ist unbedingt erforderlich für den rechtmäßigen Zweck, die Nutzung eines bestimmten Dienstes zu ermöglichen, der vom Teilnehmer oder Nutzer ausdrücklich gewünscht wird, oder für den alleinigen Zweck, die Übertragung einer Nachricht über ein elektronisches Kommunikationsnetz durchzuführen.
Vorlieben
Die technische Speicherung oder der Zugriff ist für den rechtmäßigen Zweck der Speicherung von Präferenzen erforderlich, die nicht vom Abonnenten oder Benutzer angefordert wurden.
Statistiken
Die technische Speicherung oder der Zugriff, der ausschließlich zu statistischen Zwecken erfolgt. Die technische Speicherung oder der Zugriff, der ausschließlich zu anonymen statistischen Zwecken verwendet wird. Ohne eine Vorladung, die freiwillige Zustimmung deines Internetdienstanbieters oder zusätzliche Aufzeichnungen von Dritten können die zu diesem Zweck gespeicherten oder abgerufenen Informationen allein in der Regel nicht dazu verwendet werden, dich zu identifizieren.
Marketing
Die technische Speicherung oder der Zugriff ist erforderlich, um Nutzerprofile zu erstellen, um Werbung zu versenden oder um den Nutzer auf einer Website oder über mehrere Websites hinweg zu ähnlichen Marketingzwecken zu verfolgen.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
Einstellungen anzeigen
{title} {title} {title}