Category Archives: TV remote extender

1st code

As I moved all my electronic equipment in a cabinet, I had to foresee an IR extender. I first looked at commercial devices or ones that are based on a 555 timer, but wanted to keep the amount of components at a minimum. Hence, Arduino to the rescue:

This project is currently running on a full Arduino, but I’m going to port it to a barebone soon. Right now, it is capturing IR via a TSOP alike IR receiver connected to pin 2. As these signals are demodulated, I had to regenerate the 36kHz carrier via timer 2 and turn it on/off depending on the the captured signal. This seems to work fine for most of my devices, except for the Belgacom setup box, which reacts very slow for the moment.

Todo:

  • try to combine this code with the IRremote library, so I can remotely control a led strip.
  • debug the Belgacom setup box issues
  • mount everything in a permanent enclosure
  • add an enc28j60 interface for future domotica enhancements

const byte LED = 10;  // Timer 2 “A” output: OC2A
int sensePin = 2;        // This is the INT0 Pin of the ATMega328
int sensePinInt = 0; // INT0 zit op pin 2, INT1 op pin 3

volatile int value = 0;  // Sense value

void setup() {
pinMode (LED, OUTPUT);
pinMode(sensePin, INPUT);   // read from the sense pin
attachInterrupt(sensePinInt, state, CHANGE);

// set up Timer 2
TCCR2A = _BV (COM2A0) | _BV(WGM21);  // CTC, toggle OC2A on Compare Match
TCCR2B = _BV (CS20);   // No prescaler
OCR2A = 220; // 36khz
//  OCR2A =  209;          // compare A register value (210 * clock speed)
//  = 13.125 nS , so frequency is 1 / (2 * 13.125) = 38095
}  // end of setup

void loop() { }

void state() {
value = digitalRead(sensePin);

if (value)
{
TCCR2A &= !(_BV(COM2A0) | COM2A1); // PWM off
}
else
{
TCCR2A = _BV (COM2A0) | _BV(WGM21);  // PWM on
}
}