RPi Quadcopter blog

RPi Quadcopter blog
Click to open

May 23, 2011

Receiving and sending IR with Arduino

Sending IR with Arduino means that you can control various different devices in your home. Controlling different devices with IR can be part of your Arduino smart home.

Reading the IR signals is fairly easy. All you need is a IR receiver. The most commonly used infrared carrier signal is 38 kHz, but it should still work fine, if the receiver and sender use different frequencies.


Receiver:
38khz

I used IRremote library to send and receive infrared signals. You can download and read more instructions about IRremote library here.

Use the IRrecieveDump -demo to dump all the data read from your remotecontroller. If the data could be identified as RC5, Sony or NEC it will also be very simple to send.

To send IR, you need an Infrared LED with a resistor. You don't want to burn your LED so use this counter to calculate the best resistor for it.


IR-Led



Example:

Start the IRrecieveDump -demo and open serial monitor.
Point your remote towards the receiver and press a button.
The program should print out for example the NEC -code and the raw data.
The NEC -code should look like this: "FF906F".

Now you can try sending the same code by using sendNEC() method:
Irsend.sendNEC(0xFF906FF, 38); 

UPDATE:
the 38 above is wrong. The second parameter is the lenght in bits. The Nec function will always send 38khz. Correct way is:

Irsend.sendNEC(0xFF906FF, 32);

Because the code you are sending is a HEX code you need to put the "0x" before it.
"38" in the constructor means that you want to send it with 38khz carrier frequensy.


Some devices use their own protocols such as Samsung, but you can get the raw data from them. To clean the raw data you get from the dump -demo, you need to erase the first number, then convert all negative numbers to positive and place commas between the numbers.

Here's an example:

Raw data: 4802, -620, 500, -420, 600, -440....

Sending:

unsigned int[68] power_ON ={620,500,420,600,440... ...};
Irsend.sendRaw(power_ON, 68, 38);

68 is the length of the unsigned integer.

18 comments:

  1. Hey,
    Nice post..The IRRemote library is built for atmega 168/328..but not for atmega8.Is there a way i can tweak the library for it to work with atmega8.Or is there any other similar IR remote library i can use with arduino.Basically all i want to do is interface a TSOP1738 ( IR Receiver ) with an arduino and the library should give me different outputs for different buttons pressed on the remote so i can differentiate between the different buttons in the remote and accordingly perform certain actions.
    Thanks..

    ReplyDelete
  2. This helped me a lot before I found the IRreceive library.
    http://www.ladyada.net/learn/sensors/ir.html

    ReplyDelete
  3. @ville valta
    thanks a lot..that links seems useful..checking it out..

    ReplyDelete
  4. Thank you very much for sharing. This got me where I needed to be on sending raw IR using the Arduino library you mentioned.

    ReplyDelete
  5. I'm very pleased to hear that! And thanks a lot for leaving a comment :)

    ReplyDelete
    Replies
    1. hello
      i want to control led with remote in arduino
      i m using atmage8
      plz send me program

      Delete
  6. hello
    i want to control led with remote in arduino
    i m using atmage8
    plz send me program

    ReplyDelete
    Replies
    1. Hi I have the same query. To interface TSOP1738 with ATMega8.

      Please help me if you got a solution.
      Thanks.

      Delete
  7. Thank you ! i finaly got my samsung tv to work,,,, any chance you could help with DISh network? i have tried every examble possible i can find , it uses the 20.0 ir remote i have tried raw and no luck

    ReplyDelete
  8. Thank you!!!! Ken Shirriff should have posed something this useful into his blog too!!

    ReplyDelete
  9. Thanks to your application I am able to control my AC from the internet with an android application!

    Here is the tutorial for those interested (its in spanish though)

    http://techcontostones.blogspot.com/2013/04/arduino-android-como-controlar-un-aire.html

    ReplyDelete
  10. You said ""38" in the constructor means that you want to send it with 38khz carrier frequensy."

    I think this is wrong. The sendNEC function is declared this way in IRRemote.h:

    void sendNEC(unsigned long data, int nbits);

    As you see that parameter (nbits) is the number of bits to send. I think this is the same number reported when you capture the code with the IRRecvDump example. As in this log:

    FF30CF
    Decoded NEC: FF30CF (32 bits)
    Raw (68): -28998 9100 -4400 650 -500 600 -500 650 -450 650 -500 600 -550 600 -500 650 -450 650 -500 600 -1650 600 -1650 600 -1650 600 -1600 650 -1600 650 -1600 600 -1650 600 -1600 650 -500 600 -550 600 -1650 600 -1650 600 -500 600 -500 650 -500 600 -550 600 -1600 650 -1600 600 -500 650 -500 600 -1650 600 -1650 600 -1650 600 -1600 650


    To send this command I had to use:

    irsend.sendNEC(0xFF30CF, 32);


    ReplyDelete
  11. Hi, i'm planning to control my sharp air conditioner over my android. But the problem is I cant find the correct decoding mechanism (it's detected as unknown if i'm using IRdump). And i've tried to use your way (samsung). but still can't work.

    any workaround for this? thanks

    ReplyDelete
  12. @Ville valta
    laita mulle meiliä, tarviin vähän apua tähän liittyen

    ReplyDelete
  13. Thank you very much! I used the method you described to control a toy robot :D

    ReplyDelete
  14. Using the IRremote library doesn't seem to work for the Arduino UNO rev. 3
    Error: uint8_t recvpi, " no rawlen"??

    ReplyDelete
  15. I've got dis interesting site for dis. Try it.
    http://vaaiibhav.me/how-to-send-ir-signal-with-arduino/

    ReplyDelete