Sichvot
Published © GPL3+

Universal Remote

This was made to control my elderly grandmothers T.V. from my home.. Combined with a program like Teamviewer and a webcam. -For Alzheimer's

BeginnerFull instructions provided1 hour1,409
Universal Remote

Things used in this project

Hardware components

IR transmitter (generic)
IR LED From an old remote control.
×1
IR receiver (generic)
IR Reciever
×1
Jumper wires (generic)
Jumper wires (generic)
Bit of wire for putting the IR LED a distance away,
×1

Software apps and online services

Arduino IDE
Arduino IDE
And the IRremote libraries.

Story

Read more

Schematics

Universal Remote Diagram

Simple Schematic

Code

Universal Remote

Arduino
IR LED to pin 3. IR Receiver to pin 11, Upload Sketch. Open serial monitor.
#include <IRremote2.h>   // IRremote.h for the Uno IRremote2.h for Due
#include <EEPROM.h>

                         // IR LED PIN 3
int RECV_PIN = 11;       // IR Reciever pin
int KeyInput;            // Keyboard Key
unsigned long Code;      // Used and Variable Shuttle
unsigned long Address=0; // EEPROM memory Address


IRsend irsend;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  KeyInput=NULL;
  Code=0;
  Address=1023;
  DisplayMain();
}


void DisplayMain()
{
 Serial.println("/======================================\\");
 Serial.println("|            Main Menu                 |");
 Serial.println("|        -----------------             |");
 Serial.println("|                                      |");
 Serial.println("|       1. Config for IR Button Codes  |");
 Serial.println("|       R. Reload Screen               |");
 Serial.println("|  --------- T.V. Controls ----------  |");
 Serial.println("|       2. Power                       |");
 Serial.println("|       3. Input                       |");
 Serial.println("|       4. Menu                        |");
 Serial.println("|       5. Enter                       |");
 Serial.println("|       6. Exit                        |");
 Serial.println("|       7. Caption                     |");
 Serial.println("|       8. Mute                        |");
 Serial.println("|   - / +. Volume Down/Up              |");
 Serial.println("|   < / >. Channel Down/Up             |");
 Serial.println("| W,S,A,D. Up,Down,Left,Right          |");
 Serial.println("|  ------- Cable Box Controls -------  |");
 Serial.println("|       G. Guide                       |");
 Serial.println("| P,;,L,'. Up,Down,Left,Right          |");
 Serial.println("|       [. Enter                       |");
 Serial.println("|       ]. Exit                        |");
 Serial.println("|       K. Page Up                     |");
 Serial.println("|       ,. Page Down                   |");
 Serial.println("|       I. Power                       |");
 Serial.println("\\======================================/");
 Serial.print(" >");
}

void DisplayConfig()
{
 Serial.println("/======================================\\");
 Serial.println("|         Button Config Menu           |");
 Serial.println("|        --------------------          |");
 Serial.println("|                                      |");
 Serial.println("|       1. Return to Main Menu         |");
 Serial.println("|       R. Reload Screen               |");
 Serial.println("|  --------- T.V. Controls ----------  |");
 Serial.println("|       2. Power                       |");
 Serial.println("|       3. Input                       |");
 Serial.println("|       4. Menu                        |");
 Serial.println("|       5. Enter                       |");
 Serial.println("|       6. Exit                        |");
 Serial.println("|       7. Caption                     |");
 Serial.println("|       8. Mute                        |");
 Serial.println("|   - / +. Volume Down/Up              |");
 Serial.println("|   < / >. Channel Down/Up             |");
 Serial.println("| W,S,A,D. Up,Down,Left,Right          |");
 Serial.println("|  ------- Cable Box Controls -------  |");
 Serial.println("|       G. Guide                       |");
 Serial.println("| P,;,L,'. Up,Down,Left,Right          |");
 Serial.println("|       [. Enter                       |");
 Serial.println("|       ]. Exit                        |");
 Serial.println("|     J,M. Page Up,Down                |");
 Serial.println("|       I. Power                       |");
 Serial.println("\\======================================/");
 Serial.print(" >");
}



void loop() 
{
  KeyInput=NULL;
  Code=0;
  Address=1023;
  if (Serial.available() > 0) 
    {  
      KeyInput = Serial.read();      // read the serial input  
                                     // Output from Serial is in ASCII 
      if ((KeyInput == 49) or (KeyInput ==  33)) // 1,! Config 
        {
          SubButtonConfig(); // Goto Button Config 
        }
      if ((KeyInput == 50) or (KeyInput ==  64)) // 2,@ Power
        {
          Address=0;
        }
      if ((KeyInput == 51) or (KeyInput == 35)) // 3,# Input
        {
          Address=4;
        }
      if ((KeyInput == 52) or (KeyInput ==  36)) // 4,$ Menu
        {
          Address=8;
        }
      if ((KeyInput == 53) or (KeyInput ==  37)) // 5,% Enter
        {
          Address=12;
        }
      if ((KeyInput == 54)  or (KeyInput ==  94)) // 6,^ Exit
        {
          Address=16;
        }
      if ((KeyInput == 55)  or (KeyInput ==  38)) // 7,& Caption
        {
          Address=20;
        }
      if ((KeyInput == 56)  or (KeyInput ==  42)) // 8,* Mute
        {
          Address=24;
        }
        
      if ((KeyInput == 45) or (KeyInput ==  95)) // -,_ Vol down
        {
          Address=28;
        }
      if ((KeyInput == 61) or (KeyInput ==  43)) // =,+ Vol up
        {
          Address=32;
        }
      if ((KeyInput == 60) or (KeyInput ==  44)) // <,, Channel down
        {
          Address=36;
        }
      if ((KeyInput == 62) or (KeyInput ==  46)) //  >,. Channel Up
        {
          Address=40;
        }
      if ((KeyInput == 119) or (KeyInput ==  87)) // W,w Up
        {
          Address=44;
        }
      if ((KeyInput == 115) or (KeyInput ==  83)) // S,s Down
        {
          Address=48;
        }
      if ((KeyInput == 97) or (KeyInput ==  65)) //A,a Left
        {
          Address=52;
        }
      if ((KeyInput == 100) or (KeyInput ==  68)) // d,D Right
        {
          Address=56;
        }
      if ((KeyInput == 103) or (KeyInput ==  71)) // g,G Guide
        {
          Address=60;
        }
      if ((KeyInput == 112) or (KeyInput ==  80)) // p,P Up
        {
          Address=64;
        }
      if ((KeyInput == 59) or (KeyInput ==  58)) // ;,: Down
        {
          Address=68;
        }
        if ((KeyInput == 39) or (KeyInput ==  34)) // '," Right
        {
          Address=72;
        }
      if ((KeyInput == 108) or (KeyInput ==  76)) // l,L Left
        {
          Address=76;
        }
      if ((KeyInput == 91) or (KeyInput ==  123)) // [,{ Enter
        {
          Address=80;
        }
      if ((KeyInput == 93) or (KeyInput ==  125)) // ],} Exit
        {
          Address=84;
        }
      if ((KeyInput == 106) or (KeyInput ==  74)) // j,J pageup
        {
          Address=88;
        }
      if ((KeyInput == 109) or (KeyInput ==  77)) // m,M pagedown
        {
          Address=92;
        }
      if ((KeyInput == 105) or (KeyInput ==  73)) // i,I Power
        {
          Address=96; // Next Address 100
        }
      if ((KeyInput == 114) or (KeyInput ==  82)) // r,R Reload
        {
          DisplayMain();
        }
  }
  if (Address!=1023)
  {
        irsend.sendNEC(EEPROMReadlong(Address), 32); // Send Power Signal.
  }
} 

void SubButtonConfig()
{
 DisplayConfig();
 KeyInput = NULL;
 while ((KeyInput!=49) or (KeyInput!=33))
  {
   Address=1023;
   if (Serial.available() > 0) 
    {  
      KeyInput = Serial.read();      // read the serial input  
                                     // Output from Serial is in ASCII 

      if ((KeyInput == 49) or (KeyInput ==  33)) // 1,! Main Menu
        {
          DisplayMain();
          return;
        }
      if ((KeyInput == 50) or (KeyInput ==  64)) // 2,@ power
        {
          Address=0;
        }
      if ((KeyInput == 51) or (KeyInput == 35)) // 3,# input
        {
          Address=4;
        }
      if ((KeyInput == 52) or (KeyInput ==  36)) // 4,$ menu
        {
          Address=8;
        }
      if ((KeyInput == 53) or (KeyInput ==  37)) // 5,% enter
        {
          Address=12;
        }
      if ((KeyInput == 54)  or (KeyInput ==  94)) // 6,^ exit
        {
          Address=16;
        }
      if ((KeyInput == 55)  or (KeyInput ==  38)) // 7,& caption
        {
          Address=20;
        }
      if ((KeyInput == 56)  or (KeyInput ==  42)) // 8,* mute
        {
          Address=24;
        }
        
      if ((KeyInput == 45) or (KeyInput ==  95)) // -,_ vol down
        {
          Address=28;
        }
      if ((KeyInput == 61) or (KeyInput ==  43)) // =,+ vol up
        {
          Address=32;
        }
      if ((KeyInput == 60) or (KeyInput ==  44)) // <,, Channel down
        {
          Address=36;
        }
      if ((KeyInput == 62) or (KeyInput ==  46)) //  >,. Channel Up
        {
          Address=40;
        }
      if ((KeyInput == 119) or (KeyInput ==  87)) // W,w Up
        {
          Address=44;
        }
      if ((KeyInput == 115) or (KeyInput ==  83)) // S,s Down
        {
          Address=48;
        }
      if ((KeyInput == 97) or (KeyInput ==  65)) //A,a Left
        {
          Address=52;
        }
      if ((KeyInput == 100) or (KeyInput ==  68)) // d,D Right
        {
          Address=56;
        }
      if ((KeyInput == 103) or (KeyInput ==  71)) // g,G Guide
        {
          Address=60;
        }
      if ((KeyInput == 112) or (KeyInput ==  80)) // p,P
        {
          Address=64;
        }
      if ((KeyInput == 59) or (KeyInput ==  58)) // ;,:
        {
          Address=68;
        }
        if ((KeyInput == 39) or (KeyInput ==  34)) // '," Right
        {
          Address=72;
        }
      if ((KeyInput == 108) or (KeyInput ==  76)) // l,L Left
        {
          Address=76;
        }
      if ((KeyInput == 91) or (KeyInput ==  123)) // [,{ Enter
        {
          Address=80;
        }
      if ((KeyInput == 93) or (KeyInput ==  125)) // ],} Exit
        {
          Address=84;
        }
      if ((KeyInput == 106) or (KeyInput ==  74)) // j,J pageup
        {
          Address=88;
        }
      if ((KeyInput == 109) or (KeyInput ==  77)) // m,M pagedown
        {
          Address=92;
        }
      if ((KeyInput == 105) or (KeyInput ==  73)) // i,I Power
        {
          Address=96; // Next Address 100
        }
      if ((KeyInput == 114) or (KeyInput ==  82)) // r,R Reload
        {
          DisplayConfig();
        }
    }

    if (Address != 1023)
    {
      SubIRrecieve();
      EEPROMWritelong(Address, Code);
    }
  }
 DisplayMain(); // Goto Main Menu
 return; 
}

void SubIRrecieve() 
{
 irrecv.enableIRIn(); // Start the receiver
 Serial.println("Press A button on the remote for the code of that button.");
 results.value=0;
 irrecv.resume(); // Receive the next value

 while (results.value==0)
  { 
    if (irrecv.decode(&results)) 
      {
        Serial.println(results.value,HEX); // Print Code
        Code = results.value; //Load Signal to Code Shuttle
        results.value=0;
        irrecv.resume(); // Receive the next value
      }
   }
}

//This function will write a 4 byte (32bit) long to the eeprom at
//the specified Address to Address + 3.
void EEPROMWritelong(int Address, unsigned long value)
 {
      //Decomposition from a long to 4 bytes by using bitshift.
      //One = Most significant -> Four = Least significant byte
      byte four = (value & 0xFF);
      byte three = ((value >> 8) & 0xFF);
      byte two = ((value >> 16) & 0xFF);
      byte one = ((value >> 24) & 0xFF);

      //Write the 4 bytes into the eeprom memory.
      EEPROM.write(Address, four);
      EEPROM.write(Address + 1, three);
      EEPROM.write(Address + 2, two);
      EEPROM.write(Address + 3, one);
      Serial.println("EEPROM write, Successful.");
 }


unsigned long EEPROMReadlong(unsigned long Address)
 {
      //Read the 4 bytes from the eeprom memory.
      long four = EEPROM.read(Address);
      long three = EEPROM.read(Address + 1);
      long two = EEPROM.read(Address + 2);
      long one = EEPROM.read(Address + 3);

      //Return the recomposed long by using bitshift.
      return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF);
 }

Credits

Sichvot
1 project • 0 followers
Contact
Thanks to z3t0 and enternoescape.

Comments

Please log in or sign up to comment.