Pages: [1]   Go Down
Author Topic: Controlling devices with a TV Remote  (Read 1482 times)
0 Members and 1 Guest are viewing this topic.
Andrews SC
Offline Offline
Full Member
***
Karma: 0
Posts: 238
If Arduino is not the answer, you are asking the wrong question!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've set up a recycled IR sensor from an old VCR with my Arduino. I heavily modified a sketch and used the library from http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html to display number values from keypresses, documented a value for each key, and used a switch / case statement to activate different pins based on keypresses.

I used a samsung remote, but this will work with any TV remote, and could work with any device that can output IR at 38kHz, AFAIK.

Use a SSR instead of the LED to control line voltage ac devices, and a MOSFET or BJT for DC devices. A neat adaptation would be changing a variable with the vol up/down for a thermostat or Light dimming. The TV channel buttons would work for this as well. Better yet, if one could select a device with the number pad, and use a button to on / off, and the volume to change levels. My simple code does not implement that. I'd be interested it seeing it done though.

Full details, including video at http://arduinotronics.blogspot.com/2012/11/arduino-ir-receiver-part-2.html


Code:
/*
 * IRremote: IRrecvDump - dump details of 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
 * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
 * Heavily modified by Steve Spence, http://arduinotronics.blogspot.com
 */

#include

int RECV_PIN = 19;

int reversePin = 4;                 // LED connected to digital pin 4
int forwardPin = 5;                 // LED connected to digital pin 5
int playPin = 6;                 // LED connected to digital pin 6
int pausePin = 7;                 // LED connected to digital pin 7

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  pinMode(reversePin, OUTPUT);      // sets the digital pin as output
  pinMode(forwardPin, OUTPUT);      // sets the digital pin as output
  pinMode(playPin, OUTPUT);      // sets the digital pin as output
  pinMode(pausePin, OUTPUT);      // sets the digital pin as output
}

void loop() {
  if (irrecv.decode(&results)) {
  
    long int decCode = results.value;
    Serial.println(decCode);
    switch (results.value) {
      case 1431986946:
        Serial.println("Forward");
        digitalWrite(forwardPin, HIGH);   // sets the LED on
        break;
      case -11780576:
        Serial.println("Reverse");
        digitalWrite(reversePin, HIGH);   // sets the LED on
        break;
      case -873913272:
        Serial.println("Play");
        digitalWrite(playPin, HIGH);   // sets the LED on
        break;
      case -1025287420:
        Serial.println("Pause");
        digitalWrite(pausePin, HIGH);   // sets the LED on
        break;
      case 1791365666:
        Serial.println("Stop");
        digitalWrite(forwardPin, LOW);   // sets the LED off
        digitalWrite(reversePin, LOW);   // sets the LED off
        digitalWrite(playPin, LOW);   // sets the LED off
        digitalWrite(pausePin, LOW);   // sets the LED off
        break;
      default:
        Serial.println("Waiting ...");
    }

    irrecv.resume(); // Receive the next value
  }
}
« Last Edit: November 04, 2012, 10:02:24 am by Steve Spence - KK4HFJ » Logged

Steve Spence - ET/AT/R&D KK4HFJ

Pages: [1]   Go Up
Jump to: