0

Edit: Took some advice from below but it still doesn't work. I think it probably blocking code but please tell me how I could fix it to send a the valid infrared signal, NOTE: I wouldn't actually code it like this I am just trying to learn and understand how to do it and then make it better after:

uint8_t Status;
uint8_t Counter;
const uint32_t Code[] = {4507,4507,573,1694,573,1694,573,1694,573,573,573,573,573,573,573,573,573,573,573,1694,573,1694,573,1694,573,573,573,573,573,573,573,573,573,573,573,573,573,1694,573,573,573,573,573,573,573,573,573,573,573,573,573,1694,573,573,573,1694,573,1694,573,1694,573,1694,573,1694,573,1694,573,46560};

void setup() {
  pinMode(4, OUTPUT);
}

void loop() {
  while(Counter<70) {
    if (Status=1) {
        digitalWrite(4, HIGH);
        Status=3;
        while(Status=3) {
          delayMicroseconds(26);
          digitalWrite(4, HIGH);
          delayMicroseconds(26);
          digitalWrite(4, LOW);
        }
        delayMicroseconds(Code[Counter]);
        Status=2;
        Counter++;
    } else {
      if (Status=2) {
        digitalWrite(4, LOW);
        Status=0;
        while(Status=0) {
          delayMicroseconds(26);
          digitalWrite(4, HIGH);
          delayMicroseconds(26);
          digitalWrite(4, LOW);
        }
        delayMicroseconds(Code[Counter]);
        Status=1;
        Counter++;
      }
    }
  }
}
8
  • 1
    It is unclear, what exactly is the problem. Maybe you have some basic misconceptions. Like, that infrared remotes (and also most libraries) use a fixed modulation for the pulses (for example at 38kHz) to get better noise resistance. How are you receiving the IR signal? You need to send an IR signal, that the receiver understands. – chrisl Oct 8 '20 at 9:50
  • 1
    Raw infrared timings do not need to specify hz I believe. if you flash a led constantly at 1Hz you would be flashing 1 time per second. 2Hz 2 times per second. The actual infrared timings in the Buf variable do not need to specifcy a frequency since they are RAW. So the code above It starts with the first 4507 and that would be the delay. the (timing). I believe that's how it works after reading alot about infrared. But the problem im having is that I don't know how to implement it i guess? do I flash delay for 4507 and then keep it off for 4507? I know how it works but need help debuging this – Macaroni Oct 8 '20 at 10:51
  • 1
    Im not looking at the recieving side. – Macaroni Oct 8 '20 at 11:24
  • 1
    If the TV turns on then it works :/ – Macaroni Oct 8 '20 at 11:59
  • 1
    if (Status=1) is an assignement, this will not work like you think it does. It should be a comparison: if (Status==1). Likewise for while (Status=2) and other if() and while() statements in your code. Furthermore there is no way your while() { } loops will ever exit because the value of Status never changes inside the loop. – StarCat Oct 8 '20 at 13:49
0

There are two basic things wrong here - one with your understanding of the timings, and the other with your understanding of how IR communication works.

First the timings - those are both ON and OFF timings. You don't just turn on for a defined length of time - you turn on for a defined length of time and then turn off for another defined length of time.

So for the timings in your code 4507,4507,573,1694,573,...etc... you would:

  • Turn on
  • Wait 4507us
  • Turn off
  • Wait 4507us
  • Turn on
  • Wait 573us
  • Turn off
  • Wait 1694us
  • Turn on
  • Wait 573us
  • ... etc ...

You have no "off" time in your code, only ever on times.

Secondly is your understanding of IR communications. It does not involve turning an LED on or off for defined times. It's not as simple as that. Instead you are controlling the modulation of an LED. When the LED of an IR remote control is "on" it's not just turned on - it's rapidly turning on and off. The receiver looks for the presence or absence of this rapid turning on and off light. This is the "carrier frequency" of the signal and must match what the receiver is looking for.

Typically this is between 30kHz and 50kHz depending on the receiver.

So you need some way of generating that rapid on-off signal. Normally this is done using PWM by the IR libraries and switching between 0% and 50% duty cycle for the off and on periods of the signal you want to send.

So it's far simpler to just use a library that does all this underlying work for you.

12
  • Thanks I will try this out and see if it works <3 – Macaroni Oct 8 '20 at 11:24
  • I have edited my question because yours should work but it doesn't. – Macaroni Oct 8 '20 at 12:17
  • You have covered the first problem, but done nothing at all about the second problem. – Majenko Oct 8 '20 at 12:22
  • 1
    can you provide me some basic simplified code on wat i need to do? :> – Macaroni Oct 8 '20 at 12:40
  • 1
    I mean I can use the library. I just want to understand how it works and I want to make my own simplified version. Satisfaction of doing it urself and just more flexible since its small and I can read it better and not only that improve its performance even if its at a fraction. – Macaroni Oct 8 '20 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.