Go Down

Topic: IR transmittion.. again (Read 656 times) previous topic - next topic

Gofilord

Here is the code, I want everytime I press the button it fires the signal
Code: [Select]
// This sketch will send out an arbitrary IR signal

int IRledPin =  13;    // LED connected to digital pin 13

const int pulses = 37;
const int buttonPin = 2;     // the number of the pushbutton pin
int buttonState = 0;         // variable for reading the pushbutton status

const int IRsignal[pulses*2] = { // ON, OFF (in 10's of microseconds)
  86, 88,
  176, 88,
  84, 90,
  86, 88,
  86, 88,
  84, 90,
  84, 94,
  82, 88,
  84, 174,
  84, 90,
  176, 88,
  86, 2394,
  86, 88,
  176, 88,
  86, 92,
  88, 82,
  92, 82,
  86, 88,
  86, 88,
  92, 82,
  92, 166,
  92, 82,
  182, 82,
  86, 2398,
  88, 82,
  182, 82,
  86, 88,
  86, 88,
  92, 82,
  92, 86,
  82, 84,
  96, 82,
  86, 172,
  92, 82,
  182, 86,
  82, 0};

// The setup() method runs once, when the sketch starts



void setup()   {               
  // initialize the IR digital pin as an output:
  pinMode(IRledPin, OUTPUT);     
    pinMode(buttonPin, INPUT);
   
}
   
    void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:   
    SendCode(pulses, IRsignal); 
  }

}




// This procedure sends a 38KHz (26 microsecond cycle time) pulse to the IRledPin
// for a certain # of microseconds. We'll use this whenever we need to send codes
void pulseIR(long microsecs) {
  // we'll count down from the number of microseconds we are told to wait

  cli();  // this turns off any background interrupts

  while (microsecs > 0) {
    // 38 kHz is about 13 microseconds high and 13 microseconds low
    digitalWrite(IRledPin, HIGH);  // this takes about 3 microseconds to happen
    delayMicroseconds(10);         // hang out for 10 microseconds
    digitalWrite(IRledPin, LOW);   // this also takes about 3 microseconds
    delayMicroseconds(10);         // hang out for 10 microseconds

    // so 26 microseconds altogether
    microsecs -= 26;
  }

  sei();  // this turns them back on
}

void SendCode(const int pulses, const int IRsigna[]) {

  for (int i=0; i< pulses; i++)
  {
    pulseIR(IRsignal[2*i] * 10);
    delayMicroseconds(IRsignal[2*i+1] * 10);
  }
}

cyborg5

My recommendation is you give up on the custom code and just go with this library. Or wait a couple of weeks. I'm working on a new library based on the one mentioned below. Will be a lot more flexible and easier to add new protocols. But if all you want to do is send raw values, this library will do it for you easily.
http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html

johnnyonthespot

Hi,

1. I am assuming your code is not ready correct? I understand the current state of your code does this:

- Clock out a 38kHz square wave to the LED once a button is pushed.

I see you clear/enable interrupts, but do not implement them in your code. Do you need help with this (for the button press)?
Also, do you understand how to implement the actual signal with the 38kHz carrier frequency?

I'm just trying to get an idea on what you need help with.

Gofilord

Well, I need to know what's wrong with my code, because currently, when I press the button, It doesn't send a signal.
Basiclly it's the code from the TV remote and I want to control the TV with the arduino, so someone from here helped me out and put the code from the remote to this code that's ment to send it.
That guy also included a line that sends the code every 60 seconds, so I tried changing it and putting a code that everytime I click the button it fires the code.

johnnyonthespot

Has this code every worked for you? Are you trying to mimic a working system (a TV remote?). I would put each on an oscilloscope to compare them if possible.

Go Up