Trending

IR transmitter, Control your TV/ AC etc with Arduino/ESP8266


IR radiation better, light that we cannot see, which makes it great for communication. Most of TV/AC/Music player etc use an Infrared remote. The LED mounted at one end of remote which is always invisible is actually an IR LED. We will learn how to use IR LED with arduino to control IR controlled appliances.

IR Communication Basics

38 KHz modulation is used commonly.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.

How IR Remote Works

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 your appliance. Below image shows how data is transmitted and how receiver decodes it(2nd graph).

Thanks to SBProjects.com for the gif.

Protocols

In computing, a protocol or communication protocol is a set of rules in which computers communicate with each other. Many TV/ AC/ Audio devices use RC6, NEC, Sony protocols, etc
You have to be careful which device uses which protocol so they can be controlled via Arduino, also its different IR codes corresponding to different task like vol +, vol-, ch+,ch-, power. All this is covered in this tutorial- Recording/Decoding IR codes of IR remote using Arduino/ESP8266

Parts/Components

IR LED: < 0.2$ NPN Transistor:
OR
IR Transmitter module(Recommended) – around 1$

Wiring

In case of IR LED (Transmitter)-
**Note ** - Power Will be not enough in ESP8266 use some sort of amplifier with it (like common emitter amplifier, don't worry its easy, google it).
Pin 2 DAT (i.e long leg)
GND -> -ve Pin of LED (i.e Short leg)
In case of IR Transmitter Module-
Pin 2 -> DAT
5V -> VCC
GND –> GND
For Arduino data pin in 3 For ESP8266 data pin is configurable in the sketch

Programming

Library

If you don't know how to install Library Click Here.

For Arduino

Install “IRremote” Library by “shirrif” from Arduino Library manager.

For ESP8266/NodeMCU

Install “IRremoteESP8266” Library by “Sebastian Warin,…” from Arduino Library manager. Many other libraries are also available maybe they are better , but this one is best, for now.

Code

This is basic code only full protocol and library featured is not mentioned. Visit for more http://z3t0.github.io/Arduino-IRremote/

For Arduino

#include <IRremote.h>

IRsend irsend;
int ircode = 0xC005C; // demo ir code recorded  by IRrecvDemo.ino
int side = 32; //size of data
void setup()
{
}

void loop() {
 for (int i = 0; i < 3; i++) {
  irsend.sendSony(0xa90, 12);
  delay(40);
 }
 irsend.sendNEC(ircode,32);
 delay(5000); //5 second delay between each signal burst
}

For ESP8266/NodeMCU

It's Same(Not Exactly) Inbuilt Example IRsendDemo
#ifndef UNIT_TEST
#include <Arduino.h>
#endif
#include <IRremoteESP8266.h>
#include <IRsend.h>

#define IR_LED 4  // ESP8266 GPIO pin to use. Recommended: 4 (D2).
#define size_of_data 32
IRsend irsend(IR_LED);  // Set the GPIO to be used to sending the message.

// Example of data captured by IRrecvDumpV2.ino
uint16_t rawData[67] = {9000, 4500, 650, 550, 650, 1650, 600, 550, 650, 550,
                        600, 1650, 650, 550, 600, 1650, 650, 1650, 650, 1650,
                        600, 550, 650, 1650, 650, 1650, 650, 550, 600, 1650,
                        650, 1650, 650, 550, 650, 550, 650, 1650, 650, 550,
                        650, 550, 650, 550, 600, 550, 650, 550, 650, 550,
                        650, 1650, 600, 550, 650, 1650, 650, 1650, 650, 1650,
                        650, 1650, 650, 1650, 650, 1650, 600};

void setup() {
  irsend.begin(); //Initilize IR Transmitter
  Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
}

void loop() {
  irsend.sendNEC(0x00FFE01FUL, size_of_data); 
}

Common Mistakes and Tips


  • Don't just connect the IR LED directly to the pin, it won't have enough current to drive the IR LED effectively.
  • Make sure you have the IR LED polarity correct. See: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
  • Typical digital camera/phones can be used to see if the IR LED is flashed. Replace the IR LED with a normal LED if you don't have a digital camera when debugging.
  • Avoid using the following pins unless you really know what you are doing: -Pin 0/D3 (Only For ESP8266): Can interfere with the boot/program mode & support circuits. -Pin 1 (0 For Arduino)/TX/TXD0: Any serial transmissions from the ESP8266 will interfere. -Pin 3 (1 For Arduino)/RX/RXD0: Any serial transmissions to the ESP8266 will interfere. -ESP-01 modules are tricky. We suggest you use a module with more GPIOs

No comments