uint16_t rawData[71] = {8994, 4428, 600, 522, 600, 520, 602, 520, 604, 1608, 606, 516, 60
6, 516, 606, 516, 606, 516, 606, 1604, 600, 1610, 604, 1606, 598, 524, 598, 1612, 602, 1
610, 604, 1606, 598, 1614, 600, 1612, 602, 520, 602, 1608, 606, 514, 608, 514, 596, 524,
598, 524, 598, 524, 598, 524, 598, 1610, 604, 518, 604, 1606, 598, 1612, 600, 1610, 60
4, 1606, 596, 1616, 598, 35622, 8988, 2214, 598}; // NEC 10EFA05F
uint32_t address = 0x8;
uint32_t command = 0x5;
uint64_t data = 0x10EFA05F;
These lines will be used in the next example, where we test the emitter.
Sending IR Codes
Armed with the timing data for your desired IR command, load up the
IRsendDemo
example. Around line 42,
replace the
rawData
array with the one you copied from the previous example. You shouldn’t have to modify the
pin definition for the IR emitter – just double-check to make sure
IR_LED
is set to 4, which is the ESP8266 pin
connected to the IR emitter.
With that change made, upload the code. Then point the IR emitter at your device. The emitter has a range of
about 10 feet, so you may need to get a little close. It should receive a command every 6 seconds.
If your code is Sony- or NEC-encoded, you can also plug the value from
data
in the previous example to send an
NEC or Sony command. This is quite a bit more efficient than sending the raw timing data.
Sending NEC Codes via Web Server
One last example which really begins to show the power of this module is the
IRServer
example. This sketch will
connect your ESP8266 to WiFi and set it up as a web server. When the right HTTP endpoint is hit, it will send a
desired command. So you can trigger your device from a web browser!
This example requires that you have an NEC-encoded signal to send.
Before uploading this example, plug your WiFi network’s SSID and password into the
ssid
and
password
variables.
Then adjust some of the static HTML in the
handleRoot()
function to send your desired code. This is a little tricky.
You need to find your NEC code from the receive example – in my case it was
0x10EFA05F
. You’ll also need to
convert this value to decimal (here’s a calculator for that). In my case it was
284139615
. Plug those two values
into a new line of C-string'ed HTML. I added this line on line 59, for example:
"<p><a href=\"ir?code=284139615\">Send 0x10EFA05F</a></p>" \
Then upload the code! Open the serial monitor to check on your ESP8266’s connection status. Once connected it
should provide you an IP address.
On a device connected to the same WiFi network, plug that IP address into the address bar. You should be
greeted with a page like this: