public
Created

Remote IR and RF Control for Sony TV and Chacon Ref:54656

  • Download Gist
iRemotuino
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
/*
* iRemotuino - Remote IR and RF Control for Sony TV and Chacon Ref:54656
* Diogo Gomes <diogogomes@gmail.com>
* Copyright 2012
*/
 
#include <IRremote.h> //http://github.com/shirriff/Arduino-IRremot
#include <RemoteTransmitter.h> //https://bitbucket.org/fuzzillogic/433mhzforarduino
 
IRsend irsend;
 
#define IRLED_PIN 3
#define RFTRANSMITTER_PIN 9
#define RF_PERIOD 493 //usecs (as detected for Chacon Ref:54656 using a 434mhz receiver and fuzzillogic example code)
 
#define SONY 'S'
#define RC5 'Z' //used by ZonBox (Thomson model at least)
#define RF 'R'
 
void setup()
{
pinMode(IRLED_PIN, OUTPUT);
pinMode(RFTRANSMITTER_PIN, OUTPUT);
 
Serial.begin(9600);
}
 
unsigned long readCode() {
// Read 8 hex characters
if (Serial.available() < 8) return 0;
unsigned long code = 0;
for (int i = 0; i < 8; i++) {
char ch = Serial.read();
code = code << 4; //make way for new char
if (ch >= '0' && ch <= '9') {
code += ch - '0';
} else if (ch >= 'a' && ch <= 'f') {
code += ch - 'a' + 10;
} else if (ch >= 'A' & ch <= 'F') {
code += ch - 'A' + 10;
} else {
Serial.print("Unexpected hex char: ");
Serial.println(ch);
Serial.flush();
return 0;
}
}
return code;
}
 
void sendIRCommand(char type, int code) {
switch(type) {
case SONY:
for (int i = 0; i < 6; i++) {
digitalWrite(IRLED_PIN, HIGH); // set the LED on
irsend.sendSony(code, 12); // Sony TV code
delay(100);
digitalWrite(IRLED_PIN, LOW); // set the LED off
}
break;
case RC5:
digitalWrite(IRLED_PIN, HIGH); // set the LED on
irsend.sendRC5(code, 12);
delay(100);
digitalWrite(IRLED_PIN, LOW); // set the LED off
break;
}
}
 
void loop() {
if (Serial.available() < 9) return;
char type = Serial.read();
//Reads the extra 8 chars
unsigned long code = readCode();
/* Debug
Serial.print("0x");
Serial.println(code, HEX);
*/
switch(type) {
case SONY:
case RC5:
sendIRCommand(type, code);
break;
case RF:
// Retransmit the signal 8 times ( == 2^3) on pin RFTRANSMITTER. Note: no object was created!
RemoteTransmitter::sendCode(RFTRANSMITTER_PIN, code, RF_PERIOD, 3);
break;
default:
Serial.print("Unexpected type: ");
Serial.println(type);
}
Serial.println("ok");
Serial.flush();
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.