Skip to content

Instantly share code, notes, and snippets.

@vindolin

vindolin/ir_babelfish.ino

Last active Nov 16, 2019
Embed
What would you like to do?
Arduino IR Babelfish
// This sketch translates incoming IR codes from a front facing IR receiver to an IR LED on the back of the device.
// I'm using it to controll my Edifier sound system with my Samsung TV remote control.
#include <IRremote.h> // https://github.com/z3t0/Arduino-IRremote
const int RECV_PIN = 4; // attach 1838 IR receiver to this pin
const int LED_PIN = 13; // attach an LED to this pin as a monitor
// the send pin is depending on the timer the library is using, for the nano it's 9
// see: https://github.com/z3t0/Arduino-IRremote/blob/master/boarddefs.h#L67
const int BLINK_LENGTH = 50;
const int RELAY_DELAY = 100;
// LG
// const long IN_MUTE = 0x20DF906F;
// const long IN_VOL_UP = 0x20DF40BF;
// const long IN_VOL_DOWN = 0x20DFC03F;
// Samsung
const long IN_BLUE = 0xE0E06897;
const long IN_MUTE = 0xE0E0F00F;
const long IN_VOL_UP = 0xE0E0E01F;
const long IN_VOL_DOWN = 0xE0E0D02F;
// Edifier
const long OUT_POWER = 0xFF629D;
const long OUT_MUTE = 0xFF827D;
const long OUT_VOL_UP = 0xFF609F;
const long OUT_VOL_DOWN = 0xFFE21D;
const IRrecv irrecv(RECV_PIN);
IRsend irsend;
unsigned long on_millis = 0;
decode_results results;
void setup() {
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
irrecv.enableIRIn();
Serial.println("init");
}
void send(long code) {
delay(RELAY_DELAY);
irsend.sendNEC(code, 32);
irrecv.enableIRIn();
}
void loop() {
// wait for incoming IR codes
if (irrecv.decode(&results)) {
Serial.print("received: ");
Serial.println(results.value, HEX);
switch (results.value) {
case IN_BLUE:
send(OUT_POWER);
break;
case IN_MUTE:
Serial.println("mute");
send(OUT_MUTE);
break;
case IN_VOL_UP:
Serial.println("up");
send(OUT_VOL_UP);
break;
case IN_VOL_DOWN:
Serial.println("down");
send(OUT_VOL_DOWN);
break;
default:
break;
}
irrecv.resume();
digitalWrite(LED_PIN, HIGH);
on_millis = millis();
}
if(millis() - on_millis > BLINK_LENGTH) {
digitalWrite(LED_PIN, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.