August 2, 2020

IR Software Remote Control

Filed under: electronics Himanshu @ 12:21 pm

This weekend, I reopened my boxes hosting electronic components with target to assess and validate couple of ideas that I had to build alternate interface to my TV, alternate to TV remote.

During discovery phase or say “feasibility study” of idea, i found 2 useful resources.

Arduino IR Remote is great library to work with proprietary protocol of different manufacturers, include one that I was looking for – Sony.

LIRC is great repository for referring codes to send to electronics device for several operation, including TV, but not limited to only TV.

Below is intermediate code that accepts number on serial, and depending upon entered number, sends IR signal to my TV.

#include <IRremote.h>
//https://github.com/z3t0/Arduino-IRremote/issues/580
//http://lirc.sourceforge.net/remotes/sony/RM-ED035

IRsend irsend;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // send an intro:
  Serial.println("\n\nString toInt():");
  Serial.println();
}

void sendCommand(unsigned long signalValue){
  for (int i = 0; i < 3; i++) {  // sends code 3 times
    irsend.sendSony(signalValue, 12);
    delay(20);
  }
  delay(200);
}

void onOff() { sendCommand(0xA90); }
void input() { sendCommand(0xA50); }

void volumnUp() { sendCommand(0x490); }
void volumnDown() {  sendCommand(0xC90); }
void mute() { sendCommand(0x290); }

void priorProgram() { sendCommand(0x890); }
void nextProgram() { sendCommand(0x90); }

void homeKey() { sendCommand(0x070); }
void okay() {  sendCommand(0xA70); }
void upKey() { sendCommand(0x2F0); }
void downKey() { sendCommand(0xAF0); }
void leftKey() { sendCommand(0x2D0); }
void rightKey() { sendCommand(0xCD0); }
void exitKey() { sendCommand(0xC70); }
void infoKey() { sendCommand(0x5D0); }

void one() { sendCommand(0x010); }
void two() {  sendCommand(0x810); }
void three() { sendCommand(0x410); }
void four() { sendCommand(0xC10); }
void five() { sendCommand(0x210); }
void six() { sendCommand(0xA10); }
void seven() { sendCommand(0x610); }
void eight() {  sendCommand(0xE10); }
void nine() { sendCommand(0x110); }
void zero() { sendCommand(0x910); }

void audio() { sendCommand(0xE90); }

String inString = "";    // string to hold input
void loop() {
  // Read serial input:
  while (Serial.available() > 0) {
    int inChar = Serial.read();
    if (isDigit(inChar)) {
      // convert the incoming byte to a char and add it to the string:
      inString += (char)inChar;
    }
    // if you get a newline, print the string, then the string's value:
    if (inChar == '\n') {
      Serial.print("Value:");
      Serial.println(inString.toInt());
      switch (inString.toInt()){
        case 1:
          onOff();
          break;
        case 2:
          input();
          break;
        case 3:
          volumnUp();
          break;
        case 4:
          volumnDown();
          break;
        case 5:
          mute();
          break;
        case 6:
          priorProgram();
          break;
        case 7:
          nextProgram();
          break;
        case 8:
          homeKey();
          break;
        case 9:
          okay();
          break;
        case 10:        
          upKey();
          break;
        case 11:
          downKey();
          break;
        case 12:
          leftKey();
          break;
        case 13:
          rightKey();
          break;
        case 14:
          exitKey();
          break;
        case 15:
          infoKey();
          break;
        case 16:
          audio();
          break;        
      }
      inString = "";
    }
  }
}

Powered by WordPress