on Sunday, 23 March 2014


 
Introduction:

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)

Modulation:
RC5 uses machester coding. i.e to transmit logical zero(0) remote will transmit 10
and for transmitting logical one(1) then 01 will be transmitted..


****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.
 
volatile char allow=0,i=0,holdr=0b00000000,took[15],toggl=2,intru=0;
 void interrupt()//ISR when interrupt occurs
 {
     if(INTCON.INT0IF==1)
    {
     INTCON=0X0;delay_us(1000);//disable the interrupt and delay of 1000us
      for(i=0;i<13;i++)//taking input
      {
           took[i]=portb.f0;
           delay_us(1778);
      }allow=1;//allow flag to 1, indicating that we have received all data
     }
}
void main()
{
 unsigned char j,dustbin;
 TRISB=0XFF;TRISC=0X0;//portb input and portc output
 portc=0;
 delay_ms(2000);//stabilize the device 
 INTCON=0b10010000;//enable the interrupt int0
 INTCON2.INTEDG0=0;//for falling edge
    while(1)
    {
      while(allow==0);//when allow flag is 0 then be in this loop for ever.
      if(took[1]!=toggl)//check the T bit i.e toggle bit with previous one.
      {
        if(toggl==2)toggl=took[1];
 
                      //check the fist line of code,we assigned toggl as 2,
                      //if toggl==2 then take real T bit into it  
        j=5;
        for(i=7;i<13;i++)//convert array to variable for 
                             easy comparison with command
        {
           took[i]=took[i]<<j ;
           holdr=holdr|took[i];took[i]=0;
           j--;
        }
        if(holdr==1)portc.f1=~portc.f1;//comparing
        if(holdr==2)portc.f2=~portc.f2;
        if(holdr==4)portc.f3=~portc.f3;
        if(holdr==5)portc.f4=~portc.f4;
        if(holdr==6)portc.f5=~portc.f5;
      }
      holdr=0;allow=0;
      portc.f7=1;delay_ms(200);portc.f7=0;
      INTCON=0b10010000;
      INTCON2.INTEDG0=0;
      while(uart1_data_ready())
        {
               dustbin=uart1_read();
             }
 
      
           
 
    }
}  
AUTHOR: YOUSTRON SIC
Special thx to GOD. 
Suggested by Ravi Teja by e-mail. 
Special thx to SHerzod bek from Uzbekistan for his support
on Saturday, 15 March 2014


Introduction:

Do you ever thought to switch ON and OFF your tube light, fan or any other home appliances  just by pressing  one button of T.V remote ? You might be thought long back, but you might not get the correct source to help you to build such project..
Now you can do it,in this post i'm going to explain you pretty good project with comprehensive way. Lets start...


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 Relays, IR sensor,etc
Before going to this section, first we should have clear picture of aim of the project.
AIM: Our aim is to switch ON and OFF any of the home appliance(i.e we are using light bulb here)  by using Tv remote.
In general to do this, we need something like sensor to detect the IR pulses from tv remote and a relay.
In general the output of micro-controller gives 5v output but in order to switch ON any home device in general we require 230v AC , so to get this we use device 'Relay'. Relay acts as switch. Lets have look on these two....

Relay: 

I strictly recommend you to read this tutorial post based on 'relay' before continuing further

http://www.microcontroller4beginners.com/2013/12/relay-tutorial.html 

------------------------------------------------------------------------------------------------------------------
IR sensor: We are using Tsop1738 sensor. Observe the pins shown below


>>we connect 'out pin' to microcontroller.
>>vs=5v, Gnd=ground.
I will not go much deep into its working, just one important point to note is that, its output is active high(1), i.e whenever it senses the ir rays then its output will be low(0).

Output from remote: when ever remote key is pressed it transmit pulses. These pulses have different frequencies depending upon the different key pressed.Dont worry about the protocols of the remote , just we need to know the above step that's enough for our project.

How it works internally(Algorithm):

>> When ever Tsop sensor senses the IR pulses then it also produce pulses, which are given as input to microcontroller

>>As soon as  microcontroller gets the input then it makes particular pin(i.e pin connected to relay) will be flipped or inverted( i.e first time ON , next time OFF, so on)

>> Above step means, if we press remote  once then device will be made ON, if we press remote again then device will be turned OFF.
Project requirements:
>> MikroC compiler for Pic
>>Pic18f452 microcontroller
>>Tv remote( any remote will work)
>>Bulb( any home appliance may work)
>>Relay spst 5v DC
>>Tsop1738 sensor
>>4Mhz crystal osciallator
>>Resistors and Capacitors
>>9V battery, 7805 volate regulator IC
CIRCUIT DIAGRAMS:
Power supply:


Relay connections:
(Note: I use to write articles for dostmuhammad.com long back )


Total circuit diagram:



Software:

We use counter to count the number of input pulses, variable 'flip' is to flip the output i.e from ON to OFF and from OFF to ON.
Imp Note: For accuracy we are writing code in such a way that, only if we press remote for two times only then the device will be ON or OFF, i.e if we want to make ON then we need to press remote two times again to make it OFF we need to press two times. we can set this to any number of times by changing the value of the variable ''click'' in the below code i.e if click=3 then after pressing 3 times  remote then the device will be ON and after pressing 3 times the devices go to OFF, so on...
 
void main()
{
    unsigned char click=0,flip=0;
    ADCON0=0X00;
    TRISC=0x0;//protC as output
    trisa=0b00010000;// protA pin 4 used as input
    T0CON=0b11101000;//configuration for counter
    TMR0L=0X0;//counts are zero
       for(;;)
       {
         if(TMR0L>30)//if input pulses are more than 30 pulses then
         {
           click++;//increment clicks
           if(click==2)//check above note 
           {
             click =0;
             flip=~flip;
             portc.f0=flip;// flip the output
           }
        }
     TMR0L=0X0;// again count to zero
     delay_ms(1000);
    }
}
This code will works well, i have tested it on hardware too.. 
In our next project we will see how to control multiple loads...
 
 
 

Author: Youstron Sic