IR2Keyboard - Converting Infrared Remote Control Signals Into Keyboard Strokes.

by steve.ivie.92 in Circuits > Arduino

320 Views, 1 Favorites, 0 Comments

IR2Keyboard - Converting Infrared Remote Control Signals Into Keyboard Strokes.

IMG_4768.JPG

How to Make an IR2Keyboard with Arduino Micro

In this project, you will learn how to make an IR2Keyboard with an Arduino Micro, an IR receiver, and an IR remote control. This device will allow you to use an IR remote to send keystrokes to a computer that is connected to the Arduino Micro via USB. You will be able to use this device to control various applications on your computer, such as media players, browsers, games, etc.

Supplies

  • An Arduino Micro board
  • An IR receiver module (such as TSOP1738)
  • An IR remote control
  • Some jumper wires
  • A breadboard [optional]
  • A USB cable to connect the Arduino with a computer

Connect the Circuit

Connect the IR Receiver to the Arduino as follows:

  • Connect the VCC pin of the IR receiver to the 5V pin of the Arduino Micro.
  • Connect the GND pin of the IR receiver to the GND pin of the Arduino Micro.
  • Connect the OUT pin of the IR receiver to the pin 2 of the Arduino Micro.
  • Connect the Arduino Micro to your computer via USB cable.

Install the IRremote Library

To use the IR receiver module, you will need to install the IRremote library. This library supports many different IR communication protocols and allows you to decode and encode IR signals. You can download the library from [this link] and install it using the Arduino IDE. If you don’t know how to install additional Arduino libraries, you can follow Installing Libraries | Arduino Documentation.

Find the IR Codes for Each Remote Control Button

To use the IR remote control, you will need to find the IR codes for each button that you want to use. To do this, you can use the IRrecvDemo example sketch that comes with the IRremote library. You can find it in File > Examples > IRremote > IRrecvDemo. Before uploading the sketch, make sure to change the RECV_PIN value to 2, which is the pin that we connected the IR receiver to. Also, make sure to select the Arduino Micro board and the correct port from the Tools menu. After uploading the sketch, open the Serial Monitor and press the buttons on your IR remote. You should see the IR codes printed on the Serial Monitor. Note down the codes for each button that you want to use.

Write the Code for the IR2Keyboard

To write the code for the IR2Keyboard, you will need to use the Keyboard library, which allows the Arduino Micro to emulate a USB keyboard. You will also need to use the IRremote library, which allows you to decode the IR signals from the IR remote.

/*
 * IrReceiver to Keyboard
 * Author: Steve Ivie
 * Demonstrates receiving NEC IR codes with IRremoted translating them into Keyboard strokes.  
 * Works well with Arduino's that can act as a Keyboard, like Arduino Micro.
 * Schematic: IR Receiver is connected to +5v, GND, and D2.
 *
 */


//#define DEBUG  
#include "Keyboard.h"
#include <Arduino.h>


/*
 * Specify which ir remote protocol should be used for decoding.
 * This must be done before the #include <IRremote.hpp>
 */
#define DECODE_NEC          // Includes Apple and Onkyo
#define DECODE_MAGIQUEST
#define RAW_BUFFER_LENGTH  180  // Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100.
#include <IRremote.hpp> // include the library

#define IR_RECEIVE_PIN 2


// Define the IR codes for the 13 keys
#define IR_KEY_1 0xE916FF00 // NEC code for 1
#define IR_KEY_2 0xE619FF00 // NEC code for 2
#define IR_KEY_3 0xF20DFF00 // NEC code for 3
#define IR_KEY_4 0xF30CFF00 // NEC code for 4
#define IR_KEY_5 0xE718FF00 // NEC code for 5
#define IR_KEY_6 0xA15EFF00 // NEC code for 6
#define IR_KEY_7 0xF708FF00 // NEC code for 7
#define IR_KEY_8 0xE31CFF00 // NEC code for 8
#define IR_KEY_9 0xA55AFF00 // NEC code for 9
#define IR_KEY_0 0xAD52FF00 // NEC code for 0
#define IR_KEY_A 0xBB44FF00 // NEC code for A
#define IR_KEY_B 0xBC43FF00 // NEC code for B
#define IR_KEY_C 0xEA15FF00 // NEC code for C


void setup() {
    Serial.begin(115200);
    // Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED
    IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
    Keyboard.begin();
}

void loop() {

  if (IrReceiver.decode()) {
    // Print a short summary of received data
    IrReceiver.printIRResultShort(&Serial);

    if (IrReceiver.decodedIRData.protocol == NEC) { // Check if the protocol is NEC
      switch (IrReceiver.decodedIRData.decodedRawData) { // Check the IR code
        case IR_KEY_1: // If the code is 1
          Keyboard.write('1'); // Send the keystroke 1
          break;
        case IR_KEY_2: // If the code is 2
          Keyboard.write('2'); // Send the keystroke 2
          break;
        case IR_KEY_3: // If the code is 3
          Keyboard.write('3'); // Send the keystroke 3
          break;
        case IR_KEY_4: // If the code is 4
          Keyboard.write('4'); // Send the keystroke 4
          break;
        case IR_KEY_5: // If the code is 5
          Keyboard.write('5'); // Send the keystroke 5
          break;
        case IR_KEY_6: // If the code is 6
          Keyboard.write('6'); // Send the keystroke 6
          break;
        case IR_KEY_7: // If the code is 7
          Keyboard.write('7'); // Send the keystroke 7
          break;
        case IR_KEY_8: // If the code is 8
          Keyboard.write('8'); // Send the keystroke 8
          break;
        case IR_KEY_9: // If the code is 9
          Keyboard.write('9'); // Send the keystroke 9
          break;
        case IR_KEY_0: // If the code is 0
          Keyboard.write('0'); // Send the keystroke 0
          break;
        case IR_KEY_A: // If the code is A
          Keyboard.write('A'); // Send the keystroke A
          break;
        case IR_KEY_B: // If the code is B
          Keyboard.write('B'); // Send the keystroke B
          break;
        case IR_KEY_C: // If the code is C
          Keyboard.write('C'); // Send the keystroke C
          break;
        default: // If the code is not recognized
          // Do nothing
          break;
      }
    }
    Serial.println();
    IrReceiver.resume(); // Enable receiving of the next value
  }
}


I hope these instructables helps you with your project. 😊