IR transmittion.. again

Here is the code, I want everytime I press the button it fires the signal

// 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);
  }
}

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.

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.

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.

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.

Well yes, on an osciloscope it shows that there is a certain pulse system, but the TV won't react.
Yup, trying to mimic the remote

Has the code ever worked before you modified it? I'm suggesting to compare the arduino pulsed output with the actual remote signal. you can use an IR receiver to receive the tv remote signal. But until you compare the two signals to see if you are implementing it correctly , there's not much else I can suggest.

I want everytime I press the button it fires the signal

Then, you need to manage the state of the switch better. It appears that you want to send the signal once per switch press, not over and over as long as the switch is pressed (which is what the code you posted would do).

The first thing that we need to establish is that the switch is wired correctly. The code you posted does not use the internal pullup resistor. Therefore, you need an external pullup or pulldown resistor. Do you have one? How is the switch wired?

Using the internal pullup resistor and wiring the switch between the digital pin and ground is far simpler to however you have it wired now.