Hello friends, I'm back with an amazing project. As name says we are
going to control all the home appliances using TV remote. Before i have
written on the similar project here where
we have controlled only one load by TV remote, but if you want
to control all the appliances of home then it wont work with that project...
So,I'm writing this post by which we can control all the home devices using
Philips TV remote. We use Philips remote which works on RC5 protocol.
Without wasting time lets jump into the project....

Basic understanding:

We need to have basic understanding of few modules to design this
project.Next thing is to write software code for it.
We are going to look at few important things how they work,like RC5
protocol, Relays, IR sensor,etc
Before going to this section, first we should have clear picture on aim of
the project.

AIM: Our aim is to switch ON and OFF any of the home appliance by
using Philips TV remote which works on RC5 protocol.

In general to do this, we need something called sensor to detect the IR pulses
from TV remote and a relay to switch.
In general the output of Micro-controller gives 5v output but in order to switch
ON any home device we require 230v AC , so to get this we use device 'Relay'.
Relay acts as switch. Let’s have a look on it, i have explained in dept in my previouspost so i strongly recommend you to refer it for better understanding.
Now we need to look at how TV remote sends its pulses when a key is pressed.
Only if we understand the protocol (set of rules) only then we can program for
it better. As I said earlier we use Philips remote which works on RC5
protocol. Below are few model numbers of Philips remote which works on RC5
protocol.

List of model numbers of Philips remote which works on RC5 protocol:
Philips-RC7805,RC7806,RC7807,RC7808,RC7809,RC7812,RC7812-S,RC7815,RC7843,RC7848,RC7854,RC7940,RC7943,etc
Lot of remotes works on this protocol,
better ask for RC7805 in your local market. In India we find lot of local brands
which sell Philips universal remotes costs less than Rs. 120(china remotes ).

RC5 Protocol:
It is must to understand about this protocol in order to write code by our
own. I will not relate this section with unnecessary topics.
when we press any key of remote it will transmit stream of pulses. Every
remote have its own way of transmitting its pulses. So, let us look at our
remote how it sends, what is the order of pulses and which part of stream of
pulses we need to process.

Look at the above fig. the standard format of stream of pulses have
total of 14 pulses, in which
s1,s2 = Start bits(always 1)
T =Toggle bit(which changes for every time we press the key)

a0,a1,a2,a3 = Address bits(for TV remote it have different address for VCR

remote it have different address , so on.. we need not to worry about this)

c0,c1,c2,c3,c4,c5 = Command bits( each key will have different command,
we will
recognise which key is pressed by using these bits)

****i.e for logical '1' low to high
transition takes place, for zero high to low takes place.whole logical 1 or
zero stands for 1778us i.e half 889us on either sides.. so if we want to
check whether it is logical 1 or zero just if we check the 2nd part that's
enough i.e for logical 1 second part is 1 and for zero second part is
zero. As we use IR sensor like Tsop1738 or Tsop1736 their output is active
low i.e whenever a pulse it detect it will give '0' output. so it acts as
inverter i.e for logical 1 output from TSOP sensor will be 10 and for logical
zero output will be 01. as we are using these sensors we need to check
first half to know what actually the bit is, for '1' the first half will be '1'
, for '0' first half will be '0'. look below fig.

>> Look at the below image for commands
e.g for key0 then command block will be decimal 0, key1=decimal1,
key2=decimal3,so on

How it works internally(Algorithm):

>>Once look at the standard format picture, below pulses
are just the example it will change according to the button pressed.

we need not to worry about address bits i.e a0 to a3 , we just need the
command bits c0 to c5. we don't know when the pulses arrive at the
microcontroller, we cannot know when the user press the TV button, so we need
to implement a hardware interrupt (int).
As we know that first two pulses we get are logical 1(s1,s0 always 1) , we
know that logical 1 means 10 from the output of the tsop1738 sensor. so we set
interrupt for high to low transition for the first pulse, when ever high to low
occur an interrupt will be generated,by which we can know that TV button have
been pressed.
>>Look at the below fig carefully and understand the given steps below

>>Remote will transmit data as long as the key is pressed,so to know
actually person pressed the same key again we need to check T bit.
when ever a person presses a key, T bit will be flipped, for example suppose
we pressed key '1' then T=01 and after some time again we press key '1' or any
other key then T will be 10. for every key press it will be inverted.

Step by step procedure for programing:

>> we need to start an falling edge interrupt, when ever interrupt
occur uc will know that data has been arrived and it has to be saved.Disable
the interrupt.

>>As we need to take the first half portion transition from all,so we
need to produce a delay of 1000us in order to take the first bit of 's2'

>> we need to produce the delay of 1778us in order to take the first
bit of 'T' , again we need to produce the delay of 1778us in order to take the
first bit of 'A4', again we need to produce the delay 1778us to jump to 'A5',
in the same way we take all the bits.

INTCON=0X0;//step1

delay_us(1000); //step2

for(i=0;i<13;i++)//step3

{

took[i]=portb.f0;//taking input from portb.f0 int0 pin

delay_us(1778);

}

>> we took input in an array , so we need to convert it to a string of
pulses to check command data

j=5;

for(i=7;i<13;i++)//we are only taking from command bits

{

took[i]=took[i]<<j; //left shift

holdr=holdr|took[i];//or operation

j--;

}

>> Lets check which key has been pressed, and flip its output, i.e if
we press once then it will be in ON state and if we press the same key again,
then it will be in OFF state

if(holdr==1)portc.f0=~portc.f1;//if we pressed key 1, then portc pin 1 will be flipped

if(holdr==2)portc.f1=~portc.f2;//if we pressed key 2, then portc pin2 will be flipped

if(holdr==4)portc.f2=~portc.f3;

if(holdr==5)portc.f3=~portc.f4;

if(holdr==6)portc.f4=~portc.f5;

Note:Notice from above code, i dint took key 0 and
key 3, because i'm getting little error for these keys, so i have took key
1,2,4,5,6, so on>> when ever we press the key on remote and senses by the uc correctly
then portc.f7 will be blinked

portc.f7=1;

delay_ms(200);

portc.f7=0;

Circuit diagrams:POWER SUPPLY:As we are using 9v input
battery , so we need to convert it to 5v using 7805 Ic.

Relay circuit:

(I use to write articles of 'dostmuhammad' website before)Overall Circuit:

The general connections for pic are the same
i.e crystal oscillator between 13 and 14th pin,
pin31=pin12=ground,pin11=pin32=pin1=vcc.

Software:
MikroC is one of the comprehensive software which have lot of inbuilt
libraries. We need not to worry about writing code for general modules
interfacing like Lcd's, keypad's, and many more.. so basic idea at C language
is enough to code using MikroC compiler.
Now let us analyze the code, its very simple code.*** We need to press the same key twice
to enable or disable the corresponding pin. Rather than connecting
directly relays to uc, just connect leds for the testing if we get appropriate
result then connect relays.. I have tested this code on real hardware.