IRRemote transmit and receiver.

IRRemote transmit and receiver.

This page is to Setup and Config IRRemote transmit and receiver.

Hardware and Software

Hardware

IRRemote transmit and receiver.

Software

Arduino IDE

Driver Download : https://github.com/z3t0/Arduino-IRremote

Sanki Notes

    • IR Remote transmit and receiver.

    • Receiver PIN 11

    • Transmit : PIN 3 with 100 Om Transiter

    • Switch : PIN 12 with 1K Transiter

    • And PIN 13 for Signal LEN

IRremote Library

IRremote, by Ken Shirriff, allows you to receive or transmit Infrared Remote Control codes. You can make your projects controlled by a remote, or make them control other devices like televisions and stereo components.

Download: IRremote.zip (modified to work on Teensy and other boards)

Hardware Requirements

For transmitting, a single Infrared LED and resistor are needed. For receiving, an IR receiver module with internal bandpass filter is needed.

TODO: Add part numbers of known-good infrared LEDs and receivers. The LED in this photo is Lumex OED-EL-8L (Digikey 67-1000-ND) and the receiver is probably Sharp GP1UD281YK0F (now discontinued, Digikey 425-1987-ND).

TODO: Test Vishay TSOP39338 receiver (Digikey 751-1390-5-ND). It's very likely to work. Update this photo. Maybe PJRC should sell a known-good LED & receiver pair?

For transmitting, you must connect the LED to a specific pin. The receiver output may be connected to any pin.

Basic Usage

IRremote acts like 2 libraries, one for sending and one for receiving. Usually it's easiest to find the codes to transmit by first using the receiver.

Receiving

IRrecv irrecv(receivePin)

Create the receiver object, using a name of your choice.

irrecv.enableIRIn()

Begin the receiving process. This will enable the timer interrupt which consumes a small amount of CPU every 50 µs.

irrecv.decode(&results)

Attempt to receive a IR code. Returns true if a code was received, or false if nothing received yet. When a code is received, information is stored into "results".

results.decode_type: Will be one of the following: NEC, SONY, RC5, RC6, or UNKNOWN.

results.value: The actual IR code (0 if type is UNKNOWN)

results.bits: The number of bits used by this code

results.rawbuf: An array of IR pulse times

results.rawlen: The number of items stored in the array

irrecv.resume()

After receiving, this must be called to reset the receiver and prepare it to receive another code.

irrecv.blink13(true)

Enable blinking the LED when during reception. Because you can't see infrared light, blinking the LED can be useful while troubleshooting, or just to give visual feedback.

Transmitting

IRsend irsend;

Create the transmit object. A fixed pin number is always used, depending on which timer the library is utilizing.

irsend.sendNEC(IRcode, numBits);

Send a code in NEC format.

irsend.sendSony(IRcode, numBits);

Send a code in Sony format.

irsend.sendRC5(IRcode, numBits);

Send a code in RC5 format.

irsend.sendRC6(IRcode, numBits);

Send a code in RC6

irsend.sendRaw(rawbuf, rawlen, frequency);

Send a raw code. Normally you would obtain the contents of rawbuf and rawlen by using the receiver many times and averaging the results. Some adjustments may be necessary for best performance. The frequency is the expected bandpass filter frequency at the receiver, where 38 is the most commonly used.

Examples

This example is read signal to RAW and Send out

          1. /* IRrecord: record and play back IR signals as a minimal

          2. * An IR detector/demodulator must be connected to the input RECV_PIN.

          3. * An IR LED must be connected to the output PWM pin 3.

          4. * A button must be connected to the input BUTTON_PIN; this is the

          5. * send button.

          6. * A visible LED can be connected to STATUS_PIN to provide status.

          7. *

          8. * The logic is:

          9. * If the button is pressed, send the IR code.

          10. * If an IR code is received, record it.

          11. *

          12. * Version 0.11 September, 2009

          13. * Copyright 2009 Ken Shirriff

          14. * http://arcfn.com

          15. */

          16. #include <IRremote.h>

          17. int RECV_PIN = 11;

          18. int BUTTON_PIN = 12;

          19. int STATUS_PIN = 13;

          20. // Pin 3 for Send IR

          21. IRrecv irrecv(RECV_PIN);

          22. IRsend irsend;

          23. decode_results results;

          24. void setup()

          25. {

          26. Serial.begin(9600);

          27. irrecv.enableIRIn(); // Start the receiver

          28. pinMode(BUTTON_PIN, INPUT);

          29. pinMode(STATUS_PIN, OUTPUT);

          30. }

          31. // Storage for the recorded code

          32. int codeType = -1; // The type of code

          33. unsigned long codeValue; // The code value if not raw

          34. unsigned int rawCodes[RAWBUF]; // The durations if raw

          35. int codeLen; // The length of the code

          36. int toggle = 0; // The RC5/6 toggle state

          37. // Stores the code for later playback

          38. // Most of this code is just logging

          39. void storeCode(decode_results *results) {

          40. codeType = results->decode_type;

          41. int count = results->rawlen;

          42. if (codeType == UNKNOWN) {

          43. Serial.println("Received unknown code, saving as raw :: ");

          44. //Serial.println("");

          45. codeLen = results->rawlen - 1;

          46. // To store raw codes:

          47. // Drop first value (gap)

          48. // Convert from ticks to microseconds

          49. // Tweak marks shorter, and spaces longer to cancel out IR receiver distortion

          50. for (int i = 1; i <= codeLen; i++) {

          51. if (i % 2) {

          52. // Mark

          53. rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK - MARK_EXCESS;

          54. Serial.print(" m");

          55. }

          56. else {

          57. // Space

          58. rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK + MARK_EXCESS;

          59. Serial.print(" s");

          60. }

          61. Serial.print(rawCodes[i - 1], DEC);

          62. //Serial.println(rawCodes[i - 1], HEX);

          63. }

          64. //Serial.println("");

          65. //Serial.println("-----END----");

          66. }

          67. else {

          68. if (codeType == NEC) {

          69. Serial.print("Received NEC: ");

          70. if (results->value == REPEAT) {

          71. // Don't record a NEC repeat value as that's useless.

          72. Serial.println("repeat; ignoring.");

          73. return;

          74. }

          75. }

          76. else if (codeType == SONY) {

          77. Serial.print("Received SONY: ");

          78. }

          79. else if (codeType == PANASONIC) {

          80. Serial.print("Received PANASONIC: ");

          81. }

          82. else if (codeType == JVC) {

          83. Serial.print("Received JVC: ");

          84. }

          85. else if (codeType == RC5) {

          86. Serial.print("Received RC5: ");

          87. }

          88. else if (codeType == RC6) {

          89. Serial.print("Received RC6: ");

          90. }

          91. else {

          92. Serial.print("Unexpected codeType ");

          93. Serial.print(codeType, DEC);

          94. Serial.println("");

          95. }

          96. Serial.println(results->value, HEX);

          97. codeValue = results->value;

          98. codeLen = results->bits;

          99. }

          100. }

          101. void sendCode(int repeat) {

          102. if (codeType == NEC) {

          103. if (repeat) {

          104. irsend.sendNEC(REPEAT, codeLen);

          105. Serial.println("Sent NEC repeat");

          106. }

          107. else {

          108. irsend.sendNEC(codeValue, codeLen);

          109. Serial.print("Sent NEC ");

          110. Serial.println(codeValue, HEX);

          111. }

          112. }

          113. else if (codeType == SONY) {

          114. irsend.sendSony(codeValue, codeLen);

          115. Serial.print("Sent Sony ");

          116. Serial.println(codeValue, HEX);

          117. }

          118. else if (codeType == PANASONIC) {

          119. irsend.sendPanasonic(codeValue, codeLen);

          120. Serial.print("Sent Panasonic");

          121. Serial.println(codeValue, HEX);

          122. }

          123. else if (codeType == JVC) {

          124. irsend.sendPanasonic(codeValue, codeLen);

          125. Serial.print("Sent JVC");

          126. Serial.println(codeValue, HEX);

          127. }

          128. else if (codeType == RC5 || codeType == RC6) {

          129. if (!repeat) {

          130. // Flip the toggle bit for a new button press

          131. toggle = 1 - toggle;

          132. }

          133. // Put the toggle bit into the code to send

          134. codeValue = codeValue & ~(1 << (codeLen - 1));

          135. codeValue = codeValue | (toggle << (codeLen - 1));

          136. if (codeType == RC5) {

          137. Serial.print("Sent RC5 ");

          138. Serial.println(codeValue, HEX);

          139. irsend.sendRC5(codeValue, codeLen);

          140. }

          141. else {

          142. irsend.sendRC6(codeValue, codeLen);

          143. Serial.print("Sent RC6 ");

          144. Serial.println(codeValue, HEX);

          145. }

          146. }

          147. else if (codeType == UNKNOWN /* i.e. raw */) {

          148. // Assume 38 KHz

          149. //irsend.sendRaw(rawCodes, codeLen, 38);

          150. irsend.sendRaw(rawCodes, sizeof(rawCodes) / sizeof(rawCodes[0]), 38);

          151. Serial.println("Sent raw");

          152. for (int i = 1; i <= codeLen; i++) {

          153. Serial.print(rawCodes[i - 1], DEC);

          154. }

          155. Serial.println("");

          156. }

          157. }

          158. int lastButtonState;

          159. void loop() {

          160. // If button pressed, send the code.

          161. int buttonState = digitalRead(BUTTON_PIN);

          162. if (lastButtonState == HIGH && buttonState == LOW) {

          163. Serial.println("Released");

          164. irrecv.enableIRIn(); // Re-enable receiver

          165. }

          166. if (buttonState) {

          167. Serial.println("Pressed, sending");

          168. digitalWrite(STATUS_PIN, HIGH);

          169. sendCode(lastButtonState == buttonState);

          170. digitalWrite(STATUS_PIN, LOW);

          171. delay(50); // Wait a bit between retransmissions

          172. }

          173. else if (irrecv.decode(&results)) {

          174. digitalWrite(STATUS_PIN, HIGH);

          175. storeCode(&results);

          176. irrecv.resume(); // resume receiver

          177. digitalWrite(STATUS_PIN, LOW);

          178. }

          179. lastButtonState = buttonState;

          180. }