Najad
Published © GPL3+

IR Remote with Arduino

Let's learn how to use an infrared remote with an Arduino.

BeginnerProtip4,468
IR Remote with Arduino

Things used in this project

Hardware components

UTSOURCE Electronic Parts
UTSOURCE Electronic Parts
×1
UTSOURCE Arduino UNO
×1
UTSOURCE TSOP38436
×1
UTSOURCE Breadboard
×1
UTSOURCE jumper wires
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

hd_Vv9fmGbqFH.png

arduino_ir_with_led_2zb9eJQgNs.jpg

Code

Code snippet #1

Arduino
/*
 * 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);
}

Code snippet #2

Arduino
/*
   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);
}

Credits

Najad

Najad

30 projects • 96 followers
Just crazy stuff​

Comments