Introduction: Web IR Remote With Esp8266 (NodeMCU)

About: Making stuff is my preferred way to aquire new skills.

Problem

There are three remotes on the living room table. To watch your favourite show you have to precisely follow a special sequence of button pushes on at least two of them. And your roommate, mom, girlfriend never remembers those..

Solution

You buy a Logitech Harmony ;-)

But if you don't want to spend this money you can build something similar for under 10$.
By connecting a infrared LED to a ESP8266 (s.th. like an Arduino but with WiFi onboard) we can easily construct a device with which we can control devices with a small webpage from any computer or mobile phone in your WiFi.

What you need

  • NodeMCU development board (they ship from Asia for < 5€)
  • IR sensor ( OS-1838B or TSOP38238)
  • IR LED
  • 100Ω Resistor
  • NPN Transistor (i.e. 2N2222)
  • small piece of prototype PCB
  • four pin connector that fits on the NodeMCU (i.e. floppy disk power adapter)

If you have an old remote you probably can use the IR LED and the transistor from it.

Step 1: Assembling the Hardware

Assemble the components on a small piece on a small piece of prototype circuit board and connect the components as shown in the diagram.

Depending on the LED the protective resistor may not be neccessary. If you find that you have to aim really well or have to be really close to the device you can probably remove it.

I connected everything to a plug I removed from an broken PC power adapter (the one for the floppy disk).

Step 2: Installing the Application on the NodeMCU

Setup up your environment to compile programs for the esp8266 with the Arduino IDE: [https://github.com/espressif/arduino-esp32

Clone or Download the source code of the application from the github repository

In the Arduino IDE, install the library IRremoteESP8266 (Menu: Sketch -> Manage Libraries). Copy the config.h.example file and name this copy config.h. You must at least specify SSID and Password of your WiFi in the config.h to be able to connect to the Webserver. The Arduino Sketch should now be able to be compiled and uploaded. Connect the breakout board you created to 3V, Ground, D5, D6.

If everything worked and you run the chip connected to the Arduino IDE you should be displayed the IP-address the server is running on in the serial monitor.

Step 3: Customizing the HTML-page to Control the NodeMCU

The process in this step is also shown in the video.

In the source code directory there is also a 'ir.html'. If configured correctly this will 'talk' to the NodeMCU.

So the first step is to tell the file under which address it can find the NodeMCU.
Open the ir.html file in a text editor and search for a line looking like this:

 var host = '192.168.2.121';

Change the value between the ticks to match the address the web server printed on the serial monitor after starting.

Recording
Press the Record ButtonPoint the remote control at the sensor and press the desired button on the remoteAfter that under the Record button a long list of numbers should occur. Those are the timings of the signal for that button you pressed on the remote.

Setting up Commands

Now we want a way to send a signal with those timings from the chip itself. For that we have to add the timings we just recorded to the list of known signals. Copy the values (including the square brackets) that the recording process gave you and insert a new line with a name and the values in the ir.html file after the line looking like this:

var signals = {
    "pgr1 btn": [1,2,3],


Replace the 1,2,3 with the recorded values and dont forget the comma after the surrounding brackets. To actually add a button we also have to add a command. A command can consist of multiple signals since we may have to 'press' multiple buttons on the remote, i.e. 1 and 2 to reach channel 12 on the TV. This also allows to control multiple device with one command.
Look for the line looking like this

"Sound on/off": ["mute"], 


Copy that line and change the text "Sound on/off" to match what you want to display on the new button. Change the name"mute"to the name of thesignal` you added.
So the result could be:

"HBO": ["prg 1 btn"],

If you want to execute multiple signals add them like this:

"HBO": ["prg 1 btn", "prg 2 btn"],

Step 4: Usage

After you inserted your desired signal sequences into the HTML file you can copy it to any computer or mobile device that has a browser and is connected to the same WiFi as the NodeMCU.

Microcontroller Contest

Participated in the
Microcontroller Contest