A little confused. Could use some help!

Hello everyone, ive been playing with arduino(and some other different micros) for a little while now. Im still a beginner, but i am learning every day. Ive recently came across a task, and figured the arduino platform would be perfect (and hopefully i can get it onto an attiny soon). What im trying to do is transmit the infrared power code for a very popular cable box, when an input is switched high. It will be controlled by RF once its finished, but for now, and simplicity i will be using a pushbutton. I tried writing the code from the ground up, but realized i was in over my head. I read dozens of different articles about the defferent IR protocols, and the many projects that already use IR and stumbled across this page.

http://www.controllerprojects.com/auto-channel-checker-changelog/

Under the project named SApower1_6_5 i found he had all the IR codes neccesary, and than some. All i need is the one power on/off code. So my question is, what part of that code would be the actual power command thats sent out, and what else from that code is neccesary to support it? There is a lot of stuff in there thats not needed for my project, but i cant manage to sort out what i need and to get it working. Once i have that im pretty sure i can just use the button code. Thanks!

Another good project for sources of codes is the "lirc" or "lircd" project, which is a Linux remote control system. The source code is quite informative.

You can "just" hook up an IR LED to a digital output, and send the right code, like you would flash a regular LED.

But! There are three levels of modulation that are needed.

  1. The actual bits of the command you want to send. This is the easy part.
  2. How those bits translate into "high" and "low" ("mark" and "space") in the particular serial binary protocol used by your box.
  3. How to in turn modulate the carrier signal with those marks and spaces.

Typically, remote controls require a pulse train of about 30% duty cycle on/70% off at 38 kHz. Then you modulate this by not sending pulses for the "off"/"low" sections. However, some remotes run at different carrier frequencies, typically in the range from 16 to 60 kHz. And B&O gear runs at some much higher frequency -- 433 kHz IIRC.

The easiest way I've found to do this is to set up timer 2 to generate the carrier wave using PWM, and then in turn modulate that output signal with a transistor coupled to a second digital out, which I feed using simple pin writes (for the marks and spaces). This ends up driving a second transistor that drives the IR LED. I use BS170 MOSFETs, feel free to use whatever floats your boat. My "arduino hacks" project on github contains the code I use to drive this: https://github.com/jwatte/arduino-chargetimer/blob/master/ircontrol/ircontrol.ino The code is slightly more complex because it actually receives the commands to transmit from the serial port, but it should be easy to tease apart the bits you need if you know C programming :-)

Thanks, that was helpful! ive got the code condensed down to this. Im sure theres still a bunch of stuff thats not needed but right now im trying to get it to function on an attiny85. Ive been using a usbtinyisp, and the ardiuno IDE, but cant seem to figure out how to get rid of the old pin assignments, and replace them with the correct code for the attiny85 output 3. Heres what i have that is functioning on the atmega328.

#define NOPDelays "nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t"
#define IRBitLength 840 //For a Scientific Atlanta remote control, the bit length is .84 millisecond (840 uS)
#define OscillationBitLength 49 //For a Scientific Atlanta remote control, the number of 56kHz oscillations for one bit is 49
#define DDR_IRRegister DDRB //  The last character signifies the Register (A, B, C, or D)
#define PORT_IRRegister PORTB // The last character signifies the Register (A, B, C, or D)
#define IRPin B00001000 // The pin number in the register






void setup()
{
  SetIRPinOutput();  // which pin is used for output is defined on sheet IRModulation in "#define IRPin" and "#define DDR_IRRegister" and "#define PORT_IRRegister"
}




void SetIRPinOutput()
{
      DDR_IRRegister |= IRPin; //example: DDRD = DDRD | B00010000
}

void IROn(int OnCycles)                      //  How many time cycles of High (1) that the IR signal is on
{
  Oscillation(OscillationBitLength*OnCycles);//  OscillationBitLength is the number of oscillations needed to achieve one IR bit
}


void IROff(int OffCycles)                    //  How many time cycles of Low (0) that the IR signal is off
{
  PORT_IRRegister = PORT_IRRegister & ~IRPin;  // This *SHOULD* turn off only the IRPin
  delayMicroseconds(IRBitLength*OffCycles);  //  Stay off for OffCycles number of bit lengths
}

void IROn1Off1(int On1Off1Cycles)    //  How many times to repeat the cycles of on one cycle then off one cycle
{
  while (On1Off1Cycles > 0)          //  Repeat the following for the number of times specified in the function call
  {
    IROn(1);                         //  Turn the LED on one timing cycle
    IROff(1);                        //  Turn the LED off one timing cycle
    On1Off1Cycles--;                 //  One less time to repeat
  }
}

void IROn1Off3(int On1Off3Cycles)    //  How many times to repeat the cycles of on one cycle then off three cycles
{
  while (On1Off3Cycles > 0)          //  Repeat the following for the number of times specified in the function call
  {
    IROn(1);                         //  Turn the LED on one timing cycle
    IROff(3);                        //  Turn the LED off three timing cycles
    On1Off3Cycles--;                 //  One less time to repeat
  }
}
void IRHeader()                      //  This sequence of IR signals is common to the beginning of *most* of the remote control commands
{
  IROn(4);                           //  On 4 cycles
  IROff(4);                          //  Off 4 cycles
  IROn1Off3(2);                      //  On 1 cycle then off 3 cycles (twice)
  IROn1Off1(1);                      //  On 1 cycle then off 1 cycle
  IROn1Off3(2);                      //  On 1 cycle then off 3 cycles (twice)
  IROn1Off1(1);                      //  On 1 cycle then off 1 cycle
}


void IRPowerFooter()                 //  Remote control button power has a non-standard footer (below)
{
  IROff(1);                          //  Off 1 cycle
  IROn1Off3(3);                      //  On 1 cycle off 3 cycles (three times)
  delay(1000);                       //  Wait 1 second (for an automatic delay between key presses)
}

void IRFooter()                      //  This sequence of IR signals is common to the ending of *most* of the remote control commands
{
  IROff(1);                          //  Off 1 cycle
  IROn1Off3(2);                      //  On 1 cycle then off 3 cycles (twice)
  IROff(4);                          //  Off 4 cycles
  delay(1000);                       //  Wait 1 second (for an automatic delay between key presses)
}

void IR_Power()
{
  //
  IRHeader();
  //
  IROff(2);
  IROn1Off3(2);
  IROn1Off1(5);
  IROn1Off3(1);
  IROn1Off1(5);
  IROn1Off3(5);
  //
  IRPowerFooter();
  //
}



void Oscillation(int numCycles)
{
  int i;
  for (i=0; i<numCycles; i++)        //  For each for loop iteration, it's one cycle of 56kHz modulation
  {
    PORT_IRRegister |= IRPin;        //  Bring the IR pin high and only that pin
    delayMicroseconds(8);            //  leave it up for 8 uS
    __asm__(NOPDelays);              //  continue to leave it up for the number of NOP Delay cycles defined at the top of the code
    PORT_IRRegister &= ~IRPin;       //  Bring the IR pin low and only that pin low
    delayMicroseconds(8);            //  leave it down for 8 uS
    __asm__(NOPDelays);              //  continue to leave it down for the number of NOP Delay cycles defined at the top of the code
  }
}





void loop() 
 {
 IR_Power();
   }