Samsung IR remote basic code check please

I am trying to use my Arduino to turn on/off a Samsung TV. I am not at this time able to actually test it on the TV. From much reading and attempting to understand, I have the following code.

//Turn Samsung TV on/off repeatedly to test program. IR LED connected to pin 3.

#include <IRremote.h>

#define POWER         0xE0E040BF            //from IRrecvDemo, Ken Shirriff
#define SAMSUNG_BITS  32 

IRsend irsend;

void setup()
{
  pinMode (3, OUTPUT);  //output as used in library
}

void loop() {

  irsend.sendSAMSUNG(POWER, SAMSUNG_BITS); 

  delay (5000);

}//end of loop

Can someone with experience please tell me if this is likely to work. My expectation is that it should turn the TV on/off.

The IR LED appears to flash.

Any help would be much appreciated.

Weedpharma

All looks reasonable with a few caveats:

  1. I presume the power code 0xE0E040BF is correct ??
  2. irsend.sendSAMSUNG is an extension to IRremote & you have the version with SAMSUNG support
  3. Normally, the power button will toggle between on & off, but this may not always be the case.
  4. The code you posted will send the signal every 5 secs.
  5. Note: the send pin can be different on he various Arduino models. Mostly, it is pin 3.

FYI: on our samsung TV the protocol used is 32 bit NEC and the code for power is 0xF4BA2988.

So make sure you have the correct protocol for your TV.

Thanks for the responses.

The hex code used was given using Ken's example sketch. My main sketch also recognises the code when sent from the remote.

I have installed the library and tested that it is in use for IRsend for Samsung by inserting a line into the library to output a message to serial when it is used.

It is sending something to the IR diode as I can see it via my mobile phone.

The loop example is simply to test the code in its simplest form. Once found to work, it will be used in a practical sketch.

I was able to test it during the weekend and it did not work. The test TV is away from my home.

Weedpharma

weedpharma: The hex code used was given using Ken's example sketch. My main sketch also recognises the code when sent from the remote.

Does IRremote recognise the signal as Samsung or does it just provide a HEX value?

IRremote: IRrecvDemo only returns a hex value.

I have used this program to identify the codes to use for other keys such as up and down arrow etc. I have then used the values returned, in my main program to receive the button press from the remote. This works as expected. My sketch also accepts the code for power and goes into the function.

The next step is to have the sketch control the TV. Hence my basic sketch to prove it works. Unfortunately it doesn't !

Weedpharma

Hence my basic sketch to prove it works. Unfortunately it doesn't !

Thats may be because you are sending as SAMSUNG and it may not be the correct protocol.

The sketch probably works, but the mistake could be that you are assuming your protocol is the same as the Samsung one in the library. There can be many varients of protocols even within the same manufaturer. They only guarantee that a remote works with the 'paired' device.

Try using the sendRAW command to send the signal and if that doesn't work post the RAW output from IRremote [format is like *RAW (xx): 9000,3000,600,600....*etc] and I will look into it for you.

Thank you for your offer of help. I will try to do as you suggest over the next week or so. Things are a little bit busy!

Weedpharma

Below is the output from IRrecvDump for power button on the Samsung remote.

E0E040BF E0E040BF (32 bits)

Raw (68): 14672 4550 -4400 600 -1650 550 -1650 600 -1650 550 -550 600 -500 600 -550 550 -550 600 -500 600 -1650 600 -1600 600 -1650 550 -550 600 -500 600 -550 600 -500 600 -500 650 -450 650 -1600 600 -500 650 -450 650 -500 600 -500 600 -500 600 -550 600 -1600 600 -500 650 -1600 650 -1550 650 -1600 650 -1550 650 -1600 650 -1600 600

How do I treat the negative numbers in the array for use in irsend.sendRaw(arrayName,68,38)?

I did a number of dumps and they where different but very similar.

Weedpharma

This should work for you.

/*
Automatically Generated by AnalysIR - Batch Export Utility
Registered to: xxxxxxxx
Session History
Type : Key : Value : Bits
0 : RAW :  :  : 32
*/

// NB: Not all protocols are supported by IRremote or IRLib. You may need to edit the code below manually
// Automatically Generated by AnalysIR for xxxxxxxx, visit http://www.AnalysIR.com or email info@....... for further details
int khz=38; //NB Change this default value as neccessary to the correct modulation frequency

unsigned int Signal_0_0[] = {4550,4400,600,1650,550,1650,600,1650,550,550,600,500,600,550,550,550,600,500,600,1650,600,1600,600,1650,550,550,600,500,600,550,600,500,600,500,650,450,650,1600,600,500,650,450,650,500,600,500,600,500,600,550,600,1600,600,500,650,1600,650,1550,650,1600,650,1550,650,1600,650,1600,600}; //AnalysIR Batch Export - RAW

irsend.sendRaw(Signal_0_0, sizeof(Signal_0_0)/sizeof(int), khz); //AnalysIR Batch Export - RAW
 // AnalysIR IR Protocol: RAW, Key:

Notes: 1. Try using the IRLib library as this seems to match the NECx protocol & you will avoid having to deal with RAW mode. 2. The first 14672 in the dump you posted is a bug with IRremote and should be ignored/deleted 5. The correct valid times are 4500,560 & 1690 - so you will get better performance if you replace the values in the above with these.

I did the same with my Samsung TV, using the IRremote library and it works well.

Raw (68): 14672 4550 -4400 600 -1650 550 -1650 600 -1650 550 -550 600 -500 600 -550 550 -550 600 -500 600 -1650 600 -1600 600 -1650 550 -550 600 -500 600 -550 600 -500 600 -500 650 -450 650 -1600 600 -500 650 -450 650 -500 600 -500 600 -500 600 -550 600 -1600 600 -500 650 -1600 650 -1550 650 -1600 650 -1550 650 -1600 650 -1600 600

How do I treat the negative numbers in the array for use in irsend.sendRaw(arrayName, 68, 38)?

Exactly as other people already said, this library don't handle the Samsung protocol exactly, so you need to use the RAW data. To treat the RAW data the first thing to do is to remove the first numeric-value AND convert all negatives to positive values (just remove the minus signal).

I did a number of dumps and they where different but very similar.

You are right, the RAW data seens a bit different each time, but if you get the the full code (normaly 68 length for Samsung) it will work normally.

Here is a nice tutorial I used when I did my code.

http://as3breeze.com/arduino-sending-samsung-ir-codes/

the RAW data seens a bit different each time,

The reason for this is because IRremote just measures to 50 uSecs accuracy, so all times will be a multiple of 50. That is why I provided the correct timings earlier.

I believe, the IRLib libarary allows more accurate timing and as I mentioned implements this protocol as NECx, so no real need for RAW.

FYI: here is what your signal looks like.

Thank you for your help. I will try it in a week when I am at the TV to be controlled.

Weedpharma

It works!! Thank you for your help.

Using the values for raw as supplied by analysIR, it worked as required.

The information supplied by analysIR and Arank is very much appreciated and will be kept for future reference.

Weedpharma

I spoke too soon.

The code works perfectly as used in

//Turn Samsung TV on/off repeatedly to test program.
//IR LED connected to pin 3.

#include <IRremote.h>

unsigned int power[] = {4550,4400,600,1650,550,1650,600,1650,
550,550,600,500,600,550,550,550,600,500,600,1650,600,1600,600,
1650,550,550,600,500,600,550,600,500,600,500,650,450,650,1600,
600,500,650,450,650,500,600,500,600,500,600,550,600,1600,600,
500,650,1600,650,1550,650,1600,650,1550,650,1600,650,1600,600};

IRsend irsend;

void setup()
{
  pinMode (3, OUTPUT);  //output used in library
}

void loop() {

      irsend.sendRaw(power,68,38);
      
  delay (5000);

}//end of loop

But not when used with receiving a signal from the remote. My long sketch reads the input from the remote and does actions dependent on the key pressed. It all worked correctly until I added the irsend.sendRaw statement in a function.

I have removed all of the program that is not relevant to the problem and have this code.

#define power       0xE0E040BF    //for receiver

#include <IRremote.h>             // http://arcfn.com 

//raw data for IR Tx;
unsigned int powerIRout[] = {
  4550,4400,600,1650,550,1650,600,1650,550,550,600,500,
  600,550,550,550,600,500,600,1650,600,1600,600,1650,550,550,600,500,600,550,
  600,500,600,500,650,450,650,1600,600,500,650,450,650,500,600,500,600,500,600,
  550,600,1600,600,500,650,1600,650,1550,650,1600,650,1550,650,1600,650,1600,600};

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

void setup () {
  Serial.begin (9600);
  irrecv.enableIRIn();      // Start the IR receiver
  pinMode (3, OUTPUT);      //IR LED
}

void loop (){
  if (irrecv.decode(&results))   //read IR    
  {    
      sendIR ();
  }
  irrecv.resume();           // Resume decoding (necessary!) 
  delay (200);               
}   

void sendIR ()   //function to output "POWER" code to IR diodes. 
{  
  Serial.println ("send IR out");

  irsend.sendRaw(powerIRout,68,38); 

  Serial.println ("sent");
}

The function sendIR works once then locks up, reset needed to repeat. Comment out the irsend.sendRaw line and it works repeatedly each time I press the remote.

It appears that the irsend interferes with the irreceive.

The basic code was derived from the examples in the library.

Your assistance would be appreciated.

weedpharma

void loop (){
  if (irrecv.decode(&results))   //read IR    
  {    
      sendIR ();
  }
  irrecv.resume();           // Resume decoding (necessary!) 
  delay (200);               
}

I'm not sure (because I never tried to do something like this). But for me the first problem is that you are trying to send the signal in the middle off the reciving function. Try to send only when you end the reciving function (I presume the irrecv.resume() is the end of it). If needed you can store it in a char array (or whatever).

I had some incompatibility problems like this with another things and this was always my first approach, and many times it worked.

One answer can be found in point 8, in the 'pitfalls' article linked in my signature.

You must enable receiving after every send (irrecv.enableIRIn();)

Might be a good idea to read the full article :)

Arank, sendIR is not in the middle of a function. The lines before and after are separate functions.

AnalysIR, thanks, I was not aware of this. I will give it a go.

Weedpharma

However, you should really have the 'resume' within the if statement & the delay is not required (it slows down reception of a signal).

(ref: your example code)