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.

Circuit

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

Coding

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() {
  Serial.begin(115200);
  irrecv.enableIRIn();  // Start the receiver
  while (!Serial)  // Wait for the serial connection to be establised.
    delay(50);
  Serial.println();
  Serial.print("IRrecvDemo is now running and waiting for IR message on Pin ");
  Serial.println(kRecvPin);
  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);
    Serial.println("");

    switch(results.value){
          case 0xFFA25D:
          Serial.println("CH-");
          break;
          case 0xFF629D:
          Serial.println("CH");
          break;
          case 0xFFE21D:
          Serial.println("CH+");
          break;
          case 0xFF22DD:
          Serial.println("|<<");
          break;
          case 0xFF02FD:
          Serial.println(">>|");
          break ;  
          case 0xFFC23D:
          Serial.println(">|");
          break ;               
          case 0xFFE01F:
          Serial.println("-");
          break ;  
          case 0xFFA857:
          Serial.println("+");
          break ;  
          case 0xFF906F:
          Serial.println("EQ");
          break ;  
          case 0xFF6897:
          Serial.println("0");
          break ;  
          case 0xFF9867:
          Serial.println("100+");
          break ;
          case 0xFFB04F:
          Serial.println("200+");
          break ;
          case 0xFF30CF:
          Serial.println("1");
          break ;
          case 0xFF18E7:
          Serial.println("2");
          // green LED on for 2 seconds
          digitalWrite(greenPin, HIGH);
          delay(2000);
          digitalWrite(greenPin, LOW);
          break ;
          case 0xFF7A85:
          Serial.println("3");
          break ;
          case 0xFF10EF:
          Serial.println("4");
          break ;
          case 0xFF38C7:
          Serial.println("5");
          // yellow LED on for 2 seconds
          digitalWrite(yellowPin, HIGH);
          delay(2000);
          digitalWrite(yellowPin, LOW);
          break ;
          case 0xFF5AA5:
          Serial.println("6");
          break ;
          case 0xFF42BD:
          Serial.println("7");
          break ;
          case 0xFF4AB5:
          Serial.println("8");
          break ;
          case 0xFF52AD:
          Serial.println("9");
          break ;      
        }
        key_value = results.value;
        
    irrecv.resume();  // Receive the next value
  }
  delay(100);
}

4 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. I get an error,
    (.text.ets_timer_arm_new+0x104): undefined reference to `ets_intr_lock’, and I cant figure out why it doesnt work, because today, on a raspberry pi, it worked very fine, but now, on windows, it shows this error

Leave a Reply

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

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
100% Free SEO Tools - Tool Kits PRO