Controlling TV using arduino and IR Led

Hi.

I’m trying to control my TV (it’s a BLAUPUNKT) using the arduino and an infrared led.

I am using the IRremote.h library by shirriff for this.

I already read the button codes from the TV remote, and wrote them to notepad. For that, I used the following code:

#include <IRremote.h>

const int RECV_PIN = 12;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  irrecv.blink13(true);
}

void loop() {
  if (irrecv.decode(&results)) {
    if (results.decode_type == NEC) {
      Serial.print("NEC: ");
    } else if (results.decode_type == SONY) {
      Serial.print("SONY: ");
    } else if (results.decode_type == RC5) {
      Serial.print("RC5: ");
    } else if (results.decode_type == RC6) {
      Serial.print("RC6: ");
    } else if (results.decode_type == UNKNOWN) {
      Serial.print("UNKNOWN: ");
    } else {
      Serial.print("wtf: ");
    }
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
}

And the wiring was just directly from the IR sensor pins to the pins on the arduino (VCC to 5V, GND to GND, OUT to 12 digital input). The IR sensor I’m using is VS1838B, datasheet here: https://www.elecrow.com/download/Infrared%20receiver%20vs1838b.pdf (I also don’t understand chinese, but it says the pinout of the sensor).

Now, when I try to send one of the codes (already tried a few different button codes), using the following code:

/*
   An IR LED must be connected to Arduino PWM pin 3.
*/

#include <IRremote.h>

IRsend irsend;


void setup()
{
}

void loop() {

  irsend.sendNEC(0xFEFA05, 24);
  delay(1000);
  irsend.sendNEC(0xFEFA05, 24);
  delay(40);
  irsend.sendNEC(0xFEFA05, 24);
  delay(1000);
}

and the wiring: Arduino PWM pin 3 (output from the library) to 220 ohm resistor, then from that resistor to infrared led positive, then from the infrared led negative to arduino GND. Did how the library author says here under the “Hardware Setup” subtitle: A Multi-Protocol Infrared Remote Library for the Arduino
The led blinks every second when I look at it using the phone camera, and its brightness is very similar to the TV remote.
But when I turn the IR led to the TV like a remote, even if I put it close to the TV IR sensor, it won’t react.

Any ideas what could be wrong?

Some more info:
Arduino is the arduino UNO;
I don’t have more arduinos, so can’t test send and receive, unless it can be done on the same arduino, sending and receiving at the same time *.
If I missed some useful info, please tell me.
Thank you.

  • I already tried send and receive from the same arduino, but I can’t get it to work properly. I tried this code:
/*
   An IR LED must be connected to Arduino PWM pin 3.
*/

#include <IRremote.h>

const int RECV_PIN = 12;

IRsend irsend;
IRrecv irrecv(RECV_PIN);
decode_results results;

unsigned long previousMillis = 0;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  irrecv.blink13(true);
}

void loop() {
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= 1000) {
    previousMillis = currentMillis;
    
    irsend.sendNEC(0xFE0AF5, 24);
    
    irrecv.enableIRIn();
  }
  if (irrecv.decode(&results)) {
    if (results.decode_type == NEC) {
      Serial.print("NEC: ");
    } else if (results.decode_type == SONY) {
      Serial.print("SONY: ");
    } else if (results.decode_type == RC5) {
      Serial.print("RC5: ");
    } else if (results.decode_type == RC6) {
      Serial.print("RC6: ");
    } else if (results.decode_type == UNKNOWN) {
      Serial.print("UNKNOWN: ");
    }
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }

}

It should every second send the signal and read for signals all the time. But I can’t get it to read itself:

Trying to read from itself:
vid1.mp4 (sorry, the forum says error when I attach the videos)
The feedback on led 13 is weak.

Trying to read from the TV remote:
vid2.mp4
Much stronger feedback, and the library can even recognise it and send to the serial.

Seems to me that it is only receiving the final part of the signal sent by itself.

I don’t know what to try next. Any ideas?

PS: this is a nice doc about the library from which I based some of my code: IRremote Library, Send & Receive Infrared Remote Control

Maybe 24 bits is not the right number of bits?

Use File->Eaxmples->IRremote->IRrecvDumpV2 to display the received codes. That will include the bit count. Sending 24 bits when the TV requires 28 or 32 could cause the codes to fail.

If using an AVR such as Uno, large integer constants may need the UL suffix. For example, 0xFEFA05UL

@johnwasser But all the codes I wrote down have 6 hex (24 bits). Should I still type 28 or 32?
I didn't notice the examples were on the IDE, I have been looking at them at github :stuck_out_tongue:

@gbafamilty 6 hex characters, 16^6 = 16 777 216 doesn't seem to be too big, as int can hold up to 2 147 483 648‬. But I will give it a try.

Thanks for the suggestions!

@johnwasser

I tried the IRrecvDumpV2 example and actually got a 32 bit reply!

Encoding : NEC
Code : FE0AF5 (32 bits)
Timing[67]:
+8750, -4450 + 500, - 550 + 550, - 550 + 550, - 600

  • 500, - 550 + 550, - 550 + 500, - 600 + 500, - 600
  • 550, - 550 + 500, -1700 + 500, -1700 + 500, -1700
  • 500, -1650 + 550, -1650 + 550, -1650 + 500, -1700
  • 550, - 550 + 500, - 600 + 500, - 600 + 500, - 600
  • 500, - 600 + 500, -1700 + 500, - 600 + 500, -1650
  • 500, - 600 + 550, -1650 + 500, -1700 + 500, -1700
  • 500, -1700 + 500, - 600 + 500, -1700 + 500, - 600
  • 500, -1650 + 500
    unsigned int rawData[67] = {8750,4450, 500,550, 550,550, 550,600, ...
    unsigned int data = 0xFE0AF5;

Then tried to call the sendNEC function with 32 instead of 24 and it worked! Thanks very much! Now I can have my TV remote on my smartphone! (planning to use bluetooth)

Benur21:
as int can hold up to 2 147 483 648‬. But I will give it a try.

sizeof (int) on AVR is 2 bytes (16 bits). sizeof(int) on ESP and ARM is 4 bytes (32 bits).

gbafamily:
If using an AVR such as Uno, large integer constants may need the UL suffix. For example, 0xFEFA05UL

Adding 'L' or 'UL' is good practice but not strictly necessary. The compiler will upgrade an integer constant to 'long int' if it won't fit in an 'int'.

Benur21:
@johnwasser But all the codes I wrote down have 6 hex (24 bits). Should I still type 28 or 32?
I didn't notice the examples were on the IDE, I have been looking at them at github :stuck_out_tongue:

When you use Serial.print(value, HEX); on the Arduino it does not display leading zeroes. Without looking at the bit count in the received data there was no way of knowing that those (undisplayed) leading zeroes were significant. I figured it was worth checking.