Trybotics Logo

IR Remote Control for Presentation PC

DESCRIPTION

This is a project that will allow you to remotely control the display of presentations on your computer.

It is very simple, but you remember, before you start you need to install two libraries in your Arduino IDE.

Explanation of the NEC protocol.

The arrow keys remain unchanged. The other keys are unused (1, 2, 4, 5, 7, 8).

The Pro Micro module works as a Human Interface Device and does not require additional drivers.

Opis w języku polskim.

Description:

Description:

This is a project that will allow you to remotely control the display of presentations on your computer.

It is very simple, but you remember, before you start you need to install two libraries in your Arduino IDE.

Explanation of the NEC protocol.

The arrow keys remain unchanged. The other keys are unused (1, 2, 4, 5, 7, 8).

The Pro Micro module works as a Human Interface Device and does not require additional drivers.

Opis w języku polskim.

Description:

CodeC/C++
// Remote Control For Presentation PC
// Module Pro Micro (AT MEGA 32U4) 16MHz
// NEC protocol only

// Author: Piotr Sylwesiuk
// https://plus.google.com/109581799567307387329

// IR Remote library from https://github.com/z3t0/Arduino-IRremote
// HID library from https://github.com/NicoHood/HID

#include <HID-Project.h>
#include <HID-Settings.h>

#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>

uint8_t ir_code();

// Infrared remote control
#define IR_ADDR 0x00FF // Address
// used keys
#define IR_KEY_3             0xE2  // Vol+
#define IR_KEY_6             0xC2  // Vol-
#define IR_KEY_9             0x90  // Mute
#define IR_KEY_0             0x98  // Play/Pause
#define IR_KEY_STAR          0x68  // ESC
#define IR_KEY_HASH          0xB0  // Shift F5
#define IR_KEY_UP_ARROW      0x18  // Arrow Up
#define IR_KEY_DOWN_ARROW    0x4A  // Arrow Down
#define IR_KEY_RIGHT_ARROW   0x5A  // Arrow Right
#define IR_KEY_LEFT_ARROW    0x10  // Arrow Left
#define IR_KEY_OK            0x38  // F5

// IR Receiver
#define IR_RECEIVER_PIN A2

IRrecv irrecv(IR_RECEIVER_PIN);

void setup() {
  // put your setup code here, to run once:

  // Initializing the infrared receiver
  irrecv.enableIRIn();
  irrecv.blink13(false);

  // Initializing control over the keyboard
  Keyboard.begin();
  Consumer.begin();
}

void loop() {
  // put your main code here, to run repeatedly:
  
  switch(ir_code()){
    case IR_KEY_UP_ARROW    : Keyboard.write(KEY_UP_ARROW); break;
    case IR_KEY_DOWN_ARROW  : Keyboard.write(KEY_DOWN_ARROW); break;
    case IR_KEY_RIGHT_ARROW : Keyboard.write(KEY_RIGHT_ARROW); break;
    case IR_KEY_LEFT_ARROW  : Keyboard.write(KEY_LEFT_ARROW); break;
    case IR_KEY_STAR        : Keyboard.write(KEY_ESC); break;

    // Shift F5
    case IR_KEY_HASH        : Keyboard.press(KEY_LEFT_SHIFT);
                              Keyboard.write(KEY_F5);
                              Keyboard.release(KEY_LEFT_SHIFT); break;
                               
    case IR_KEY_OK          : Keyboard.write(KEY_F5); break;
    case IR_KEY_9           : Consumer.write(MEDIA_VOLUME_MUTE); break;
    case IR_KEY_3           : Consumer.write(MEDIA_VOLUME_UP); break;
    case IR_KEY_6           : Consumer.write(MEDIA_VOLUME_DOWN); break;
    case IR_KEY_0           : Consumer.write(MEDIA_PLAY_PAUSE); break;
  }
}

// ----------------------------------------------------------
uint8_t ir_code() {
  decode_results irResults; // Here we store the results
  uint16_t irCode = 0;
  static uint8_t irTmp = 0;

  if (irrecv.decode(&irResults)) {
    if ((irResults.decode_type == NEC) && (!irResults.overflow)) {
      if ((irResults.bits == 32) && (((irResults.value & 0xffff0000)>>16) == IR_ADDR)) {
        irCode = irResults.value & 0x0000ffff;
        irTmp = (~(irCode & 0x00ff))& 0x00ff;
        irCode >>= 8;
        if (!(irCode == irTmp)) irCode = irTmp = 0;
        
             // Recognition of the code repetition of the pressed remote control button.
      } else if ((irResults.bits == 0) && (irResults.value == 0xffffffff) && (irTmp != 0)) {
        
          // Autorepeat for Vol+ and Vol- (IR_KEY_3 and IR_KEY_6)
          if((irTmp==IR_KEY_3)||(irTmp==IR_KEY_6)) irCode=irTmp; else irCode = 0xff; 
          
      } else irCode = irTmp = 0;
    } else irCode = irTmp = 0;
    irrecv.resume(); // Prepare for the next value
    return (irCode);
  } else {
    irCode = 0;
    return (irCode);
  }
}

Description:

Wiring diagram
Ir promicro4a lry6dgku79


YOU MIGHT ALSO LIKE