Site icon DIY Usthad

IR Remote with Arduino

arduino with ir remote

What are infrared signals?

Remote controls such as those used for your TV, DVD/Blu-ray or Cable box use infrared transmitters and receivers. The transmitter is basically nothing more than a flashlight that emits a light beam at a frequency that is lower than the human eye can detect.

Video

What we are going to do?

Hardware Needed

Components Amazon.comAmazon.inBanggoodAliExpress
IR remote
IR receiver
Arduino UNO
Bread Board
Jumper Wires

IR Sensor Pinout

Pinout diagram of TSOP 1738 & TSOP 1838

Circuit

TSOP 1738 IR receiver with Arduino UNO

Connect the circuit as follows.

ArduinoIR Receiver (TSOP 1738)
5vVCC (2nd leg)
GNDGND (1st leg)
Digital Pin 11OUT (3rd leg)

Note that there is a lot of different types of IR receivers so be careful when giving the connections, the pin(VCC, GND, OUT) might be shuffled in the model you are using.

Software & Libraries Needed

SoftwaresDownload
IR library for Arduino
Arduino IDE

Example Code


/*
 * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  // In case the interrupt driver crashes on setup, give a clue
  // to the user what's going on.
  Serial.println("Enabling IRin");
  irrecv.enableIRIn(); // Start the receiver
  Serial.println("Enabled IRin");
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
  delay(100);
}

Now let’s connect an LED to one of the digital pins of Arduino and edit the above example to turn ON/OFF the LED using the IR remote.

Circuit With LED

ArduinoIR ReceiverLED
D9Anode(+) via
220 Ohm resistor
D11OUT
5VVCC
GNDGNDCathode(-)

Changes needed to make in the example code are:

Code


/*
   IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
   An IR detector/demodulator must be connected to the input RECV_PIN.
   Version 0.1 July, 2009
   Copyright 2009 Ken Shirriff
   http://arcfn.com
*/

#include <IRremote.h>

int RECV_PIN = 11;

int codeON = 16744575;
int codeOFF = 16711935;

int code;

int LED = 9;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  // In case the interrupt driver crashes on setup, give a clue
  // to the user what's going on.
  Serial.println("Enabling IRin");
  irrecv.enableIRIn(); // Start the receiver
  Serial.println("Enabled IRin");
  pinMode(LED, OUTPUT); digitalWrite(LED, LOW);
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, DEC);
    code = results.value, DEC;
    irrecv.resume(); // Receive the next value
  }

  if (code == codeON)
    digitalWrite(LED, HIGH);
  else if (code == codeOFF)
    digitalWrite(LED, LOW);

  delay(100);
}

To buy electronic components order from UTSOURCE

Exit mobile version