Loading... Please wait...

Remote Control

Remote Control

This example shows how to use a remote controller with a TSOP4838 IR Receiver.

Hardware Required

  • Arduino Board
  • Remote Control
  • TSOP4838 IR Receiver

Software Required

Download the IRremote library here.

Circuit

The TSOP4838 IR Receiver has three pins.

Connect the output pin (pin 1 on TSOP4838) of the Infrared Receiver to digital pin 6
Connect the GND Pin (Pin 2 of TSOP838) to GND
Connect +5V Pin (Pin 3 of TSOP4838)to +5V

Code

/*
  Remote controlled LED

  This program controls the onboard LED to be ON or OFF
  The output pin (pin 1 on TSOP4838) of the Infrared Receiver is attached to pin 6
  The GND Pin (Pin 2 of TSOP838) is connected to GND
  The +5V Pin (Pin 3 of TSOP4838) is connected to +5V

  The LED should be ON if you push the forward key of the Remote Controller, and be OFF if you push the backward key
*/


#include "IRremote.h"

// Output pin of the IR Receiver
int RECV_PIN = 6;

// Define the all the hex values for the keys on the remote

#define KEY_CHDOWN 0xFFA25D
#define KEY_CH 0xFF629D
#define KEY_CHUP 0xFFE21D
#define KEY_PREV 0xFF22DD
#define KEY_NEXT 0xFF02FD
#define KEY_PLAYPAUSE 0xFFC23D
#define KEY_MINUS 0xFFE01F
#define KEY_PLUS 0xFFA857
#define KEY_EQ 0xFF906F
#define KEY_0 0xFF6897
#define KEY_100 0xFF9867
#define KEY_200 0xFFB04F
#define KEY_1 0xFF30CF
#define KEY_2 0xFF18E7
#define KEY_3 0xFF7A85
#define KEY_4 0xFF10EF
#define KEY_5 0xFF38C7
#define KEY_6 0xFF5AA5
#define KEY_7 0xFF42BD
#define KEY_8 0xFF4AB5
#define KEY_9 0xFF52AD

// define the keys we want to use to switch the LEDs
long LED_ON = KEY_NEXT;
long LED_OFF = KEY_PREV;

// declare the IR Receiver
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  // initialize the digital pin as an output.
  pinMode(RECV_PIN, INPUT);
  pinMode(13, OUTPUT);
  irrecv.enableIRIn(); // Start the receiver
}
void loop() {
  int i = 0;
  if (irrecv.decode(&results))
  {
     irrecv.resume(); // Receive the next value
     if (results.value == LED_ON )
     {
       digitalWrite(13, HIGH);
     }
     if (results.value == LED_OFF )
     {
       digitalWrite(13, LOW);
     }
  }
}

 

Sketch to read IR codes

This sketch is useful if you don't know what codes are being transmitted.

#include <IRremote.h>
int RECV_PIN = 6; //define input pin on Arduino
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}
void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
}

 

 

 

What's News

newsletter

Copyright 2017 oddWires. All Rights Reserved.
 Sitemap | oddWires