Ir remote using the arduino

Discussion in 'The Completed Projects Collection' started by be80be, Nov 28, 2017.

  1. be80be

    Thread Starter Distinguished Member

    Jul 5, 2008
    954
    165
    Figured I'd share this works great . First off grab a remote anyone would work next let's install the libraries needed.
    https://github.com/cyborg5/IRLib2
    Next let's get IR Sensor most any will work i happened to have a 38kHz one laying around.
    [​IMG]

    http://www.vishay.com/docs/82479/tssp58038.pdf

    The code to find out what your remote is and list output to a terminal is from .
    https://learn.adafruit.com/using-an-infrared-library/hardware-needed
    This is there code for finding the key codes and remotes works really good.

    Code (Text):
    1. Decoded NEC(1): Value:FF50AF Adrs:0 (32 bits)
    2.  
    The top line gives you the needed values we have NEC and my key press was FF50AF
    Code (Text):
    1. #include "IRLibAll.h"
    2.  
    3. //Create a receiver object to listen on pin 2
    4. IRrecvPCI myReceiver(2);
    5.  
    6. //Create a decoder object
    7. IRdecode myDecoder;
    8.  
    9. void setup() {
    10.   Serial.begin(9600);
    11.   delay(2000); while (!Serial); //delay for Leonardo
    12.   myReceiver.enableIRIn(); // Start the receiver
    13.   Serial.println(F("Ready to receive IR signals"));
    14. }
    15.  
    16. void loop() {
    17.   //Continue looping until you get a complete signal received
    18.   if (myReceiver.getResults()) {
    19.     myDecoder.decode();           //Decode it
    20.     myDecoder.dumpResults(true);  //Now print results. Use false for less detail
    21.     myReceiver.enableIRIn();      //Restart receiver
    22.   }
    23. }
    The above code finds your keys code which we set in the next code to turn on and off 3 pins of the arduino.

    This is code I did to turn on and off with 3 buttons 3 leds the pins could be used for anything you need to control.
    Code (Text):
    1. int led1 = 8;
    2. int led2 = 9;
    3. int led3 = 10;
    4. #include <IRLibAll.h>
    5.  
    6. IRrecv myReceiver(2);//receiver on pin 2
    7. IRdecode myDecoder;//Decoder object
    8.  
    9. void setup()
    10. {
    11.   pinMode (led1, OUTPUT);
    12.   pinMode (led2, OUTPUT);
    13.   pinMode (led3, OUTPUT);
    14.   Serial.begin(9600);
    15.   myReceiver.enableIRIn(); // Start the receiver
    16. }
    17.  
    18. void loop() {
    19.   if (myReceiver.getResults()) {
    20.     myDecoder.decode();
    21.     if (myDecoder.protocolNum == NEC) {
    22.       switch(myDecoder.value) {
    23.         case 0xFF50AF:  //Volume Down
    24.         Serial.println(F("Volume Down"));
    25.         digitalWrite(led1, !digitalRead(led1));
    26.           break;
    27.         case 0xFFA05F:  //Play/Pause
    28.         Serial.println(F("CH UP"));
    29.         digitalWrite(led2, !digitalRead(led2));
    30.           break;
    31.         case 0xFF7887:  //Volume Up
    32.         Serial.println(F("Volume up"));
    33.        digitalWrite(led3, !digitalRead(led3));
    34.           break;
    35.       }
    36.    }
    37.      myReceiver.enableIRIn(); //Restart the receiver
    38.   }
    39. }
    40.  
    The circuit
    The pins are named pin10 to 8 for the leds, Ground and Vdd for power, And pin2 for the IR output to the arduino.
    Screenshot from 2017-11-28 03-15-00.png


    Here what I put it in a dumptruck im going to down size the uno but it works
     
    Last edited: Nov 29, 2017
Loading...