Use Infrared to Control your Home TV

Use Infrared to Control your Home TV

I’ve always wanted to use mCookie and infrared sensor to control home TV.

But I’ve tried to simply send out the code received by infrared, and it couldn’t control anything.

Because household electric appliances on the market adopt many infrared remote control signal transmission agreements.

There are basically the following several kinds of agreements on the market:
NEC with simple repeat code
NEC with full repeat code
TC9012
Panasonic 7051 yards
SONY yad
RC5/RC6A

My home TV is SHARP.

The information received by the infrared is known to use the RC6 agreenment.

So through google materials and experiments, we can know the send format of RC6 is as following:

for (int i = 0; i < 3; i++) {
irsend.sendRC6(thisIREncode,20);
delay(100);
}

The following problem is how to solve the problem of keys?
I thought about it and finally decided to use mobile phone APP rather than keys, and use the Bluetooth to send command to control the infrared sending.
Hao Chen has just written a Bluetooth serial port debugging APP, which is just can be used.

 

Modules which are used:

CoreUSB

Sensor Hub

BT

IR-sensor

IR-reciver

BM

 

Other:

3.7V lithium battery

mSerial serial port debugging app

The final code is as follows:

//#include <SoftwareSerial.h>

#include <IRremote.h>
//SoftwareSerial mySerial(4, 5);

String currentInfo=””;
#define my_Serial Serial1
//#define my_Serial  mySerial

unsigned long RC6Array[16] = {0x8010A600, //0
0x8010A601, //1
0x8010A602, //2
0x8010A603, //3
0x8010A604, //4
0x8010A605, //5
0x8010A606, //6
0x8010A607, //7
0x8010A608, //8
0x8010A609, //9
0x8010A620, //p+
0x8010A621, //p-
0x8010A610, //v+
0x8010A611, //v-
0x8010A60D, //mute
0x8010A60C  //sleep
};

char commandStrs[6][9]={“p+”, “p-“, “v+”, “v-“, “mute”, “sleep”};

unsigned long lastIREncode;
unsigned long thisIREncode;

//0x8000

char command[9] = “disconnd”;

IRsend irsend;

// boolean switchEncode=false;

void setup() {
Serial.begin(9600);
my_Serial.begin(9600);

}

void loop() {

if (my_Serial.available() > 0) {//If there is data having been received
currentInfo = my_Serial.readStringUntil(‘\n’);
if(currentInfo.length()<=9) {//If the data received is not too big
currentInfo.toCharArray(command, 9);

if(strlen(command)==1) {// if type 0~9
if(RC6Array[atoi(command)]==lastIREncode) {
thisIREncode=RC6Array[atoi(command)]-0x8000;
} else {
thisIREncode=RC6Array[atoi(command)];
}
for (int i = 0; i < 3; i++) {
irsend.sendRC6(thisIREncode,20);
delay(100);
}
lastIREncode=thisIREncode;
} else {//else type >9 or p+/- v+/- power mute sleep

if(strcmp(command, “power”) == 0) {//power
//Serial.println(“power”);
for (int i = 0; i < 3; i++) {
irsend.sendRC6(0x2FD48B7,20);
delay(100);
}

for (int i = 0; i < 3; i++) {
irsend.sendRC6(0xFFFFFFFF,20);
delay(100);
}
}

if(isNumber(command)) {//Two bit channel, such as :Jiangsu TV 32.
int string_len = strlen(command);
for(int i=0; i<string_len; i++) {
if(RC6Array[command[i]-‘0’]==lastIREncode) {
thisIREncode=RC6Array[command[i]-‘0’]-0x8000;
} else {
thisIREncode=RC6Array[command[i]-‘0’];
}
for (int i = 0; i < 3; i++) {
irsend.sendRC6(thisIREncode,20);
delay(100);
}
lastIREncode=thisIREncode;
delay(500);
}
}

for(int i=0; i<6; i++) {//p+/- v+/- mute sleep
if(strcmp(command, commandStrs[i]) == 0) {

if(RC6Array[i+10]==lastIREncode) {
thisIREncode=RC6Array[i+10]-0x8000;
} else {
thisIREncode=RC6Array[i+10];
}
for (int i = 0; i < 3; i++) {
irsend.sendRC6(thisIREncode,20);
delay(100);
}
lastIREncode=thisIREncode;
break;
}
}

}
}
}
}

bool isNumber(const char* string) {
const int string_len = strlen(string);
for(int i = 0; i < string_len; ++i) {
if(!isdigit(string[i]))
return false;
}
return true;
}

 

How to use:

Use mobile phone APP to enter the channel number and the channel is sent. Others are:

p+   Add channel;
p-    Reduce channel;
v+    Increase volume;
v-    Reduce volume;
mute
sleep    Standby.

Related Post

The Microduino Tank

The Microduino Tank

I don’t say much, start to work at once! Start with the materials list, this one is a green environmental…

Leave a Reply

Your email address will not be published. Required fields are marked *

Skip to toolbar