Tuesday, October 6, 2015

Infrared Remote Control

How to setup an IR Remote Control on an Arduino with a TV remote control:
by J.B. Wylzan 

Project 26:  IR Remote Control
This project shows how to turn on and off each color in an RGB led 
by using the Up, Down, Left, Right, Enter arrows on you TV/DVD remote control.



Hardware:
IR sensor (hacked from an old dvd player ;-) 
Remote control ( any brand lying on your house)
RGB leds
connecting wires
breadboard
Arduino R3 UNO board

Block Diagram:




NOTE: The RGB and the Push Button are not on the sketch below. However using your understanding on our previous lessons or projects, you can add them on your sketch. Good Luck ;-)

Code # 27:
/* ===============================================================
      Project # 27: Infrared Remote Control
      Author: J. B. Wylzan with some help from the Arduino community
      Website: http://www.ihacklab.blogspot.com
      Abstract: This project shows how to turn On and Off each color 
                of an RGB led using a TV remote control.
================================================================== */

// STEP 1: Sketch to extract codes from remote control and captured by your serial monitor :

#include <IRremote.h>

int RECV_PIN = 3;
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
  }
}

---------------------------------------------------------------------------------------------------

// STEP 2: Sketch to test the IR codes in step 1 which will turn on and off each color on your RGB led using either a TV or DVD remote control:

#include <IRremote.h>

int IR_PIN = 3;
int kPin = 4;                  
int bPin = 5;                  
int gPin = 6;                  
int rPin = 7;                  

// The codes below were generated from Step 1:
const long lft = 0x4EB338C7;    
const long fwd = 0x4EB322DD;    
const long rht = 0x4EB312ED;    
const long rvs = 0x4EB3B847;    
const long stp = 0x4EB33AC5;    

IRrecv irrecv(IR_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();        // turn on the receiver
  pinMode(kPin, OUTPUT);       
  pinMode(bPin, OUTPUT);       
  pinMode(gPin, OUTPUT);       
  pinMode(rPin, OUTPUT);       
}

void loop() {
  if (irrecv.decode(&results)) {
    long int decCode = results.value;
    Serial.println(decCode);
    
    switch (results.value) {
      case lft:
        Serial.println("Blue");
        digitalWrite(bPin, HIGH);    
        digitalWrite(kPin, LOW);    
        digitalWrite(gPin, LOW);    
        digitalWrite(rPin, LOW);    
        break;
        
      case fwd:
        Serial.println("Blink");
       digitalWrite(gPin, HIGH);            
       delay(1000);                            
        digitalWrite(gPin, LOW);           
        delay(1000);
        digitalWrite(rPin, HIGH);            
       delay(1000);                            
        digitalWrite(rPin, LOW);            
        delay(1000);
         digitalWrite(bPin, HIGH);            
       delay(1000);                          
        digitalWrite(bPin, LOW);             
        delay(1000);
          break;
        
      case rht:
        Serial.println("Green");
         digitalWrite(kPin, LOW);    
        digitalWrite(bPin, LOW);    
        digitalWrite(gPin, HIGH);    
        digitalWrite(rPin, LOW);     
        break;
        
      case rvs:
        Serial.println("Red");
         digitalWrite(gPin, LOW);    
        digitalWrite(bPin, LOW);    
        digitalWrite(kPin, LOW);    
        digitalWrite(rPin, HIGH);    
        break;  
        
      case stp:
        Serial.println("Stop");
        digitalWrite(bPin, LOW);    
        digitalWrite(kPin, LOW);    
        digitalWrite(gPin, LOW);    
        digitalWrite(rPin, LOW);     
        break;  
        
      default: 
        Serial.println("Press a key ...");
    }

    irrecv.resume();  
  }

}

---------------------------------------------------------------------------------


Challenge: 
Use the sketch above to control the FWD, BCK, RVS, LFT, RHT, STP of your motors.





Actual Layout:




Step 1 Procedure:
1. Find a remote control
2. Run the Arduino Interface
3. Select File > New
4. Copy Code #27 found on Step 1
5. Paste Code #27 from step 1
6. Click File > Save
7. Click Verify
8. Click Upload
9. Open the serial monitor
10. Press the arrows one at a time
11. Write the corresponding codes for each arrow
12. Go to Step 2

Step 2 Procedure:
1. Build the prototype as shown above
2. Run the Arduino Interface
3. Select File > New
4. Copy Code #27 from step 2
5. Paste Code #27 from step 2
6. Click File > Save
7. Click Verify
8. Click Upload
9. RGB led will turn on to Red, Green, Blue and Blink by pressing the corresponding keys on your remote control.


Disclaimer:  We shall not be liable for any loss or damage of whatever nature - direct, indirect, consequential, or otherwise - which may arise as a result of your use of any information on this website. However, if you are interested in using any of the projects for personal or educational purposes, please inform the author by email. 

Public Domain Notice: Copyright (c) 2000. All rights reserved. This article is part of a book entitled iHackRobot. Copies are welcome to be shared or distributed publicly as long proper citations are observed. Please cite as follows: Biotronics: The Silver Species, Joey Lawsin, 1988, USA.

================================================================== 
The Homotronics® and Homodruinos® logos are registered trademarks.
Copyright Biotronics© Inc. iHackRobot®. All Rights Reserved.
Patent Pending. 2000 © ®

L.A.W.S.I.N. Educational Production
 ================================================================== 








No comments:

Post a Comment