You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://github.com/Arduino-IRremote/Arduino-IRremote/commits/master)
@@ -20,6 +20,7 @@ This library enables you to send and receive using infra-red signals on an Ardui
20
20
+[Example](#example)
21
21
*[Do not want to convert your 2.x program and use the 3.x library version?](#do-not-want-to-convert-your-2x-program-and-use-the-3x-library-version)
22
22
*[How to convert old MSB first 32 bit IR data codes to new LSB first 32 bit IR data codes](#how-to-convert-old-msb-first-32-bit-ir-data-codes-to-new-lsb-first-32-bit-ir-data-codes)
23
+
-[Using the new *.hpp files](#using-the-new-hpp-files)
23
24
-[Receiving IR codes](#receiving-ir-codes)
24
25
*[Minimal NEC receiver](#minimal-nec-receiver)
25
26
-[Sending IR codes](#sending-ir-codes)
@@ -38,8 +39,9 @@ This library enables you to send and receive using infra-red signals on an Ardui
38
39
-[Timer and pin usage](#timer-and-pin-usage)
39
40
+[Incompatibilities to other libraries and Arduino commands like tone() and analogWrite()](#incompatibilities-to-other-libraries-and-arduino-commands-like-tone-and-analogwrite)
40
41
+[Hardware-PWM signal generation for sending](#hardware-pwm-signal-generation-for-sending)
41
-
+[Why do we use 33% duty cycle](#why-do-we-use-33-duty-cycle)
42
-
42
+
+[Why do we use 33% duty cycle for sending](#why-do-we-use-33-duty-cycle-for-sending)
43
+
44
+
-[How we decode signals](#how-we-decode-signals)
43
45
-[NEC encoding diagrams](#nec-encoding-diagrams)
44
46
-[Quick comparison of 4 Arduino IR receiving libraries](#quick-comparison-of-4-arduino-ir-receiving-libraries)
45
47
-[Revision History](#revision-history)
@@ -170,6 +172,11 @@ Example:
170
172
0x40802CD3 is binary 01000000100000000010110011010011.<br/>
171
173
If you read the first binary sequence backwards (right to left), you get the second sequence.
172
174
175
+
# Using the new *.hpp files
176
+
In order to support [compile options](#compile-options--macros-for-this-library) more easily, the line `#include <IRremote.h>` must be changed to `#include <IRremote.hpp>`, but only in your **main program (.ino file)**, like it is done in the examples.<br/>
177
+
In **all other files** you must use `#include <IRremoteInt.h>`, otherwise you will get tons of **"multiple definition"** errors.
178
+
Be careful to define these 3 macros `RAW_BUFFER_LENGTH` and `IR_SEND_PIN` and `SEND_PWM_BY_TIMER` in IRremoteInt.h consistent with the definitions in the .ino file!
179
+
173
180
# Receiving IR codes
174
181
Check for **available data** can be done by `if (IrReceiver.decode()) {`. This also decodes the received data.
175
182
After successful decoding, the IR data is contained in the IRData structure, available as `IrReceiver.decodedIRData`.
@@ -220,7 +227,7 @@ There are some other solutions to this on more powerful processors,
220
227
since one IR diode requires only 1.5 volt.
221
228
- The line \#include "ATtinySerialOut.h" in PinDefinitionsAndMore.h (requires the library to be installed) saves 370 bytes program space and 38 bytes RAM for **Digispark boards** as well as enables serial output at 8MHz.
222
229
- The default software generated PWM has **problems on AVR running with 8 MHz**. The PWM frequency is around 30 instead of 38 kHz and RC6 is not reliable. You can switch to timer PWM generation by `#define SEND_PWM_BY_TIMER`.
223
-
- If you require **IRremote.hpp in multiple files** / want to **avoid "multiple definition" error**, use `#include <IRremote.hpp>` only in one file, e.g. the .ino file (the file containing main()) and use `#include <IRremoteInt.h>` **in all other files**. Be careful to define these 3 macros `RAW_BUFFER_LENGTH` and `IR_SEND_PIN` and `SEND_PWM_BY_TIMER` in IRremoteInt.h consistent with the definitions in the .ino file!
230
+
224
231
225
232
# Handling unknown Protocols
226
233
## Disclaimer
@@ -305,14 +312,14 @@ The file *acLG.h* contains the command documentation of the LG air conditioner I
305
312
### ReceiverTimingAnalysis
306
313
This example analyzes the signal delivered by your IR receiver module.
307
314
Values can be used to determine the stability of the received signal as well as a hint for determining the protocol.<br/>
308
-
It also computes the MARK_EXCESS_MICROS value, which is the extension of the mark (pulse) duration introduced by the IR receiver module.<br/>
315
+
It also computes the `MARK_EXCESS_MICROS` value, which is the extension of the mark (pulse) duration introduced by the IR receiver module.<br/>
309
316
It can be tested online with [WOKWI](https://wokwi.com/arduino/projects/299033930562011656).
310
317
Click on the receiver while simulation is running to specify individual NEC IR codes.
311
318
312
319
# Compile options / macros for this library
313
320
To customize the library to different requirements, there are some compile options / macros available.<br/>
314
-
Modify it by commenting them out or in, or change the values if applicable.
315
-
Or define the macro with the -D compiler option for global compile (the latter is not possible with the Arduino IDE, so consider using [Sloeber](https://eclipse.baeyens.it).
321
+
Most macros must be defined in your program before the line `#include <IRremote.hpp>` to take effect.
322
+
Modify them by enabling / disabling them, or change the values if applicable.
316
323
317
324
| Name | File | Default value | Description |
318
325
|-|-|-|-|
@@ -333,9 +340,9 @@ Or define the macro with the -D compiler option for global compile (the latter i
333
340
| `MICROS_PER_TICK` | IRremoteInt.h | 50 | Resolution of the raw input buffer data. Corresponds to 2 pulses of each 26.3 µs at 38 kHz. |
334
341
| `IR_USE_AVR_TIMER*` | private/IRTimer.hpp | | Selection of timer to be used for generating IR receiving sample interval. |
335
342
|-|-|-|-|
336
-
| `IR_INPUT_PIN` | TinyIRReceiver.h | 2 | The pin number for TinyIRReceiver IR input, which gets compiled in. |
337
-
| `IR_FEEDBACK_LED_PIN` | TinyIRReceiver.h | `LED_BUILTIN` | The pin number for TinyIRReceiver feedback LED, which gets compiled in. |
338
-
| `NO_LED_FEEDBACK_CODE` | TinyIRReceiver.h | disabled | Enable it to disable the feedback LED function. Saves 14 bytes program space. |
343
+
| `IR_INPUT_PIN` | Before `#include <TinyIRReceiver.hpp>` | 2 | The pin number for TinyIRReceiver IR input, which gets compiled in. |
344
+
| `IR_FEEDBACK_LED_PIN` | Before `#include <TinyIRReceiver.hpp>` | `LED_BUILTIN` | The pin number for TinyIRReceiver feedback LED, which gets compiled in. |
345
+
| `NO_LED_FEEDBACK_CODE` | Before `#include <TinyIRReceiver.hpp>` | disabled | Enable it to disable the feedback LED function. Saves 14 bytes program space. |
339
346
340
347
### Changing include (*.h) files with Arduino IDE
341
348
First, use *Sketch > Show Sketch Folder (Ctrl+K)*.<br/>
@@ -344,7 +351,10 @@ Otherwise you have to navigate to the parallel `libraries` folder and select the
344
351
In both cases the library source and include files are located in the libraries `src` directory.<br/>
345
352
The modification must be renewed for each new library version!
346
353
347
-
### Modifying compile options with Sloeber IDE
354
+
### Modifying compile options / macros with PlatformIO
355
+
If you are using PlatformIO, you can define the macros in the *[platformio.ini](https://docs.platformio.org/en/latest/projectconf/section_env_build.html)* file with `build_flags = -D MACRO_NAME` or `build_flags = -D MACRO_NAME=macroValue`.
356
+
357
+
### Modifying compile options / macros with Sloeber IDE
348
358
If you are using [Sloeber](https://eclipse.baeyens.it) as your IDE, you can easily define global symbols with *Properties > Arduino > CompileOptions*.<br/>
We do it according to the statement in the [Vishay datasheet](https://www.vishay.com/docs/80069/circuit.pdf):
448
458
- Carrier duty cycle 50 %, peak current of emitter IF = 200 mA, the resulting transmission distance is 25 m.
449
459
- Carrier duty cycle 10 %, peak current of emitter IF = 800 mA, the resulting transmission distance is 29 m. - Factor 1.16
@@ -454,6 +464,13 @@ BTW, **the best way to increase the IR power** is to use 2 or 3 IR diodes in ser
454
464
To keep the current, you must reduce the resistor by (5 - 1.3) / (5 - 2.6) = 1.5 e.g. from 150 ohm to 100 ohm for 25 mA and 2 diodes with 1.3 volt and a 5 volt supply.<br/>
455
465
For 3 diodes it requires factor 2.5 e.g. from 150 ohm to 60 ohm.
456
466
467
+
# How we decode signals
468
+
The IR signal is sampled at a **50 µs interval**. For a constant 525 µs pulse or pause we therefore get 10 or 11 samples, each with 50% probability.<br/>
469
+
And belive me, if you send a 525 µs signal, your receiver will output something between around 400 and 700 µs!<br/>
470
+
Therefore **we decode by default with a +/- 25% margin** using the formulas [here](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/IRremoteInt.h#L376-L399).<br/>
471
+
E.g. for the NEC protocol with its 560 µs unit length, we have TICKS_LOW = 8.358 and TICKS_HIGH = 15.0. This means, we accept any value between 8 ticks / 400 µs and 15 ticks / 750 µs (inclusive) as a mark or as a zero space. For a one space we have TICKS_LOW = 25.07 and TICKS_HIGH = 45.0.<br/>
472
+
And since the receivers generated marks are longer or shorter than the spaces, we have introduced the [`MARK_EXCESS_MICROS` value]/https://github.com/Arduino-IRremote/Arduino-IRremote#protocolunknown) to compensate for this receiver (and signal stength as well as ambient light dependent :-( ) specific deviation. Welcome to the basics of **real world signal processing**.
473
+
457
474
# NEC encoding diagrams
458
475
Created with sigrok PulseView with IR_NEC decoder by DjordjeMandic.<br/>
0 commit comments