Jason Lee
Published © GPL3+

Using Android Smart Phone to Remote Controller

Do not worry about finding a remote that does not know where you are at home. This project allows you to tune your TV with your smartphone.

IntermediateFull instructions provided5,002
Using Android Smart Phone to Remote Controller

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
HC-06 Bluetooth Module
×1
IR receiver (generic)
×1
IR transmitter (generic)
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
2SC1815
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
Capacitor 47 µF
Capacitor 47 µF
×1
Resistor 330 ohm
Resistor 330 ohm
×2
Resistor 100 ohm
Resistor 100 ohm
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 1 Ohm
×1

Software apps and online services

Bluetooth Controller

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)

Story

Read more

Schematics

Dongle4_bb.jpg

Code

MW_Remote.ino

Arduino
/* Remote Shield Ver 1.0 2016.5.3 Jason Lee */

#include <SoftwareSerial.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <EEPROM.h>


#define RECORD_MODE   1
#define DONGLE_MODE   0

const int IR_SIG_PIN = 2;   //     
const int BLUE_LED = 4;       //     LED (Blue Color)
const int GREEN_LED = 5;    //     LED (Green Color)
const int RED_LED = 6;      //      LED (RED Color)
const int bluetoothTx = 7;
const int bluetoothRx = 8;

const int MEM_ADDR_START = 0;
int mode = DONGLE_MODE;
char curKey = '\0';

struct RemoteKeyValue {
  int key;
  unsigned long val;
  int type;
};

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
IRrecv irrecv(IR_SIG_PIN);
IRsend irsend;
decode_results decodedSignal;

void setup() {
  Serial.begin(9600);
  while (!Serial) {}
  bluetooth.begin(9600);
  bluetooth.write("AT+NAMEMW-Remote");
  irsend.enableIROut(38);
  irrecv.enableIRIn();
  pinMode(GREEN_LED, OUTPUT);
  pinMode(BLUE_LED, OUTPUT);
  pinMode(RED_LED, OUTPUT);
  Serial.println("I'm ready. yo man!");
  blinkLEDColor(255,0,0,100);
  blinkLEDColor(0,0,0,50);
  blinkLEDColor(255,0,0,100);
  blinkLEDColor(0,0,0,200);
  blinkLEDColor(0,255,0,100);
  blinkLEDColor(0,0,0,50);
  blinkLEDColor(0,255,0,100);
  blinkLEDColor(0,0,0,200);
  blinkLEDColor(0,0,255,200);
  blinkLEDColor(0,0,0,50);
  blinkLEDColor(0,0,255,200);
  offLED();
  mode = DONGLE_MODE;
}

void loop() {
  btProc();
  if (mode == RECORD_MODE)
    irRecProc();
}

unsigned long last = millis();

void irRecProc() {
  struct RemoteKeyValue RetSig;

  if (irrecv.decode(&decodedSignal) == true) {
    Serial.print("IR Signal Received. [KEY=");
    Serial.print(curKey);
    Serial.println("]");
    offLED();
    blinkLEDColor(255,0,0,500);  
    blinkLEDColor(0,0,0,50);
    blinkLEDColor(255,0,0,500);  
    if (millis() - last > 250) {
      RetSig.key =  1;
      RetSig.val = decodedSignal.value;
      RetSig.type = decodedSignal.decode_type;
      
      EEPROM.put(MEM_ADDR_START+sizeof(struct RemoteKeyValue)*(curKey-'1'), RetSig);
      Serial.print("Saving IR Signal value=[");
      Serial.print(decodedSignal.value, HEX);
      Serial.print("], IR Signal TYPE=[");
      Serial.print(decodedSignal.decode_type);
      Serial.println("]. Remote signal completely copied.\n\r");
      mode = DONGLE_MODE;  
      offLED();
    }
    last=millis();
    irrecv.resume();
  }
}

void btProc() {
  char cmd;
  struct RemoteKeyValue rKey;
  
  if (bluetooth.available()) {
    Serial.println("BT Command Received. ");
    cmd = (char)bluetooth.read();
    Serial.println(mode);
    if (mode == RECORD_MODE) {
      setLEDColor(0,255,0);
    } else {
      blinkLEDColor(255,0,0,500);    
    }
    curKey = cmd;
    if (mode == DONGLE_MODE) {
      Serial.println("DONGLE MODE ");
      EEPROM.get(MEM_ADDR_START+sizeof(struct RemoteKeyValue)*(cmd - '1'), rKey);
      if (cmd != 's') {
        switch (rKey.type) {
          case NEC :
            irsend.sendNEC(rKey.val,32);
            Serial.print("SEND : ["); Serial.print(rKey.val,HEX); Serial.println("], NEC Type\n\r");        
            break;
          case SONY :
            irsend.sendSony(rKey.val,32);
            Serial.print("SEND : ["); Serial.print(rKey.val,HEX); Serial.println("], SONY Type\n\r");        
            break;
          case RC5 :
            irsend.sendRC5(rKey.val,32);
            Serial.print("SEND : ["); Serial.print(rKey.val,HEX); Serial.println("], RC5 Type\n\r");        
            break;
          case RC6 :
            irsend.sendRC6(rKey.val,32);
            Serial.print("SEND : ["); Serial.print(rKey.val,HEX); Serial.println("], RC6 Type\n\r");        
            break;
          case DISH :
            irsend.sendDISH(rKey.val, 32);
            Serial.print("SEND : ["); Serial.print(rKey.val,HEX); Serial.println("], DISH Type\n\r");        
            break;
          case PANASONIC :
            irsend.sendPanasonic(rKey.val, 32);
            Serial.print("SEND : ["); Serial.print(rKey.val,HEX); Serial.println("], Panasonic Type\n\r");        
            break;
          case JVC :
            irsend.sendJVC(rKey.val, 32, 1);
            Serial.print("SEND : ["); Serial.print(rKey.val,HEX); Serial.println("], JVC Type\n\r");        
            break;
          case SAMSUNG :
            irsend.sendSAMSUNG(rKey.val, 32);
            Serial.print("SEND : ["); Serial.print(rKey.val,HEX); Serial.println("], SAMSUNG Type\n\r");        
            break;
          case UNKNOWN:
            Serial.print("SEND : ["); Serial.print(rKey.val,HEX); Serial.println("], UNKNOWN Type");        
            Serial.println("Cannot send unknown signal type.\n\r");        
            break;
          default:
            Serial.println("Undefined Type.\n\r");        
            break;
        }
      } else {
        Serial.println("command s reveived.");
        if (mode == DONGLE_MODE) {
          Serial.println("Setting Mode Start. Select Key index on your phone.\n\r");
          mode = RECORD_MODE;
          setLEDColor(0,0,255);
        } else {
          Serial.println("Setting Mode Terminated.\n\r");
          mode = DONGLE_MODE;
          offLED();                            
        }
      }
    } 
  }  
}

void blinkLEDColor(int r, int g, int b, int d) {
  int tmpR, tmpG, tmpB;
  
  analogWrite(BLUE_LED,b);
  analogWrite(GREEN_LED,g);
  analogWrite(RED_LED,r);
  delay(d);
  offLED();
}

void setLEDColor(int r, int g, int b) {
  analogWrite(BLUE_LED,b);
  analogWrite(GREEN_LED,g);
  analogWrite(RED_LED,r);
}

void offLED() {
  analogWrite(BLUE_LED,0);
  analogWrite(GREEN_LED,0);
  analogWrite(RED_LED,0);
}

Credits

Jason Lee
1 project • 1 follower
Contact

Comments

Please log in or sign up to comment.