How do i send raw data with arduino? I'm trying to make a tv remote

The code i used to decompile my tv remote:

//------------------------------------------------------------------------------
// Include the IRremote library header
//
#include <IRremote.h>

//------------------------------------------------------------------------------
// Tell IRremote which Arduino pin is connected to the IR Receiver (TSOP4838)
//
int recvPin = 11;
IRrecv irrecv(recvPin);

//+=============================================================================
// Configure the Arduino
//
void  setup ( )
{
  Serial.begin(9600);   // Status message will be sent to PC at 9600 baud
  irrecv.enableIRIn();  // Start the receiver
}

//+=============================================================================
// Display IR code
//
void  ircode (decode_results *results)
{
  // Panasonic has an Address
  if (results->decode_type == PANASONIC) {
    Serial.print(results->address, HEX);
    Serial.print(":");
  }

  // Print Code
  Serial.print(results->value, HEX);
}

//+=============================================================================
// Display encoding type
//
void  encoding (decode_results *results)
{
  switch (results->decode_type) {
    default:
    case UNKNOWN:      Serial.print("UNKNOWN");       break ;
    case NEC:          Serial.print("NEC");           break ;
    case SONY:         Serial.print("SONY");          break ;
    case RC5:          Serial.print("RC5");           break ;
    case RC6:          Serial.print("RC6");           break ;
    case DISH:         Serial.print("DISH");          break ;
    case SHARP:        Serial.print("SHARP");         break ;
    case JVC:          Serial.print("JVC");           break ;
    case SANYO:        Serial.print("SANYO");         break ;
    case MITSUBISHI:   Serial.print("MITSUBISHI");    break ;
    case SAMSUNG:      Serial.print("SAMSUNG");       break ;
    case LG:           Serial.print("LG");            break ;
    case WHYNTER:      Serial.print("WHYNTER");       break ;
    case AIWA_RC_T501: Serial.print("AIWA_RC_T501");  break ;
    case PANASONIC:    Serial.print("PANASONIC");     break ;
    case DENON:        Serial.print("Denon");         break ;
  }
}

//+=============================================================================
// Dump out the decode_results structure.
//
void  dumpInfo (decode_results *results)
{
  // Check if the buffer overflowed
  if (results->overflow) {
    Serial.println("IR code too long. Edit IRremoteInt.h and increase RAWBUF");
    return;
  }

  // Show Encoding standard
  Serial.print("Encoding  : ");
  encoding(results);
  Serial.println("");

  // Show Code & length
  Serial.print("Code      : ");
  ircode(results);
  Serial.print(" (");
  Serial.print(results->bits, DEC);
  Serial.println(" bits)");
}

//+=============================================================================
// Dump out the decode_results structure.
//
void  dumpRaw (decode_results *results)
{
  // Print Raw data
  Serial.print("Timing[");
  Serial.print(results->rawlen-1, DEC);
  Serial.println("]: ");

  for (int i = 1;  i < results->rawlen;  i++) {
    unsigned long  x = results->rawbuf[i] * USECPERTICK;
    if (!(i & 1)) {  // even
      Serial.print("-");
      if (x < 1000)  Serial.print(" ") ;
      if (x < 100)   Serial.print(" ") ;
      Serial.print(x, DEC);
    } else {  // odd
      Serial.print("     ");
      Serial.print("+");
      if (x < 1000)  Serial.print(" ") ;
      if (x < 100)   Serial.print(" ") ;
      Serial.print(x, DEC);
      if (i < results->rawlen-1) Serial.print(", "); //',' not needed for last one
    }
    if (!(i % 8))  Serial.println("");
  }
  Serial.println("");                    // Newline
}

//+=============================================================================
// Dump out the decode_results structure.
//
void  dumpCode (decode_results *results)
{
  // Start declaration
  Serial.print("unsigned int  ");          // variable type
  Serial.print("rawData[");                // array name
  Serial.print(results->rawlen - 1, DEC);  // array size
  Serial.print("] = {");                   // Start declaration

  // Dump data
  for (int i = 1;  i < results->rawlen;  i++) {
    Serial.print(results->rawbuf[i] * USECPERTICK, DEC);
    if ( i < results->rawlen-1 ) Serial.print(","); // ',' not needed on last one
    if (!(i & 1))  Serial.print(" ");
  }

  // End declaration
  Serial.print("};");  // 

  // Comment
  Serial.print("  // ");
  encoding(results);
  Serial.print(" ");
  ircode(results);

  // Newline
  Serial.println("");

  // Now dump "known" codes
  if (results->decode_type != UNKNOWN) {

    // Some protocols have an address
    if (results->decode_type == PANASONIC) {
      Serial.print("unsigned int  addr = 0x");
      Serial.print(results->address, HEX);
      Serial.println(";");
    }

    // All protocols have data
    Serial.print("unsigned int  data = 0x");
    Serial.print(results->value, HEX);
    Serial.println(";");
  }
}

//+=============================================================================
// The repeating section of the code
//
void  loop ( )
{
  decode_results  results;        // Somewhere to store the results

  if (irrecv.decode(&results)) {  // Grab an IR code
    dumpInfo(&results);           // Output the results
    dumpRaw(&results);            // Output the results in RAW format
    dumpCode(&results);           // Output the results as source code
    Serial.println("");           // Blank line between entries
    irrecv.resume();              // Prepare for the next value
  }
}

This is version 2.2.3 of IRremote library.
This is my TV remote decompiled:

Encoding  : RC6
Code      : C (20 bits)
Timing[41]: 
     +2600, - 950     + 400, - 900     + 400, - 450     + 450, - 450
     + 450, - 900     + 850, - 450     + 450, - 400     + 450, - 450
     + 450, - 450     + 400, - 450     + 450, - 450     + 450, - 450
     + 400, - 450     + 450, - 450     + 450, - 450     + 400, - 450
     + 450, - 450     + 850, - 450     + 450, - 900     + 450, - 400
     + 450
unsigned int  rawData[41] = {2600,950, 400,900, 400,450, 450,450, 450,900, 850,450, 450,400, 450,450, 450,450, 400,450, 450,450, 450,450, 400,450, 450,450, 450,450, 400,450, 450,450, 850,450, 450,900, 450,400, 450};  // RC6 C
unsigned int  data = 0xC;

Does anyone know how i can send raw data to basically power on my tv? Thanks in advance for the answers :smiley: .

Please edit your post to add code tags, as described in the "How to get the best out of the forum" post.

send raw data to basically power on my tv

Send the appropriate "power on" command, which depends on the TV manufacturer and model.

I modified the post in order to make it more readable, im a complete beginner on this, can you tell me where i can find the "power on" command? I can probably ask my parents about the TV Model, its a Phillips TV.

You need to know the exact TV model. For many of them, the codes are documented on various web sites.

On the other hand, if you use the IRremote library to record the TV's remote while it is sending the "power on" command, enter the raw codes into your program.

To learn how, spend some time studying the IRremote library documentation here: GitHub - Arduino-IRremote/Arduino-IRremote: Infrared remote library for Arduino: send and receive infrared signals with multiple protocols

I don't know if you read the last part of my post, i already used the IRremote library to get the raw codes, what i need is the program to put them in, i can't really do that, since im a beginner, that's why i made a post about this. Thanks for the help tho.

Yes, you can, but you will need to study the documentation carefully and possibly, other helpful tutorials on the web.

I don't know if you read the last part of my post

I did, but you failed to make clear what those data represent.

I tried my best in the past days looking thru tutorials, even tried to look at documents, but i couldn't do it, if you don't want to help me to make the script someone else will eventually help me out. Thanks for all the info tho.

For a beginner, you have chosen a very challenging project. We strongly recommend to start at a lower level and work your way up.

If you don't want to learn Arduino, one option is to post on the Jobs and Paid Consultancy forum section and be prepared to pay for the help. You can use the flag button on the post to ask a moderator to move it to that section.

What project do you raccoment to start off with? And which ones to work my way up?

The Arduino IDE itself comes with lots of examples of simple but popular applications, which help you learn the programming language and special features of the Arduino. Read a voltage, a temperature, light levels, operate lights and motors, send messages, etc.

Also spend some time on the forum browsing other people's projects and questions -- all very educational!

Alright thanks!

Why? If IRrecv said the Power button is an RC6 (protocol invented by Philips) command, with key code "C", I think you could just use that with the send() functions, you don't need raw data.
Try something like this:

myIR.sendRC6(0xC, 20);

What do i need to attach to my arduino to make it work? Also i tried uploading the code and this error showed up:

error: 'myIR' does not name a type
 myIR.sendRC6(0xC, 20);
 ^~~~

exit status 1

Compilation error: 'myIR' does not name a type

Huh, yep, I said "try something like this" not "try this".... That "myIR" should be replaced by the name you give to IRsend type variable.

Just to clarify (again, this is just an example...):

#include <IRremote.h>

IRsend irsend;

void setup() {
}

void loop() {
    irsend.sendRC6(0xC, 20);
    delay(10000); // Send Power button every 30 seconds
}

Ill try to see if i can make it work, but since im a complete beginner, do i need to attach anything to my arduino to make it work? I have the Arduino Uno R3 Project. Thanks for the help.

You obviously need an IR LED connected to the output pin. Please note IR leds require more current than the one an Arduino pin can give, more than standard LEDs, so you need to drive it with a transistor like this one:


For more information about IR reading and sending, see THIS nice Adafruit tutorial.

Ever tried the examples of this library?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.