ESP8266 NodeMCU – Controling IR Remote Control Infrared Receiver VS1838B

Infrared communication is a common, inexpensive, and easy to use wireless communication technology. IR light is very similar to visible light, except that it has a slightly longer wavelength. This means IR is undetectable to the human eye.
In this tutorial, we will learn how to use an infrared remote controller to control 2 LEDs, via an infrared receiver VS1838B. It is very easy to use this remote control and is full of buttons and capabilities. Use this tutorial to control systems inside your house. Let’s start.

Parts Required

  • VS1838B Infrared Receiver and Remote Controler;
  • Breadboard (optional);
  • 2 x LED;
  • 2 x 220 ohm resistor;
  • Male to male jumper wires (optional);

The VS1838B

Figure 1

Infra-Red light is actually normal light with a particular colour. We need to know there are many more sources of Infra-Red light. The sun is the brightest source of all, but there are many others, like light bulbs, candles, central heating system, and even our body radiates Infra-Red light.

The VS1838B is an infrared receiver for infrared remote control systems, suitable for infrared communications or remote control applications where high receiver sensitivity and ambient light rejection is required. It comprises a PIN diode, a preamplifier and other signal conditioning circuitry integrated into the package. This makes the device easily interfaced with a Microcontroller.

The VS1838B IR receiver is a standard IR remote control receiver series with excellent suppression of disturbance signals, low power consumption and an easy to use package. It mates well with embedded electronics and can be used with common IR remotes. The VS1838B features can be seen below:

  • Built-in Filter at 38KHz;
  • Compatible with Arduino, Raspberry Pi;
  • Working Voltage: 2.7 – 5.5V DC;
  • Receiver Distance: 22 – 25m.

A common modulation scheme for IR communication is something called 38kHz modulation. There are very few natural sources that have the regularity of a 38kHz signal, so an IR transmitter sending data at that frequency would stand out among the ambient IR. The 38kHz modulated IR data is the most common, but other frequencies can be used.

When you hit a key on your remote, the transmitting IR LED will blink very quickly for a fraction of a second, transmitting encoded data to VS1838B. If you were to hook an oscilloscope up to your TV remote’s IR LED, you would see a signal similar to the first graph in figure 2.

Figure 2

This modulated signal is exactly what the VS1838B sees. However, the objective of the receiving device is to demodulate the signal and output a binary waveform that can be read by a microcontroller. When you read the OUT pin of the VS1838B with the wave from above, you will see something like the second graph. This is pretty much what you need to know about the sensor.


Figure 3

Follow the figure above and start connecting the hardware to the board. Connect the green LED to pin D3 and LED the yellow LED to pin D4 with a 220-ohm resistor. After that, connect the VS1838B signal pin to D1 and next to the power pins. At this point, everything is connected.

Instaling Libraries For VS1838B

In order to install the required library for the board to decode the signals, go to Sketch > Include Library > Manage Libraries… and then search for “IRremoteESP8266”. Click on the entry shown in figure 4 and then select Install.

Figure 4


Notice that at the beginning of the sketch, is a number of include libraries. Remember that you should follow the steps above to correctly instal all the libraries. The libraries (IRrecv.h and IRutils.h) are included in the IRremoteESP8266.h, which was instaled above.

Copy the main sketch bellow to your Arduino IDE project and save it. Heve fun!!

#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>

// An IR detector/demodulator is connected to GPIO pin 5 (D1 on a NodeMCU
// board).
// Note: GPIO 16 won't work on the ESP8266 as it does not have interrupts.
const uint16_t kRecvPin = 5;
unsigned long key_value = 0;
// Control LEDs with the 
const int greenPin = 0; //connected to GPIO pin 0 (D3 on a NodeMCU board).
const int yellowPin = 2; //connected to GPIO pin 2 (D4 on a NodeMCU board).

IRrecv irrecv(kRecvPin);

decode_results results;

void setup() {
  irrecv.enableIRIn();  // Start the receiver
  while (!Serial)  // Wait for the serial connection to be establised.
  Serial.print("IRrecvDemo is now running and waiting for IR message on Pin ");
  pinMode(greenPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);

void loop() {
  if (irrecv.decode(&results)) {
    // print() & println() can't handle printing long longs. (uint64_t)
    serialPrintUint64(results.value, HEX);

          case 0xFFA25D:
          case 0xFF629D:
          case 0xFFE21D:
          case 0xFF22DD:
          case 0xFF02FD:
          break ;  
          case 0xFFC23D:
          break ;               
          case 0xFFE01F:
          break ;  
          case 0xFFA857:
          break ;  
          case 0xFF906F:
          break ;  
          case 0xFF6897:
          break ;  
          case 0xFF9867:
          break ;
          case 0xFFB04F:
          break ;
          case 0xFF30CF:
          break ;
          case 0xFF18E7:
          // green LED on for 2 seconds
          digitalWrite(greenPin, HIGH);
          digitalWrite(greenPin, LOW);
          break ;
          case 0xFF7A85:
          break ;
          case 0xFF10EF:
          break ;
          case 0xFF38C7:
          // yellow LED on for 2 seconds
          digitalWrite(yellowPin, HIGH);
          digitalWrite(yellowPin, LOW);
          break ;
          case 0xFF5AA5:
          break ;
          case 0xFF42BD:
          break ;
          case 0xFF4AB5:
          break ;
          case 0xFF52AD:
          break ;      
        key_value = results.value;
    irrecv.resume();  // Receive the next value

2 thoughts on “ESP8266 NodeMCU – Controling IR Remote Control Infrared Receiver VS1838B

  1. Normally I don’t read article on blogs, but I wish to say that this write-up very forced me to try and do it! Your writing style has been surprised me. Thanks, quite nice article.

  2. Howdy! This post could not be written any better! Reading through this post reminds me of my good old room mate! He always kept talking about this. I will forward this post to him. Fairly certain he will have a good read. Many thanks for sharing!

Leave a Reply

Your email address will not be published. Required fields are marked *